| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 1 | load("//dist:generated.bzl", "DIST") |
| Make the C toolchain a dependency too, so zig travels with the action 6391496 nandi 19d ago | 2 | load(":defs.bzl", "hermetic_cxx_toolchain", "hermetic_rust_toolchain") |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 3 | load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain") |
| 4 | load("@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 ago | 7 | # 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 ago | 16 | # |
| 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 ago | 19 | _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 ago | 29 | # 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 ago | 38 | |
| 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 ago | 45 | # |
| 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 ago | 48 | # 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 ago | 56 | hermetic_cxx_toolchain( |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 57 | name = "cxx", |
| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 58 | 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 ago | 77 | visibility = ["PUBLIC"], |
| 78 | ) |
| 79 | |
| 80 | system_genrule_toolchain( |
| 81 | name = "genrule", |
| 82 | visibility = ["PUBLIC"], |
| 83 | ) |
| 84 | |
| 85 | system_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 ago | 90 | # 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. |
| 93 | hermetic_rust_toolchain( |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 94 | name = "rust", |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 95 | dist = "toolchains//dist:rust", |
| 96 | wrapper = "toolchains//:rustc.sh", |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 97 | default_edition = "2021", |
| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 98 | # 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 ago | 124 | # 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", |
| Ship the object without the notes nobody reads aabacba nandi 18d ago | 130 | # Debug info is 5.9M of the 14.5M Android object, and nothing reads it: |
| 131 | # the .so ships in the APK, and a crash comes back through logcat as a |
| 132 | # bionic backtrace against the loaded segments, not a DWARF line table. |
| 133 | # cargo's release profile already carries none — its object strips to |
| 134 | # within 168 bytes of itself — so this is buck2 matching that, not a |
| 135 | # new decision about what is debuggable. Drop the flag to get it back. |
| 136 | "-Cstrip=debuginfo", |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 137 | "--cfg=jolt_cc=\"" + _ZIG_VERSION + "\"", |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 138 | ], |
| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 139 | # Only triples there is an archive for can be named here: the desktop one |
| 140 | # comes out of the dist tarball, the Android one out of the libstd fetched |
| 141 | # beside it. |
| 142 | rustc_target_triple = select({ |
| 143 | "DEFAULT": "x86_64-unknown-linux-gnu", |
| 144 | "prelude//os:android": "aarch64-linux-android", |
| 145 | }), |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 146 | visibility = ["PUBLIC"], |
| 147 | ) |
| 148 | |
| 149 | # The wrapper the Rust toolchain runs rustc through, as an artifact so it is an |
| 150 | # input to every action that compiles anything. |
| Make the C toolchain a dependency too, so zig travels with the action 6391496 nandi 19d ago | 151 | export_file( |
| 152 | name = "zcc.sh", |
| 153 | mode = "reference", |
| 154 | visibility = ["PUBLIC"], |
| 155 | ) |
| 156 | |
| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 157 | export_file( |
| 158 | name = "ndk.sh", |
| 159 | mode = "reference", |
| 160 | visibility = ["PUBLIC"], |
| 161 | ) |
| 162 | |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 163 | export_file( |
| 164 | name = "rustc.sh", |
| 165 | mode = "reference", |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 166 | visibility = ["PUBLIC"], |
| 167 | ) |