load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain") load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain") load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain") load("@prelude//toolchains:rust.bzl", "system_rust_toolchain") # Tools come from the DotSlash files in scripts/, so the build depends on # pinned upstream releases rather than whatever the host happens to have. # # The paths are absolute, and read out of .buckconfig.local rather than written # here, because neither of the obvious spellings works. A build script runs in # a directory of its own, and the prelude re-execs the compiler from there, so # a project-relative `scripts/zcc` is not found; and the shim that does the # re-exec calls os.execl rather than os.execlp, so a bare `zcc` on PATH is not # found either. aws-lc-sys is where both show up. The `buck` recipe in justfile # writes that file, so the absolute paths are generated rather than committed. _SCRIPTS = read_root_config("jolt", "scripts", "scripts") # The compiler's version, written by the `buck` recipe alongside the paths. # # It has to reach the actions somehow, because the prelude names rustc as the # bare string "rustc" — the binary is not an input, so its identity is not in # any action's cache digest. Two compilers therefore produce artifacts under # the same digest, and a shared cache will hand one build the other's rlibs; # the failure is E0514, a long way from the cause. Naming the version in a cfg # nothing reads is enough to keep the digests apart. _RUSTC_VERSION = read_root_config("jolt", "rustc_version", "unknown") # # This is the same arrangement .cargo/config.toml used to describe: zig cc # carries its own glibc sysroot, which is why this repo builds on a machine # with no `cc` at all. Unlike vidya there is no Android row here — both shared # objects this repo ships are desktop, and the APK takes its libvidya from # vidya's own buck2 build. system_cxx_toolchain( name = "cxx", # `ar` would otherwise come off the host, which is the one thing this # toolchain is arranged not to do. archiver = _SCRIPTS + "/zar", compiler = _SCRIPTS + "/zcc", compiler_type = "clang", cxx_compiler = _SCRIPTS + "/zxx", linker = _SCRIPTS + "/zcc", visibility = ["PUBLIC"], ) system_genrule_toolchain( name = "genrule", visibility = ["PUBLIC"], ) system_python_bootstrap_toolchain( name = "python_bootstrap", visibility = ["PUBLIC"], ) system_rust_toolchain( name = "rust", default_edition = "2021", rustc_flags = [ "-Clinker=" + _SCRIPTS + "/zcc", # What [profile.release] in Cargo.toml says, and for the reason given # there: the tree walk and the texture uploads are hot every frame, and # the media plane decodes H.264. buck2 optimises nothing by default, so # without this the two objects are debug builds wearing release names. # OPT_LEVEL=2 in the buildscript fixups is the same setting for the C. "-Copt-level=2", "--cfg=jolt_rustc=\"" + _RUSTC_VERSION + "\"", ], rustc_target_triple = select({ "prelude//os:linux": select({ "prelude//cpu:arm64": "aarch64-unknown-linux-gnu", "prelude//cpu:x86_64": "x86_64-unknown-linux-gnu", }), "prelude//os:macos": select({ "prelude//cpu:arm64": "aarch64-apple-darwin", "prelude//cpu:x86_64": "x86_64-apple-darwin", }), }), visibility = ["PUBLIC"], )