Skip to content

Commit 205087e

Browse files
committed
pkgs/_bootstrap/clang, pkgs/stdenv/clang: build-dir reproducibility fixes
1 parent be847ac commit 205087e

3 files changed

Lines changed: 48 additions & 21 deletions

File tree

.maint/hashes

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
cr1bxa6hjz1baygh7kdwmhgxvypqcvag bootstrap-toolchain
33
2f7xfn3x1bgpy1wdrnn48z3c1bagwggh bootstrap-busybox
44
w4gcaxrzw0jg1darbh5m1kqc2chi916l stdenv.musl
5-
nl6ki5lh9m3nqj10pljwvfrbihpcin3k stdenv.clang^toolchain
6-
zc6lnh6w6akpn6gw819xa1fl9jpjdxgd stdenv.clang^sysroot
5+
b9hw86jiv5633wxnqmgfvppjzj4gyb42 stdenv.clang^toolchain
6+
y2cxnwccxv568n1qyq0k8hhd46paakyh stdenv.clang^sysroot
77
xd59ibybsg7a3xmfv2jawhsklsh3y5cw stdenv.busybox
8-
81j8zwidvjzkzgawbkgynx9asc5xqmnv stdenv.patchelf
8+
3drv7qr3l6yg884aydvnsfg8liay7n8b stdenv.patchelf
99
rayis1a5x2vbnvx2rn2p101p6hkjr80s gnumake
1010
nk2z6rqnd29lm71y3m90lknhnkhy59aq pkg-config
1111
k2xrd04a2rg5544ybx7m5ighzgbg3qsa zstd
@@ -35,8 +35,8 @@ ybxc8hcw1jlik2gikfy75jdr235irb74 editline
3535
ib8rkp6syqjl53ihgw3ivrj2875m8iaz libsodium
3636
blifdiax8l3anpvfbz0q12h6xikj11xz libarchive
3737
kva7q87mxpnh51ms9nsn0q13yg3nx3cn nlohmann_json
38-
f7633g4nyffhhb2qxjzmgp1zbb4696q8 nix
39-
89h5i0h2yghwgaj19lfqpsqp0mg5csq6 live-cd^initscript
40-
20pw1kdqalgybjqcxlsxwrb259z9rq7n live-cd^initrd
38+
4fnlcxja9lqsha8a6aq53qkqvd3rrawa nix
39+
4j81lc5b1niai5kmay1bs5ziy918abic live-cd^initscript
40+
0nvqsapj0ynqd4nqhcb7q6kls7dl7s5l live-cd^initrd
4141
00knav8mnf7nsq6p34xv5ax9rl68kxzz live-cd^limine_config
42-
l4a6183ziakj977gc7d1rzf9jlcc2psk live-cd^iso
42+
p29sxck8mymhc72jaaq294hj7vj422hy live-cd^iso

pkgs/_bootstrap/clang.nix

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ in
1212
inherit name;
1313
buildInputs = [ busybox toolchain cmake gnumake python ];
1414
script = ''
15-
mkdir build-dir; cd build-dir
15+
# Shared libs are not relinked on install. Instead, their rpath
16+
# is erased with RPATH_SET: `Set runtime path of
17+
# "/nix/store/.../lib/x86_64-unknown-linux-musl/libc++.so.1.0" to ""`
18+
# One (hacky) workaround to that is using a constant-len build-dir.
19+
build_dir=build-dir; expr "$(pwd)/$build_dir)" '<=' 128
20+
while ! echo "$(pwd)/$build_dir" | wc -c | grep -Fqx 128; do
21+
build_dir="$build_dir."
22+
done; expr "$(echo $(pwd)/$build_dir | wc -c)" '==' 128
23+
mkdir $build_dir; cd $build_dir
1624
export SHELL=${busybox}/bin/ash
1725
# llvm cmake configuration should pick up ccache automatically from PATH
1826
export PATH="$PATH:/ccache/bin"
@@ -39,7 +47,10 @@ in
3947
llvm/cmake/modules/AddLLVM.cmake
4048
sed -i 's|numShards = 32;|numShards = 1;|' lld/*/SyntheticSections.*
4149
sed -i 's|numShards = 256;|numShards = 1;|' lld/*/ICF.cpp
42-
sed -i 's|__FILE__|__FILE_NAME__|' compiler-rt/lib/builtins/int_util.h
50+
sed -i 's|__FILE__|__FILE_NAME__|' \
51+
libcxx/src/verbose_abort.cpp \
52+
libcxxabi/src/abort_message.cpp \
53+
compiler-rt/lib/builtins/int_util.h
4354
# figure out includes:
4455
KHDR=${linux-headers}/include
4556
EXTRA_INCL=$(pwd)/extra_includes

pkgs/stdenv/clang.nix

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{ pname ? "clang", fetchurl, stdenv, gnumake, linux-headers, cmake, python}:
22

