# The compilers, as build artifacts rather than things found on the machine. # # scripts/*.dotslash is where a tool's version and digest are written down, and # it stays that way: generated.bzl beside this file is derived from those # manifests by scripts/dotslash-to-buck, so there is one place to bump a # version and no second copy of a digest to drift. # # buck cannot use the shims themselves. DotSlash resolves a tool at run time, # on the machine running it, against a cache in the user's home — so the tool # is not an input to any action, is not in any action's cache digest, and is # not something a remote worker can be handed. Fetching the identical archive # by the identical digest is how buck gets those three properties without # taking the pinning away from DotSlash. load("//dist:generated.bzl", "DIST") def _archive(name, tool, platform): entry = DIST[tool][platform] native.http_archive( name = name, urls = [entry["url"]], sha256 = entry["sha256"], strip_prefix = entry["strip_prefix"] or None, type = entry["type"], visibility = ["PUBLIC"], ) def rust_dist(name, platform): """The Rust dist tarball: rustc, rustdoc and the std components.""" _archive(name, "rust", platform) def zig_dist(name, platform): """zig, which is the C and C++ compiler, the linker and the archiver.""" _archive(name, "zig", platform) def rust_std_android_dist(name, platform): """The Rust standard library, built for the device. A component rather than a toolchain: the dist tarball above carries a libstd for the host it runs on and no other, so cross-compiling needs this fetched beside it. """ _archive(name, "rust-std-android", platform) def rust_android_sysroot(name, rust, rust_std, host_triple, target_triple): """The two libstds above, as the one sysroot rustc will take. rustc resolves a target's libstd from sysroot/lib/rustlib/, and accepts --sysroot once. Cross-compiling therefore needs a sysroot holding both triples: the host's, for build scripts and proc macros, and the target's, for the crate being built. The components ship separately, so they are stitched together here. scripts/rustc does this at run time, in a cache under the user's home. As an artifact instead it is an input like anything else — hashed into the actions that use it, and shippable to a worker. """ native.genrule( name = name, out = "sysroot", cmd = " && ".join([ "mkdir -p $OUT/lib", "cp -a $(location {})/rust-std-{}/lib/. $OUT/lib/".format(rust, host_triple), "cp -a $(location {})/rust-std-{}/lib/rustlib/{} $OUT/lib/rustlib/".format( rust_std, target_triple, target_triple, ), ]), visibility = ["PUBLIC"], ) def dotslash_dist(name, platform): """DotSlash, as an input, so an action can fetch what it needs where it runs. The NDK is the one archive this repo does not hand to buck: unpacked it is three gigabytes, and an input that size has to reach a worker through the CAS. Fetching it on the worker instead moves the same pinned bytes over the same digest, from Google rather than from here. """ _archive(name, "dotslash", platform) def android_ndk_dist(name, platform): """The NDK: clang and the LLVM binutils, over a bionic sysroot. The one archive here that is not a compiler for the host — it is fetched for the host that runs it and builds only for Android. """ _archive(name, "android-ndk", platform)