Skip to content

Commit a7d873a

Browse files
authored
Flake update fixes (#2192)
* Fix coverage compiler * Use nightly rust for nightly artifacts * Correct minor issue in is-executable-test * Add update-module-hashes
1 parent 77b13f0 commit a7d873a

File tree

6 files changed

+62
-14
lines changed

6 files changed

+62
-14
lines changed

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ rust.toolchain(
7979
rust_analyzer_version = "nightly/2025-05-21",
8080
rustfmt_version = "nightly/2025-05-21",
8181
sha256s = {
82+
# Update the shas with update-module-hashes
83+
# BEGIN SHAS
8284
"2025-05-21/cargo-nightly-x86_64-unknown-linux-gnu.tar.xz": "e866f249dfbdf10a68b7191c025257591e8a5aa2fede1663b34c88a4f4bb8a74",
8385
"2025-05-21/clippy-nightly-x86_64-unknown-linux-gnu.tar.xz": "0a312d722a94e3b9e1f7871d9a9af01d410917c2406dbf91d014c06fe79540fb",
8486
"2025-05-21/llvm-tools-nightly-x86_64-unknown-linux-gnu.tar.xz": "eee28e99ac24c27f3de969915e808c0645ee099b136e5547681110607d09d050",
@@ -97,6 +99,7 @@ rust.toolchain(
9799
"rust-std-1.87.0-x86_64-unknown-linux-gnu.tar.xz": "1b57253bd32b8b292c965b3a2d992a266763158494cab8555584c09360b90f77",
98100
"rustc-1.87.0-aarch64-apple-darwin.tar.xz": "175800bc89cccd8f8ee2f3a4d07bdf98c163030fd5d3dc6d5b23cf4dd0a2a4c3",
99101
"rustc-1.87.0-x86_64-unknown-linux-gnu.tar.xz": "e8395c5c5756253b76107055e093ffbc4431af7b30aeebe72ce2684b9cb53973",
102+
# END SHAS
100103
},
101104
versions = [
102105
"1.87.0",

flake.nix

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@
150150
}
151151
// (pkgs.lib.optionalAttrs isLinuxTarget {
152152
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
153+
TARGET_CC = "${pkgs.lre.clang}/bin/customClang";
153154
${linkerEnvVar} = linkerPath;
154155
});
155156

156157
# Additional target for external dependencies to simplify caching.
157158
cargoArtifactsFor = p: (craneLibFor p).buildDepsOnly (commonArgsFor p);
158-
nightlyCargoArtifactsFor = p: (craneLibFor p).buildDepsOnly (commonArgsFor p);
159+
nightlyCargoArtifactsFor = p: (nightlyCraneLibFor p).buildDepsOnly (commonArgsFor p);
159160

160161
nativelinkFor = p:
161162
(craneLibFor p).buildPackage ((commonArgsFor p)
@@ -291,16 +292,7 @@
291292

292293
nativelinkCoverageFor = p: let
293294
coverageArgs =
294-
(commonArgsFor p)
295-
// {
296-
# TODO(palfrey): For some reason we're triggering an edgecase where
297-
# mimalloc builds against glibc headers in coverage
298-
# builds. This leads to nonexistend __memcpy_chk and
299-
# __memset_chk symbols if fortification is enabled.
300-
# Our regular builds also have this issue, but we
301-
# should investigate further.
302-
hardeningDisable = ["fortify"];
303-
};
295+
commonArgsFor p;
304296
in
305297
(nightlyCraneLibFor p).cargoLlvmCov (coverageArgs
306298
// {
@@ -381,7 +373,12 @@
381373
buck2-with-nativelink-test = pkgs.callPackage integration_tests/buck2/buck2-with-nativelink-test.nix {
382374
inherit nativelink buck2;
383375
};
384-
376+
update-module-hashes = pkgs.callPackage tools/updaters/rewrite-module.nix {
377+
python-with-requests = pkgs.python3.withPackages (ps:
378+
with ps; [
379+
ps.requests
380+
]);
381+
};
385382
generate-bazel-rc = pkgs.callPackage tools/generate-bazel-rc/build.nix {craneLib = craneLibFor pkgs;};
386383
generate-stores-config = pkgs.callPackage nativelink-config/generate-stores-config/build.nix {craneLib = craneLibFor pkgs;};
387384
}
@@ -466,6 +463,7 @@
466463
pkgs.pre-commit
467464
pkgs.git-cliff
468465
pkgs.buck2
466+
packages.update-module-hashes
469467

470468
# Rust
471469
bazel

tools/nativelink-is-executable-test.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
writeShellScriptBin,
44
}:
55
writeShellScriptBin "is-executable-test" ''
6-
set -xuo pipefail
6+
set -uo pipefail
77
88
nativelink_output="$(${nativelink}/bin/nativelink 2>&1)"
99
@@ -14,7 +14,8 @@ writeShellScriptBin "is-executable-test" ''
1414
Usage: nativelink <CONFIG_FILE>
1515
1616
For more information, try '--help'.
17-
EOF)
17+
EOF
18+
)
1819
1920
if [ "$nativelink_output" = "$print_error_output" ]; then
2021
echo "The output of nativelink matches the print_error output."

tools/updaters/cache/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tar.xz

tools/updaters/rewrite-module.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
python-with-requests,
3+
writeShellScriptBin,
4+
}:
5+
writeShellScriptBin "update-module-hashes" ''
6+
set -uo pipefail
7+
8+
${python-with-requests}/bin/python tools/updaters/rewrite-module.py MODULE.bazel
9+
''

tools/updaters/rewrite-module.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import re
2+
import subprocess
3+
import requests
4+
import sys
5+
import pathlib
6+
7+
module_bazel_path = sys.argv[1]
8+
cache_dir = pathlib.Path(__file__).parent.joinpath("cache")
9+
cache_dir.mkdir(exist_ok=True)
10+
11+
original = open(module_bazel_path).read()
12+
begin_shas = re.search("# BEGIN SHAS\n", original).end() # pyright: ignore[reportOptionalMemberAccess]
13+
end_shas = re.search("\n # END SHAS", original).start() # pyright: ignore[reportOptionalMemberAccess]
14+
print(begin_shas, end_shas)
15+
sha_pattern = re.compile(r"\"(.+\.tar\.xz)\": \"([0-9a-f]+)\"")
16+
17+
results = ""
18+
19+
for entry in sha_pattern.finditer(original, begin_shas, end_shas):
20+
short_url, hash = entry.groups()
21+
cache_path = cache_dir.joinpath(short_url.replace("/", "_"))
22+
if not cache_path.exists():
23+
full_url = f"https://static.rust-lang.org/dist/{short_url}"
24+
print("getting", full_url, cache_path)
25+
req = requests.get(full_url)
26+
with cache_path.open("wb") as f:
27+
f.write(req.content)
28+
sha256_cmd = subprocess.check_output(["sha256sum", cache_path.as_posix()], encoding="utf-8")
29+
sha256 = sha256_cmd.split(" ")[0]
30+
if results != "":
31+
results += "\n"
32+
results += f" \"{short_url}\": \"{sha256}\","
33+
34+
revised = original[:begin_shas] + results + original[end_shas:]
35+
with open(module_bazel_path, "w") as f:
36+
f.write(revised)

0 commit comments

Comments
 (0)