build(release): switch x86_64 Linux release artifacts to musl (#4391) Previously, `x86_64` Linux release artifacts linked static `glibc`, inflating `exe_zip_maker` to 1.37 MB with over 840 KB of static `glibc` code and tables. Switch the `x86_64` Linux release platform and toolchain registration to `x86_64-unknown-linux-musl` linked with `rust-lld`. This matches the other Linux architectures, avoids host `glibc` and `ld.bfd` quirks, and shrinks the statically linked binary to ~603 KB while preserving portability across Linux distributions. Work towards #4216
diff --git a/MODULE.bazel b/MODULE.bazel index a03eb49..21a6e53 100644 --- a/MODULE.bazel +++ b/MODULE.bazel
@@ -160,9 +160,9 @@ bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True) bazel_dep(name = "rules_pkg", version = "1.2.0", dev_dependency = True) -# Rust toolchains to cross-compile the release artifacts for other Linux CPUs -# from Linux x86_64; see dev/release_artifacts. They target musl, which Rust can -# link statically with its bundled rust-lld, so no C cross toolchain is needed. +# Rust toolchains to build the release artifacts for Linux from Linux x86_64; +# see dev/release_artifacts. They target musl, which Rust can link statically +# with its bundled rust-lld, so no C cross toolchain is needed. rust = use_extension( "@rules_rust//rust:extensions.bzl", "rust", @@ -227,6 +227,15 @@ ], target_triple = "riscv64gc-unknown-linux-musl", ) +rust.repository_set( + name = "rust_release_linux", + target_compatible_with = [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + "//dev/platforms:musl", + ], + target_triple = "x86_64-unknown-linux-musl", +) use_repo( rust, "rust_release_linux__aarch64-unknown-linux-musl__stable", @@ -234,6 +243,7 @@ "rust_release_linux__i686-unknown-linux-musl__stable", "rust_release_linux__powerpc64le-unknown-linux-musl__stable", "rust_release_linux__riscv64gc-unknown-linux-musl__stable", + "rust_release_linux__x86_64-unknown-linux-musl__stable", ) # Registered here so that they take precedence over rules_rust's default @@ -245,6 +255,7 @@ "@rust_release_linux__i686-unknown-linux-musl__stable//:toolchain", "@rust_release_linux__powerpc64le-unknown-linux-musl__stable//:toolchain", "@rust_release_linux__riscv64gc-unknown-linux-musl__stable//:toolchain", + "@rust_release_linux__x86_64-unknown-linux-musl__stable//:toolchain", dev_dependency = True, )
diff --git a/dev/platforms/BUILD.bazel b/dev/platforms/BUILD.bazel index 17f19cc..590d302 100644 --- a/dev/platforms/BUILD.bazel +++ b/dev/platforms/BUILD.bazel
@@ -111,10 +111,11 @@ ) platform( - name = "x86_64-unknown-linux-gnu", + name = "x86_64-unknown-linux-musl", constraint_values = [ "@platforms//cpu:x86_64", "@platforms//os:linux", + ":musl", ], )
diff --git a/dev/release_artifacts/BUILD.bazel b/dev/release_artifacts/BUILD.bazel index 26895e1..54d26f4 100644 --- a/dev/release_artifacts/BUILD.bazel +++ b/dev/release_artifacts/BUILD.bazel
@@ -40,7 +40,7 @@ "//dev/platforms:i686-unknown-linux-musl", "//dev/platforms:powerpc64le-unknown-linux-musl", "//dev/platforms:riscv64gc-unknown-linux-musl", - "//dev/platforms:x86_64-unknown-linux-gnu", + "//dev/platforms:x86_64-unknown-linux-musl", ], ":is_macos_aarch64": ["//dev/platforms:x86_64-apple-darwin"], ":is_windows_x86_64": ["//dev/platforms:i686-pc-windows-msvc"],
diff --git a/dev/release_artifacts/release_files.bzl b/dev/release_artifacts/release_files.bzl index e9604cd..b91541d 100644 --- a/dev/release_artifacts/release_files.bzl +++ b/dev/release_artifacts/release_files.bzl
@@ -123,7 +123,7 @@ machine's, without extra runtime libraries. The paths, one per line, are relative to the execroot, e.g. - `bazel-out/k8-opt/bin/dev/release_artifacts/foo-x86_64-unknown-linux-gnu`. + `bazel-out/k8-opt/bin/dev/release_artifacts/foo-x86_64-unknown-linux-musl`. Paths of generated files also resolve from the workspace root through the `bazel-out` convenience symlink. This lets scripts find the files without running `bazel cquery`, which re-analyzes the build.
diff --git a/tests/workflows/release_artifacts_test.py b/tests/workflows/release_artifacts_test.py index b66b38d..95637c0 100644 --- a/tests/workflows/release_artifacts_test.py +++ b/tests/workflows/release_artifacts_test.py
@@ -23,7 +23,7 @@ manifest_json_file = tmp_path / "artifacts_manifest.json" manifest_bzl_file = tmp_path / "artifacts_manifest.bzl" - linux_bin = artifacts_dir / "exe_zip_maker-x86_64-unknown-linux-gnu" + linux_bin = artifacts_dir / "exe_zip_maker-x86_64-unknown-linux-musl" linux_bin.write_bytes(b"linux-binary-contents") linux_sha = hashlib.sha256(b"linux-binary-contents").hexdigest() @@ -80,9 +80,9 @@ "@platforms//cpu:x86_64", "@platforms//os:linux", ], - "name": "exe_zip_maker_x86_64_unknown_linux_gnu", + "name": "exe_zip_maker_x86_64_unknown_linux_musl", "sha256": linux_sha, - "urls": [f"{base_url}/exe_zip_maker-x86_64-unknown-linux-gnu"], + "urls": [f"{base_url}/exe_zip_maker-x86_64-unknown-linux-musl"], }, ] }