Skip to content

Commit f9d608f

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

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

genbindings.sh

Lines changed: 29 additions & 10 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,23 @@ 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+
WASM_NAME="wasm32_wasi"
578+
# In rust 1.84, the wasi target was renamed
579+
[ "$RUSTC_MINOR_VERSION" -ge 84 ] && WASM_TARGET="wasm32-wasip1"
580+
[ "$RUSTC_MINOR_VERSION" -ge 84 ] && WASM_NAME="wasm32_wasip1"
581+
582+
if [ "$2" = "false" -a "$(rustc --print target-list | grep $WASM_TARGET)" != "" ]; then
575583
# Test to see if clang supports wasm32 as a target (which is needed to build rust-secp256k1)
576584
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
585+
if clang -nostdlib -o /dev/null --target=$WASM_TARGET -Wl,--no-entry genbindings_wasm_test_file.c > /dev/null 2>&1; then
578586
# And if it does, build a WASM binary without capturing errors
579-
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
581-
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
587+
export CFLAGS_$WASM_NAME="$BASE_CFLAGS -target wasm32-wasi -O1"
588+
RUSTFLAGS="$BASE_RUSTFLAGS -C opt-level=1 --cfg=test_mod_pointers" cargo build $CARGO_BUILD_ARGS -v --target=$WASM_TARGET
589+
export CFLAGS_$WASM_NAME="$BASE_CFLAGS -fembed-bitcode -target wasm32-wasi -Oz"
590+
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
583591
else
584-
echo "Cannot build WASM lib as clang does not seem to support the wasm32-wasi target"
592+
echo "Cannot build WASM lib as clang does not seem to support the $WASM_TARGET target"
585593
fi
586594
rm genbindings_wasm_test_file.c
587595
fi
@@ -619,23 +627,34 @@ if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
619627
LINK_ARG_FLAGS="-C link-arg=-fuse-ld=$LLD"
620628
export LDK_CLANG_PATH=$(which $CLANG)
621629
if [ "$MACOS_SDK" != "" ]; then
622-
REALLY_PIN_CC
630+
# At some point rustc fixed the issue which merits REALLY_PIN_CC. I'm not sure when,
631+
# however, so we just use 1.84 as the cutoff.
632+
[ "$RUSTC_MINOR_VERSION" -lt 84 ] && REALLY_PIN_CC
633+
[ "$RUSTC_MINOR_VERSION" -lt 84 ] && OFFLINE_OPT="--offline"
634+
623635
export CLANG="$(pwd)/../deterministic-build-wrappers/clang-lto-link-osx"
624636
for ARG in $CFLAGS_aarch64_apple_darwin; do
625637
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
626638
done
639+
# rustc appears to always look for rust-objcopy, though this may be fixed by
640+
# https://github.com/rust-lang/rust/pull/134240 in rust 1.85.
641+
if [ "$RUSTC_MINOR_VERSION" = 84 ]; then
642+
mkdir -p objcopy-bin
643+
ln -s `which llvm-objcopy` objcopy-bin/rust-objcopy
644+
PATH="$PATH:$(pwd)/objcopy-bin"
645+
fi
627646
# While there's no reason LTO should fail here (and it didn't use to), it now fails with errors like
628647
# ld64.lld: error: undefined symbol: core::fmt::Formatter::debug_lower_hex::hf8e8a79f43d62b68
629648
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
649+
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
631650
if [ "$HOST_OSX" != "true" ]; then
632651
# If we're not on OSX but can build OSX binaries, build the x86_64 OSX release now
633652
MANUAL_LINK_CFLAGS=""
634653
for ARG in $CFLAGS_x86_64_apple_darwin; do
635654
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
636655
done
637656
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
657+
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
639658
fi
640659
fi
641660
# If we're on an M1 don't bother building X86 binaries

0 commit comments

Comments
 (0)