1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
load(":defs.bzl", "hermetic_cxx_toolchain", "hermetic_rust_toolchain")
load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain")
load("@prelude//toolchains:python.bzl", "system_python_bootstrap_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.
#
# rustc does not come this way any more — see the toolchain at the bottom of
# this file. These three are what is left to make into dependencies.
_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.
# The C toolchain's version, written by the `buck` recipe alongside the paths.
#
# rustc no longer needs this: it is a dependency now, so its identity is in
# every action's digest and two compilers cannot collide on one cache entry.
# zig still does. It is named by an absolute path that does not change when the
# binary behind it does, so a version bump would silently reuse entries built
# by the old one — the E0514 failure, one toolchain over. Naming the version in
# a cfg nothing reads keeps the digests apart until zig is a dependency too.
_ZIG_VERSION = read_root_config("jolt", "zig_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.
hermetic_cxx_toolchain(
name = "cxx",
dist = "toolchains//dist:zig",
wrapper = "toolchains//:zcc.sh",
visibility = ["PUBLIC"],
)
system_genrule_toolchain(
name = "genrule",
visibility = ["PUBLIC"],
)
system_python_bootstrap_toolchain(
name = "python_bootstrap",
visibility = ["PUBLIC"],
)
# The compiler is the dist tarball in toolchains//dist, not a name resolved
# against the machine. See defs.bzl for why that distinction is the whole
# point, and dist.bzl for where the tarball comes from.
hermetic_rust_toolchain(
name = "rust",
dist = "toolchains//dist:rust",
wrapper = "toolchains//:rustc.sh",
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_cc=\"" + _ZIG_VERSION + "\"",
],
# A plain string rather than a select: the sysroot path inside the dist
# tarball is built from this, and only the triples dist.bzl fetches an
# archive for can be named here.
rustc_target_triple = "x86_64-unknown-linux-gnu",
visibility = ["PUBLIC"],
)
# The wrapper the Rust toolchain runs rustc through, as an artifact so it is an
# input to every action that compiles anything.
export_file(
name = "zcc.sh",
mode = "reference",
visibility = ["PUBLIC"],
)
export_file(
name = "rustc.sh",
mode = "reference",
visibility = ["PUBLIC"],
)
|