Skip to content

Commit 101cae8

Browse files
committed
Fix builds with rustc 1.84
1 parent 645778d commit 101cae8

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

genbindings.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ cd "$ORIG_PWD"
3636
HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')"
3737
ENV_TARGET=$(echo $HOST_PLATFORM | sed 's/-/_/g')
3838

39+
RUSTC_MINOR_VERSION=$(rustc --version | awk '{ split($2,a,"."); print a[2] }')
40+
3941
# Set path to include our rustc wrapper as well as cbindgen
4042
export LDK_RUSTC_PATH="$(which rustc)"
4143
export RUSTC="$(pwd)/deterministic-build-wrappers/rustc"
@@ -571,17 +573,21 @@ if [ "$CLANGPP" != "" ]; then
571573
export CRATE_CC_NO_DEFAULTS=true
572574
fi
573575

574-
if [ "$2" = "false" -a "$(rustc --print target-list | grep wasm32-wasi)" != "" ]; then
576+
WASM_TARGET="wasm32-wasi"
577+
# In rust 1.84, the wasi target was renamed
578+
[ "$RUSTC_MINOR_VERSION" -ge 84 ] && WASM_TARGET="wasm32-wasip1"
579+
580+
if [ "$2" = "false" -a "$(rustc --print target-list | grep $WASM_TARGET)" != "" ]; then
575581
# Test to see if clang supports wasm32 as a target (which is needed to build rust-secp256k1)
576582
echo "int main() {}" > genbindings_wasm_test_file.c
577-
if clang -nostdlib -o /dev/null --target=wasm32-wasi -Wl,--no-entry genbindings_wasm_test_file.c > /dev/null 2>&1; then
583+
if clang -nostdlib -o /dev/null --target=$WASM_TARGET -Wl,--no-entry genbindings_wasm_test_file.c > /dev/null 2>&1; then
578584
# And if it does, build a WASM binary without capturing errors
579585
export CFLAGS_wasm32_wasi="$BASE_CFLAGS -target wasm32-wasi -O1"
580-
RUSTFLAGS="$BASE_RUSTFLAGS -C opt-level=1 --cfg=test_mod_pointers" cargo build $CARGO_BUILD_ARGS -v --target=wasm32-wasi
586+
RUSTFLAGS="$BASE_RUSTFLAGS -C opt-level=1 --cfg=test_mod_pointers" cargo build $CARGO_BUILD_ARGS -v --target=$WASM_TARGET
581587
export CFLAGS_wasm32_wasi="$BASE_CFLAGS -fembed-bitcode -target wasm32-wasi -Oz"
582-
RUSTFLAGS="$BASE_RUSTFLAGS -C embed-bitcode=yes -C opt-level=z -C linker-plugin-lto -C lto" CARGO_PROFILE_RELEASE_LTO=true cargo build $CARGO_BUILD_ARGS -v --release --target=wasm32-wasi
588+
RUSTFLAGS="$BASE_RUSTFLAGS -C embed-bitcode=yes -C opt-level=z -C linker-plugin-lto -C lto" CARGO_PROFILE_RELEASE_LTO=true cargo build $CARGO_BUILD_ARGS -v --release --target=$WASM_TARGET
583589
else
584-
echo "Cannot build WASM lib as clang does not seem to support the wasm32-wasi target"
590+
echo "Cannot build WASM lib as clang does not seem to support the $WASM_TARGET target"
585591
fi
586592
rm genbindings_wasm_test_file.c
587593
fi
@@ -619,23 +625,34 @@ if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
619625
LINK_ARG_FLAGS="-C link-arg=-fuse-ld=$LLD"
620626
export LDK_CLANG_PATH=$(which $CLANG)
621627
if [ "$MACOS_SDK" != "" ]; then
622-
REALLY_PIN_CC
628+
# At some point rustc fixed the issue which merits REALLY_PIN_CC. I'm not sure when,
629+
# however, so we just use 1.84 as the cutoff.
630+
[ "$RUSTC_MINOR_VERSION" -lt 84 ] && REALLY_PIN_CC
631+
[ "$RUSTC_MINOR_VERSION" -lt 84 ] && OFFLINE_OPT="--offline"
632+
623633
export CLANG="$(pwd)/../deterministic-build-wrappers/clang-lto-link-osx"
624634
for ARG in $CFLAGS_aarch64_apple_darwin; do
625635
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
626636
done
637+
# rustc appears to always look for rust-objcopy, though this may be fixed by
638+
# https://github.com/rust-lang/rust/pull/134240 in rust 1.85.
639+
if [ "$RUSTC_MINOR_VERSION" = 84 ]; then
640+
mkdir -p objcopy-bin
641+
ln -s `which llvm-objcopy` objcopy-bin/rust-objcopy
642+
PATH="$PATH:$(pwd)/objcopy-bin"
643+
fi
627644
# While there's no reason LTO should fail here (and it didn't use to), it now fails with errors like
628645
# ld64.lld: error: undefined symbol: core::fmt::Formatter::debug_lower_hex::hf8e8a79f43d62b68
629646
export CFLAGS_aarch64_apple_darwin="$CFLAGS_aarch64_apple_darwin -O3 -fPIC -fembed-bitcode"
630-
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14 -C embed-bitcode=yes -C linker-plugin-lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-mcpu=apple-a14" cargo build $CARGO_BUILD_ARGS --offline -v --release --target aarch64-apple-darwin -Zbuild-std=std,panic_abort
647+
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14 -C embed-bitcode=yes -C linker-plugin-lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-mcpu=apple-a14" cargo build $CARGO_BUILD_ARGS $OFFLINE_OPT -v --release --target aarch64-apple-darwin -Zbuild-std=std,panic_abort
631648
if [ "$HOST_OSX" != "true" ]; then
632649
# If we're not on OSX but can build OSX binaries, build the x86_64 OSX release now
633650
MANUAL_LINK_CFLAGS=""
634651
for ARG in $CFLAGS_x86_64_apple_darwin; do
635652
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
636653
done
637654
export CFLAGS_x86_64_apple_darwin="$CFLAGS_x86_64_apple_darwin -O3 -fPIC -fembed-bitcode"
638-
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=sandybridge -C embed-bitcode=yes -C linker-plugin-lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-march=sandybridge -C link-arg=-mtune=sandybridge" cargo build $CARGO_BUILD_ARGS --offline -v --release --target x86_64-apple-darwin -Zbuild-std=std,panic_abort
655+
RUSTC_BOOTSTRAP=1 RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=sandybridge -C embed-bitcode=yes -C linker-plugin-lto -C linker=$CLANG $MANUAL_LINK_CFLAGS $LINK_ARG_FLAGS -C link-arg=-march=sandybridge -C link-arg=-mtune=sandybridge" cargo build $CARGO_BUILD_ARGS $OFFLINE_OPT -v --release --target x86_64-apple-darwin -Zbuild-std=std,panic_abort
639656
fi
640657
fi
641658
# If we're on an M1 don't bother building X86 binaries

0 commit comments

Comments
 (0)