3-
stdenv.mkDerivation {
4-
pname = pname;
5-
version = "17.0.1";
6-
3+
let
74
src = fetchurl { # parsed by other tooling, must be of fixed format
85
# local = /downloads/llvm-project-17.0.1.src.tar.xz;
96
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.1/llvm-project-17.0.1.src.tar.xz";
107
sha256 = "b0e42aafc01ece2ca2b42e3526f54bebc4b1f1dc8de6e34f46a0446a13e882b9";
118
};
9+
in
10+
11+
stdenv.mkDerivation {
12+
inherit pname src;
13+
version = "17.0.1";
1214

1315
buildInputs = [ stdenv.busybox gnumake cmake python ];
1416
# stdenv.clang not added to PATH on purpose to avoid confusion
@@ -28,7 +30,10 @@ stdenv.mkDerivation {
2830
llvm/cmake/modules/AddLLVM.cmake
2931
sed -i 's|numShards = 32;|numShards = 1;|' lld/*/SyntheticSections.*
3032
sed -i 's|numShards = 256;|numShards = 1;|' lld/*/ICF.cpp
31-
sed -i 's|__FILE__|__FILE_NAME__|' compiler-rt/lib/builtins/int_util.h
33+
sed -i 's|__FILE__|__FILE_NAME__|' \
34+
libcxx/src/verbose_abort.cpp \
35+
libcxxabi/src/abort_message.cpp \
36+
compiler-rt/lib/builtins/int_util.h
3237
'';
3338

3439
preConfigure = ''
@@ -40,6 +45,15 @@ stdenv.mkDerivation {
4045
'';
4146

4247
configurePhase = ''
48+
# Shared libs are not relinked on install. Instead, their rpath
49+
# is erased with RPATH_SET: `Set runtime path of
50+
# "/nix/store/.../lib/x86_64-unknown-linux-musl/libc++.so.1.0" to ""`
51+
# One (hacky) workaround to that is using a constant-len build-dir.
52+
build_dir=build; expr "$(pwd)/$build_dir)" '<=' 134
53+
while ! echo "$(pwd)/$build_dir" | wc -c | grep -Fqx 134; do
54+
build_dir="$build_dir."
55+
done; mkdir $build_dir; expr "$(echo $(pwd)/build* | wc -c)" '==' 134
56+
4357
export SHELL=${stdenv.busybox}/bin/ash
4458
LOADER=${stdenv.musl}/lib/libc.so
4559
@@ -59,12 +73,12 @@ stdenv.mkDerivation {
5973
6074
export LD_LIBRARY_PATH="${stdenv.musl}/lib:${stdenv.clang}/lib"
6175
export LD_LIBRARY_PATH=${python}/lib:$LD_LIBRARY_PATH
62-
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/build/lib" # libLLVM
76+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/$build_dir/lib" # libLLVM
6377
6478
REWRITE="-ffile-prefix-map=$(pwd)=/builddir/"
6579
CFLAGS="--sysroot=$(pwd)/sysroot -isystem $EXTRA_INCL $REWRITE"
6680
LDFLAGS="-Wl,--dynamic-linker=$LOADER"
67-
cmake -S llvm -B build -G 'Unix Makefiles' \
81+
cmake -S llvm -B build* -G 'Unix Makefiles' \
6882
-DCMAKE_ASM_COMPILER=${stdenv.clang}/bin/clang \
6983
-DCMAKE_C_COMPILER=${stdenv.clang}/bin/clang \
7084
-DCMAKE_CXX_COMPILER=${stdenv.clang}/bin/clang++ \
@@ -124,21 +138,23 @@ stdenv.mkDerivation {
124138
'';
125139

126140
buildPhase = ''
141+
build_dir=$(echo build*)
127142
export SHELL=${stdenv.busybox}/bin/ash
128143
export LD_LIBRARY_PATH="${stdenv.musl}/lib:${stdenv.clang}/lib"
129144
export LD_LIBRARY_PATH=${python}/lib:$LD_LIBRARY_PATH
130-
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/build/lib" # libLLVM
145+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/$build_dir/lib" # libLLVM
131146
132147
# llvm cmake configuration should pick up ccache automatically from PATH
133-
make -C build -j $NPROC
148+
make -C build* -j $NPROC
134149
'';
135150

136151
installPhase = ''
152+
build_dir=$(echo build*)
153+
export SHELL=${stdenv.busybox}/bin/ash
137154
export LD_LIBRARY_PATH="${stdenv.musl}/lib:${stdenv.clang}/lib"
138155
export LD_LIBRARY_PATH=${python}/lib:$LD_LIBRARY_PATH
139-
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/build/lib" # libLLVM
140-
export SHELL=${stdenv.busybox}/bin/ash
141-
make -C build -j $NPROC install/strip
156+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/$build_dir/lib" # libLLVM
157+
make -C build* -j $NPROC install/strip
142158
'';
143159

144160
postInstall = ''

0 commit comments

Comments
 (0)