Skip to content

Commit 73fe6e6

Browse files
committed
Avoid dependencies of build-deps on MacOS by pinning cc
Sadly we have to hack around cargo to make this work with `-Zbuild-std`.
1 parent c1c9f6e commit 73fe6e6

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

genbindings.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,33 @@ if [ "$2" = "true" ]; then
353353
ls -lha a.out
354354
fi
355355

356+
function REALLY_PIN_CC {
357+
# -Zbuild-std fails if we have any dependencies of build-deps, which
358+
# cc added in 1.0.80, thus we pin back to 1.0.79 to avoid that.
359+
cargo update -p cc --precise "1.0.79" --verbose
360+
( cargo build --features=std -v --release -Zbuild-std=std,panic_abort > /dev/null 2>&1 ) || echo -n
361+
( cargo build --features=std -v --release --target aarch64-apple-darwin -Zbuild-std=std,panic_abort > /dev/null 2>&1 ) || echo -n
362+
# Sadly, std also depends on cc, and we can't pin it in that tree
363+
# directly. Instead, we have to delete the file out of the cargo
364+
# registry and build --offline to avoid it using the latest version.
365+
NEW_CC_DEP="$CARGO_HOME"
366+
[ "$NEW_CC_DEP" = "" ] && NEW_CC_DEP="$HOME"
367+
if [ -f "$NEW_CC_DEP/.cargo/registry/cache/github.com-"*/cc-1.0.79.crate ]; then
368+
mv "$NEW_CC_DEP/.cargo/registry/cache/github.com-"*/cc-1.0.79.crate ./
369+
fi
370+
rm -f "$NEW_CC_DEP/.cargo/registry/cache/github.com-"*/cc-*.crate
371+
[ -f ./cc-1.0.79.crate ] && mv ./cc-1.0.79.crate "$NEW_CC_DEP/.cargo/registry/cache/github.com-"*/
372+
}
373+
356374
# Then, check with memory sanitizer, if we're on Linux and have rustc nightly
357375
if [ "$HOST_PLATFORM" = "x86_64-unknown-linux-gnu" ]; then
358376
if cargo +nightly --version >/dev/null 2>&1; then
359377
LLVM_V=$(rustc +nightly --version --verbose | grep "LLVM version" | awk '{ print substr($3, 0, 2); }')
360378
if [ -x "$(which clang-$LLVM_V)" ]; then
361379
cargo +nightly clean
362-
cargo +nightly rustc $CARGO_BUILD_ARGS -Zbuild-std=std,panic_abort --target x86_64-unknown-linux-gnu -v -- -Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes
380+
381+
REALLY_PIN_CC
382+
cargo +nightly rustc --offline $CARGO_BUILD_ARGS -Zbuild-std=std,panic_abort --target x86_64-unknown-linux-gnu -v -- -Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes
363383
mv target/x86_64-unknown-linux-gnu/debug/libldk.* target/debug/
364384

365385
# Sadly, std doesn't seem to compile into something that is memsan-safe as of Aug 2020,
@@ -552,20 +572,21 @@ if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
552572
LINK_ARG_FLAGS="-C link-arg=-fuse-ld=$LLD"
553573
export LDK_CLANG_PATH=$(which $CLANG)
554574
if [ "$MACOS_SDK" != "" ]; then
575+
REALLY_PIN_CC
555576
export CLANG="$(pwd)/../deterministic-build-wrappers/clang-lto-link-osx"
556577
for ARG in $CFLAGS_aarch64_apple_darwin; do
557578
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
558579
done
559580
export CFLAGS_aarch64_apple_darwin="$CFLAGS_aarch64_apple_darwin -O3 -fPIC -fembed-bitcode"
560-
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14 -C embed-bitcode=yes -C linker-plugin-lto -C lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-mcpu=apple-a14" CARGO_PROFILE_RELEASE_LTO=true cargo build $CARGO_BUILD_ARGS -v --release --target aarch64-apple-darwin -Zbuild-std=std,panic_abort
581+
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14 -C embed-bitcode=yes -C linker-plugin-lto -C lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-mcpu=apple-a14" CARGO_PROFILE_RELEASE_LTO=true cargo build $CARGO_BUILD_ARGS --offline -v --release --target aarch64-apple-darwin -Zbuild-std=std,panic_abort
561582
if [ "$HOST_OSX" != "true" ]; then
562583
# If we're not on OSX but can build OSX binaries, build the x86_64 OSX release now
563584
MANUAL_LINK_CFLAGS=""
564585
for ARG in $CFLAGS_x86_64_apple_darwin; do
565586
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
566587
done
567588
export CFLAGS_x86_64_apple_darwin="$CFLAGS_x86_64_apple_darwin -O3 -fPIC -fembed-bitcode"
568-
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=sandybridge -C embed-bitcode=yes -C linker-plugin-lto -C lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-mcpu=sandybridge -C link-arg=-mtune=sandybridge" CARGO_PROFILE_RELEASE_LTO=true cargo build $CARGO_BUILD_ARGS -v --release --target x86_64-apple-darwin -Zbuild-std=std,panic_abort
589+
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=sandybridge -C embed-bitcode=yes -C linker-plugin-lto -C lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-mcpu=sandybridge -C link-arg=-mtune=sandybridge" CARGO_PROFILE_RELEASE_LTO=true cargo build $CARGO_BUILD_ARGS --offline -v --release --target x86_64-apple-darwin -Zbuild-std=std,panic_abort
569590
fi
570591
fi
571592
# If we're on an M1 don't bother building X86 binaries

0 commit comments

Comments
 (0)