8facd237d5
- Replaced the napi-cli/cargo-zigbuild/cargo-xwin/sccache build path with Bazel: rules_rust + crate_universe over Cargo.lock, hermetic zig cc toolchains (linux-gnu pinned to glibc 2.17, linux-musl), host Xcode for darwin, and a repo-local hermetic clang-cl + llvm-ml + xwin toolchain for windows-msvc (bazel/toolchains/msvc). - All eight shipped addons build as //:natives-<target> via the release transition in bazel/defs.bzl (opt, thin LTO, cgu=16, stripped, canonical .node naming); scripts/bazel-natives.ts is the single driver for local dev and CI. - Rust validation moved to bazel test + clippy aspects (strict workspace policy for opted-in crates, default lints elsewhere, mirroring cargo semantics) and the rustfmt aspect; cargo stays as the dev-iteration surface, with brush-core/brush-builtins promoted to workspace members and excluded from cargo dev tasks to keep their historical scope. - CI caches through an in-cluster bazel-remote action cache (TLS + basic auth, cluster-internal only); GitHub-hosted runners never touch the infrastructure and use an actions/cache-backed disk cache instead. - Deleted the hand-rolled caching machinery: ci-target-cache, ci-native-artifact-cache, ci-build-native, native-source-hash, find-native-artifacts, restore-linux-native, native-prewarm workflow, ensure-* toolchain actions, and all sccache/Swatinem wiring. - Warm native rebuilds drop from ~20 minutes to seconds; a cold client with a warm remote cache rebuilds the linux x64 pair in ~2.5 minutes.
157 lines
5.4 KiB
Python
157 lines
5.4 KiB
Python
"""Repository rule materializing the MSVC CRT + Windows SDK sysroot via xwin.
|
|
|
|
Downloads a pinned xwin release binary (github.com/Jake-Shadle/xwin) for the
|
|
host that fetches the repo and runs `xwin --accept-license splat`, producing:
|
|
|
|
splat/crt/include VC toolset headers
|
|
splat/crt/lib/x86_64 VC toolset libs (msvcrt.lib & co)
|
|
splat/sdk/include/{ucrt,um,shared,winrt,cppwinrt}
|
|
splat/sdk/lib/{ucrt,um}/x86_64
|
|
|
|
Cache implications: only the small xwin binary tarball goes through Bazel's
|
|
repository cache. The CRT/SDK payload (~1 GiB) is downloaded from the
|
|
Microsoft CDN by xwin itself inside this rule, so a cold fetch (clean
|
|
--expunge, sysroot.bzl edit, new output base) re-downloads it. The xwin
|
|
download cache is deleted after splatting to keep the repo at ~800 MiB.
|
|
Keep this file stable; wrapper/toolchain iteration lives in cc.bzl precisely
|
|
so it never invalidates this repo.
|
|
|
|
Reproducibility: --manifest-version pins the VS channel (17 = VS2022), but
|
|
Microsoft advances the channel's payload over time, so the splat is stable
|
|
day-to-day, not bit-reproducible forever — same property the cargo-xwin
|
|
pipeline had.
|
|
|
|
xwin release binaries stop shipping darwin builds after 0.6.5; 0.6.5 is the
|
|
newest version covering linux-musl + darwin hosts, which is why it is pinned.
|
|
"""
|
|
|
|
_XWIN_VERSION = "0.6.5"
|
|
_XWIN_MANIFEST_VERSION = "17"
|
|
|
|
# host key -> (release triple, sha256), from the published .sha256 assets.
|
|
_XWIN_DISTS = {
|
|
"linux-arm64": ("aarch64-unknown-linux-musl", "5e131007fad7c5f30d2f41090b49937fb8f16a787e5a95b4b3140e88d174dab2"),
|
|
"linux-x64": ("x86_64-unknown-linux-musl", "9fd53950b064d067f42428a69453b927656cae68dbd7f8d3f86dcb81c80dd22d"),
|
|
"macos-arm64": ("aarch64-apple-darwin", "21acd1e35d23b72efc8c47cbeda5028989f98089174b8c87074f892b65adbc01"),
|
|
"macos-x64": ("x86_64-apple-darwin", "ecb2b19b30fa3786749fae600ad60b034b0c1c6a604ecf9f35f682c23a40e54b"),
|
|
}
|
|
|
|
def _host_key(rctx):
|
|
os_name = rctx.os.name.lower()
|
|
arch = rctx.os.arch.lower()
|
|
if os_name.startswith("linux"):
|
|
host_os = "linux"
|
|
elif os_name.startswith("mac") or os_name.startswith("darwin"):
|
|
host_os = "macos"
|
|
else:
|
|
fail("bazel/toolchains/msvc: unsupported exec host OS for xwin: " + rctx.os.name)
|
|
if arch in ("amd64", "x86_64", "x64"):
|
|
host_cpu = "x64"
|
|
elif arch in ("aarch64", "arm64"):
|
|
host_cpu = "arm64"
|
|
else:
|
|
fail("bazel/toolchains/msvc: unsupported exec host CPU for xwin: " + rctx.os.arch)
|
|
return host_os + "-" + host_cpu
|
|
|
|
_BUILD = """\
|
|
# Generated by //bazel/toolchains/msvc:sysroot.bzl — MSVC CRT + Windows SDK
|
|
# splatted by xwin {version} (manifest-version {manifest}). Consumed by the
|
|
# @msvc_cc wrappers via /imsvc and /libpath.
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
filegroup(
|
|
name = "crt_includes",
|
|
srcs = glob(["splat/crt/include/**"]),
|
|
)
|
|
|
|
filegroup(
|
|
name = "crt_libs",
|
|
srcs = glob(["splat/crt/lib/**"]),
|
|
)
|
|
|
|
filegroup(
|
|
name = "sdk_includes",
|
|
srcs = glob(["splat/sdk/include/**"]),
|
|
)
|
|
|
|
filegroup(
|
|
name = "sdk_libs",
|
|
srcs = glob(["splat/sdk/lib/**"]),
|
|
)
|
|
|
|
filegroup(
|
|
name = "sysroot",
|
|
srcs = [
|
|
":crt_includes",
|
|
":crt_libs",
|
|
":sdk_includes",
|
|
":sdk_libs",
|
|
],
|
|
)
|
|
"""
|
|
|
|
def _xwin_sysroot_impl(rctx):
|
|
key = _host_key(rctx)
|
|
if key not in _XWIN_DISTS:
|
|
fail("bazel/toolchains/msvc: no pinned xwin release binary for host " + key)
|
|
triple, sha256 = _XWIN_DISTS[key]
|
|
prefix = "xwin-{}-{}".format(_XWIN_VERSION, triple)
|
|
rctx.download_and_extract(
|
|
url = "https://github.com/Jake-Shadle/xwin/releases/download/{}/{}.tar.gz".format(_XWIN_VERSION, prefix),
|
|
sha256 = sha256,
|
|
stripPrefix = prefix,
|
|
)
|
|
rctx.report_progress("Splatting MSVC CRT + Windows SDK via xwin (first fetch ~1 GiB from the Microsoft CDN)")
|
|
result = rctx.execute(
|
|
[
|
|
rctx.path("xwin"),
|
|
"--accept-license",
|
|
"--arch",
|
|
"x86_64",
|
|
"--variant",
|
|
"desktop",
|
|
"--manifest-version",
|
|
_XWIN_MANIFEST_VERSION,
|
|
"--cache-dir",
|
|
".xwin-cache",
|
|
"splat",
|
|
"--copy",
|
|
"--output",
|
|
"splat",
|
|
],
|
|
timeout = 3600,
|
|
)
|
|
if result.return_code != 0:
|
|
fail("bazel/toolchains/msvc: xwin splat failed (exit {}):\n{}\n{}".format(
|
|
result.return_code,
|
|
result.stdout,
|
|
result.stderr,
|
|
))
|
|
|
|
# Drop the download cache (the splat is a --copy, not links into it).
|
|
rctx.delete(".xwin-cache")
|
|
|
|
# xwin drops `<sdk-version> -> .` alias symlinks (e.g. sdk/lib/10.0.26100)
|
|
# so version-qualified include/lib paths resolve. They are self-referential
|
|
# directory cycles, which Bazel's glob refuses to traverse — and nothing in
|
|
# this toolchain uses version-qualified paths, so drop them.
|
|
for dirname in ("splat/sdk/include", "splat/sdk/lib", "splat/crt/lib", "splat/crt/include"):
|
|
dirpath = rctx.path(dirname)
|
|
if not dirpath.exists:
|
|
continue
|
|
for entry in dirpath.readdir():
|
|
if entry.realpath == dirpath.realpath:
|
|
rctx.delete(entry)
|
|
|
|
rctx.file(
|
|
"BUILD.bazel",
|
|
_BUILD.format(version = _XWIN_VERSION, manifest = _XWIN_MANIFEST_VERSION),
|
|
executable = False,
|
|
)
|
|
|
|
xwin_sysroot_repository = repository_rule(
|
|
implementation = _xwin_sysroot_impl,
|
|
doc = "MSVC CRT + Windows SDK sysroot splatted by a pinned xwin release.",
|
|
)
|