| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 1 | load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain") |
| 2 | load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain") |
| 3 | load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain") |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 4 | load(":defs.bzl", "hermetic_rust_toolchain") |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 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") |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 38 | # |
| 39 | # This is the same arrangement .cargo/config.toml used to describe: zig cc |
| 40 | # carries its own glibc sysroot, which is why this repo builds on a machine |
| 41 | # with no `cc` at all. Unlike vidya there is no Android row here — both shared |
| 42 | # objects this repo ships are desktop, and the APK takes its libvidya from |
| 43 | # vidya's own buck2 build. |
| 44 | system_cxx_toolchain( |
| 45 | name = "cxx", |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 46 | # `ar` would otherwise come off the host, which is the one thing this |
| 47 | # toolchain is arranged not to do. |
| 48 | archiver = _SCRIPTS + "/zar", |
| 49 | compiler = _SCRIPTS + "/zcc", |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 50 | compiler_type = "clang", |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 51 | cxx_compiler = _SCRIPTS + "/zxx", |
| 52 | linker = _SCRIPTS + "/zcc", |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 53 | visibility = ["PUBLIC"], |
| 54 | ) |
| 55 | |
| 56 | system_genrule_toolchain( |
| 57 | name = "genrule", |
| 58 | visibility = ["PUBLIC"], |
| 59 | ) |
| 60 | |
| 61 | system_python_bootstrap_toolchain( |
| 62 | name = "python_bootstrap", |
| 63 | visibility = ["PUBLIC"], |
| 64 | ) |
| 65 | |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 66 | # The compiler is the dist tarball in toolchains//dist, not a name resolved |
| 67 | # against the machine. See defs.bzl for why that distinction is the whole |
| 68 | # point, and dist.bzl for where the tarball comes from. |
| 69 | hermetic_rust_toolchain( |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 70 | name = "rust", |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 71 | dist = "toolchains//dist:rust", |
| 72 | wrapper = "toolchains//:rustc.sh", |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 73 | default_edition = "2021", |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 74 | rustc_flags = [ |
| 75 | "-Clinker=" + _SCRIPTS + "/zcc", |
| 76 | # What [profile.release] in Cargo.toml says, and for the reason given |
| 77 | # there: the tree walk and the texture uploads are hot every frame, and |
| 78 | # the media plane decodes H.264. buck2 optimises nothing by default, so |
| 79 | # without this the two objects are debug builds wearing release names. |
| 80 | # OPT_LEVEL=2 in the buildscript fixups is the same setting for the C. |
| 81 | "-Copt-level=2", |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 82 | "--cfg=jolt_cc=\"" + _ZIG_VERSION + "\"", |
| Build both objects under buck2, against the BuildBuddy cache 600f207 nandi 19d ago | 83 | ], |
| Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago | 84 | # A plain string rather than a select: the sysroot path inside the dist |
| 85 | # tarball is built from this, and only the triples dist.bzl fetches an |
| 86 | # archive for can be named here. |
| 87 | rustc_target_triple = "x86_64-unknown-linux-gnu", |
| 88 | visibility = ["PUBLIC"], |
| 89 | ) |
| 90 | |
| 91 | # The wrapper the Rust toolchain runs rustc through, as an artifact so it is an |
| 92 | # input to every action that compiles anything. |
| 93 | export_file( |
| 94 | name = "rustc.sh", |
| 95 | mode = "reference", |
| Build under buck2, with the toolchain pinned rather than found 460541b nandi 19d ago | 96 | visibility = ["PUBLIC"], |
| 97 | ) |