nandi/jolt-nativepublic Fork 0
14a30c029628db6eb0966e8de5efffa1aeeafc57
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

BUCK · 160 lines · 7.0 KBPython Blame HistoryRaw
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago1load("//dist:generated.bzl", "DIST")
Make the C toolchain a dependency too, so zig travels with the action 6391496 nandi 19d ago2load(":defs.bzl", "hermetic_cxx_toolchain", "hermetic_rust_toolchain")
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago3load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain")
4load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain")
5
6# Tools come from the DotSlash files in scripts/, so the build depends on
Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago7# pinned upstream releases rather than whatever the host happens to have.
8#
9# The paths are absolute, and read out of .buckconfig.local rather than written
10# here, because neither of the obvious spellings works. A build script runs in
11# a directory of its own, and the prelude re-execs the compiler from there, so
12# a project-relative `scripts/zcc` is not found; and the shim that does the
13# re-exec calls os.execl rather than os.execlp, so a bare `zcc` on PATH is not
14# found either. aws-lc-sys is where both show up. The `buck` recipe in justfile
15# writes that file, so the absolute paths are generated rather than committed.
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago16#
17# rustc does not come this way any more — see the toolchain at the bottom of
18# this file. These three are what is left to make into dependencies.
Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago19_SCRIPTS = read_root_config("jolt", "scripts", "scripts")
20
21# The compiler's version, written by the `buck` recipe alongside the paths.
22#
23# It has to reach the actions somehow, because the prelude names rustc as the
24# bare string "rustc" — the binary is not an input, so its identity is not in
25# any action's cache digest. Two compilers therefore produce artifacts under
26# the same digest, and a shared cache will hand one build the other's rlibs;
27# the failure is E0514, a long way from the cause. Naming the version in a cfg
28# nothing reads is enough to keep the digests apart.
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago29# The C toolchain's version, written by the `buck` recipe alongside the paths.
30#
31# rustc no longer needs this: it is a dependency now, so its identity is in
32# every action's digest and two compilers cannot collide on one cache entry.
33# zig still does. It is named by an absolute path that does not change when the
34# binary behind it does, so a version bump would silently reuse entries built
35# by the old one — the E0514 failure, one toolchain over. Naming the version in
36# a cfg nothing reads keeps the digests apart until zig is a dependency too.
37_ZIG_VERSION = read_root_config("jolt", "zig_version", "unknown")
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago38
39# The NDK's, for the same reason and read from the pin rather than the machine.
40# The C toolchain does not need it — the archive is a dependency there, so it
41# is in every cxx action's digest already. rustc does: it links an Android
42# target through scripts/android-cc, an absolute path that does not change when
43# the NDK behind it does.
44_NDK_VERSION = DIST["android-ndk"]["linux-x86_64"]["strip_prefix"]
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago45#
46# This is the same arrangement .cargo/config.toml used to describe: zig cc
47# carries its own glibc sysroot, which is why this repo builds on a machine
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago48# with no `cc` at all.
49#
50# Android is the one target it cannot serve. zig brings a glibc sysroot and no
51# bionic, so there is nothing there to link an Android object against; the
52# NDK's own clang is the driver that knows where libc.so and the platform stubs
53# live. Only the archive and the wrapper change — the toolchain either side of
54# them is the same construction, which is the point of asking a wrapper for a
55# mode rather than naming binaries here.
Make the C toolchain a dependency too, so zig travels with the action 6391496 nandi 19d ago56hermetic_cxx_toolchain(
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago57 name = "cxx",
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago58 dist = select({
59 "DEFAULT": "toolchains//dist:zig",
60 # DotSlash, not the NDK: ndk.sh fetches the NDK where it runs, which is
61 # the difference between a worker downloading three gigabytes from
62 # Google and this machine uploading them to the CAS first.
63 "prelude//os:android": "toolchains//dist:dotslash",
64 }),
65 manifest = select({
66 "DEFAULT": None,
67 "prelude//os:android": "root//scripts:android-ndk.dotslash",
68 }),
69 wrapper = select({
70 "DEFAULT": "toolchains//:zcc.sh",
71 "prelude//os:android": "toolchains//:ndk.sh",
72 }),
73 platform_name = select({
74 "DEFAULT": "x86_64",
75 "prelude//os:android": "arm64",
76 }),
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago77 visibility = ["PUBLIC"],
78)
79
80system_genrule_toolchain(
81 name = "genrule",
82 visibility = ["PUBLIC"],
83)
84
85system_python_bootstrap_toolchain(
86 name = "python_bootstrap",
87 visibility = ["PUBLIC"],
88)
89
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago90# The compiler is the dist tarball in toolchains//dist, not a name resolved
91# against the machine. See defs.bzl for why that distinction is the whole
92# point, and dist.bzl for where the tarball comes from.
93hermetic_rust_toolchain(
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago94 name = "rust",
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago95 dist = "toolchains//dist:rust",
96 wrapper = "toolchains//:rustc.sh",
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago97 default_edition = "2021",
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago98 # Pipelined builds compile each crate against its dependencies'
99 # `-Zno-codegen` metadata rather than their rlibs. On the Android graph the
100 # two disagree for android-activity, and what comes out the far side is a
101 # link that cannot find winit — or glutin-winit, or anything else that
102 # reaches the event loop through it. Build real rlibs there. The desktop
103 # graph pipelines fine and keeps the parallelism.
104 nightly_features = select({
105 "DEFAULT": True,
106 "prelude//os:android": False,
107 }),
108 # Which libstd rustc is given. The desktop configuration takes the
109 # component the dist tarball carries for its own host; Android needs two
110 # triples in one directory, so it takes the stitched one.
111 sysroot = select({
112 "DEFAULT": None,
113 "prelude//os:android": "toolchains//dist:android-sysroot",
114 }),
115 rustc_flags = select({
116 "DEFAULT": ["-Clinker=" + _SCRIPTS + "/zcc"],
117 # zig has no bionic to link against; the NDK's clang does. The cfg
118 # nothing reads is what keeps the digests apart, as above.
119 "prelude//os:android": [
120 "-Clinker=" + _SCRIPTS + "/android-cc",
121 "--cfg=jolt_ndk=\"" + _NDK_VERSION + "\"",
122 ],
123 }) + [
Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago124 # What [profile.release] in Cargo.toml says, and for the reason given
125 # there: the tree walk and the texture uploads are hot every frame, and
126 # the media plane decodes H.264. buck2 optimises nothing by default, so
127 # without this the two objects are debug builds wearing release names.
128 # OPT_LEVEL=2 in the buildscript fixups is the same setting for the C.
129 "-Copt-level=2",
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago130 "--cfg=jolt_cc=\"" + _ZIG_VERSION + "\"",
Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago131 ],
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago132 # Only triples there is an archive for can be named here: the desktop one
133 # comes out of the dist tarball, the Android one out of the libstd fetched
134 # beside it.
135 rustc_target_triple = select({
136 "DEFAULT": "x86_64-unknown-linux-gnu",
137 "prelude//os:android": "aarch64-linux-android",
138 }),
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago139 visibility = ["PUBLIC"],
140)
141
142# The wrapper the Rust toolchain runs rustc through, as an artifact so it is an
143# input to every action that compiles anything.
Make the C toolchain a dependency too, so zig travels with the action 6391496 nandi 19d ago144export_file(
145 name = "zcc.sh",
146 mode = "reference",
147 visibility = ["PUBLIC"],
148)
149
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago150export_file(
151 name = "ndk.sh",
152 mode = "reference",
153 visibility = ["PUBLIC"],
154)
155
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago156export_file(
157 name = "rustc.sh",
158 mode = "reference",
Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago159 visibility = ["PUBLIC"],
160)