| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 1 | # The compilers, as build artifacts rather than things found on the machine. |
| 2 | # |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 3 | # scripts/*.dotslash is where a tool's version and digest are written down, and |
| 4 | # it stays that way: generated.bzl beside this file is derived from those |
| 5 | # manifests by scripts/dotslash-to-buck, so there is one place to bump a |
| 6 | # version and no second copy of a digest to drift. |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 7 | # |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 8 | # buck cannot use the shims themselves. DotSlash resolves a tool at run time, |
| 9 | # on the machine running it, against a cache in the user's home — so the tool |
| 10 | # is not an input to any action, is not in any action's cache digest, and is |
| 11 | # not something a remote worker can be handed. Fetching the identical archive |
| 12 | # by the identical digest is how buck gets those three properties without |
| 13 | # taking the pinning away from DotSlash. |
| 14 | load("//dist:generated.bzl", "DIST") |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 15 | |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 16 | def _archive(name, tool, platform): |
| 17 | entry = DIST[tool][platform] |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 18 | native.http_archive( |
| 19 | name = name, |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 20 | urls = [entry["url"]], |
| 21 | sha256 = entry["sha256"], |
| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 22 | strip_prefix = entry["strip_prefix"] or None, |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 23 | type = entry["type"], |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 24 | visibility = ["PUBLIC"], |
| 25 | ) |
| 26 | |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 27 | def rust_dist(name, platform): |
| 28 | """The Rust dist tarball: rustc, rustdoc and the std components.""" |
| 29 | _archive(name, "rust", platform) |
| 30 | |
| 31 | def zig_dist(name, platform): |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 32 | """zig, which is the C and C++ compiler, the linker and the archiver.""" |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 33 | _archive(name, "zig", platform) |
| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 34 | |
| 35 | def rust_std_android_dist(name, platform): |
| 36 | """The Rust standard library, built for the device. |
| 37 | |
| 38 | A component rather than a toolchain: the dist tarball above carries a |
| 39 | libstd for the host it runs on and no other, so cross-compiling needs this |
| 40 | fetched beside it. |
| 41 | """ |
| 42 | _archive(name, "rust-std-android", platform) |
| 43 | |
| 44 | def rust_android_sysroot(name, rust, rust_std, host_triple, target_triple): |
| 45 | """The two libstds above, as the one sysroot rustc will take. |
| 46 | |
| 47 | rustc resolves a target's libstd from sysroot/lib/rustlib/<triple>, and |
| 48 | accepts --sysroot once. Cross-compiling therefore needs a sysroot holding |
| 49 | both triples: the host's, for build scripts and proc macros, and the |
| 50 | target's, for the crate being built. The components ship separately, so |
| 51 | they are stitched together here. |
| 52 | |
| 53 | scripts/rustc does this at run time, in a cache under the user's home. As |
| 54 | an artifact instead it is an input like anything else — hashed into the |
| 55 | actions that use it, and shippable to a worker. |
| 56 | """ |
| 57 | native.genrule( |
| 58 | name = name, |
| 59 | out = "sysroot", |
| 60 | cmd = " && ".join([ |
| 61 | "mkdir -p $OUT/lib", |
| 62 | "cp -a $(location {})/rust-std-{}/lib/. $OUT/lib/".format(rust, host_triple), |
| 63 | "cp -a $(location {})/rust-std-{}/lib/rustlib/{} $OUT/lib/rustlib/".format( |
| 64 | rust_std, |
| 65 | target_triple, |
| 66 | target_triple, |
| 67 | ), |
| 68 | ]), |
| 69 | visibility = ["PUBLIC"], |
| 70 | ) |
| 71 | |
| 72 | def dotslash_dist(name, platform): |
| 73 | """DotSlash, as an input, so an action can fetch what it needs where it runs. |
| 74 | |
| 75 | The NDK is the one archive this repo does not hand to buck: unpacked it is |
| 76 | three gigabytes, and an input that size has to reach a worker through the |
| 77 | CAS. Fetching it on the worker instead moves the same pinned bytes over the |
| 78 | same digest, from Google rather than from here. |
| 79 | """ |
| 80 | _archive(name, "dotslash", platform) |
| 81 | |
| 82 | def android_ndk_dist(name, platform): |
| 83 | """The NDK: clang and the LLVM binutils, over a bionic sysroot. |
| 84 | |
| 85 | The one archive here that is not a compiler for the host — it is fetched |
| 86 | for the host that runs it and builds only for Android. |
| 87 | """ |
| 88 | _archive(name, "android-ndk", platform) |