echo "Apple clang isn't compatible with upstream clang, install upstream clang"
CLANG_LLVM_V="0"
else
- CLANG_LLVM_V=$(clang --version | head -n1 | awk '{ print substr($4, 0, 2); }')
+ CLANG_LLVM_V=$(clang --version | head -n1 | awk '{ print substr($3, 0, 2); }')
if [ -x "$(which ld64.lld)" ]; then
LLD_LLVM_V="$(ld64.lld --version | awk '{ print substr($2, 0, 2); }')"
fi
ls -lha a.out
time ./a.out > /dev/null
-if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" ]; then
+if [ "$CLANGPP" != "" ]; then
# If we can use cross-language LTO, use it for building C dependencies (i.e. libsecp256k1) as well
export CC="$CLANG"
# The cc-rs crate tries to force -fdata-sections and -ffunction-sections on, which
# breaks -fembed-bitcode, so we turn off cc-rs' default flags and specify exactly
# what we want here.
- export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -fPIC -fembed-bitcode -march=sandybridge"
+ export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -fPIC -fembed-bitcode -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
export CRATE_CC_NO_DEFAULTS=true
fi
RUSTFLAGS="$BASE_RUSTFLAGS -C linker=${EXTRA_CCS[$IDX]}" CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target "${EXTRA_TARGETS[$IDX]}" -- -C lto
done
-if [ "$CFLAGS_aarch64_apple_darwin" != "" ]; then
- RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14" CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target aarch64-apple-darwin -- -C lto
-fi
-
-if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" -a "$LLD" != "" ]; then
+if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
# Finally, test cross-language LTO. Note that this will fail if rustc and clang++
# build against different versions of LLVM (eg when rustc is installed via rustup
# or Ubuntu packages). This should work fine on Distros which do more involved
# packaging than simply shipping the rustup binaries (eg Debian should Just Work
# here).
- export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -O3 -fPIC -fembed-bitcode -march=sandybridge"
+ LINK_ARG_FLAGS="-C link-arg=-fuse-ld=$LLD"
+ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
+ export LDK_CLANG_PATH=$(which $CLANG)
+ export CLANG="$(pwd)/../deterministic-build-wrappers/clang-lto-link-osx"
+ for ARG in "CFLAGS_aarch64_apple_darwin"; do
+ MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
+ done
+ export CFLAGS_aarch64_apple_darwin="$CFLAGS_aarch64_apple_darwin -O3 -fPIC -fembed-bitcode"
+ LINK_ARG_FLAGS="$LINK_ARG_FLAGS -C link-arg="-isysroot$(xcrun --show-sdk-path)" -C link-arg=-mmacosx-version-min=10.9"
+ RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14" CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target aarch64-apple-darwin -- -C linker-plugin-lto -C lto -C linker=$CLANG $LINK_ARG_FLAGS -C link-arg=-mcpu=apple-a14
+ fi
+ export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -O3 -fPIC -fembed-bitcode -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
# Rust doesn't recognize CFLAGS changes, so we need to clean build artifacts
cargo clean --release
- CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C linker=$CLANG -C link-arg=-fuse-ld=$LLD
+ CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C linker=$CLANG $LINK_ARG_FLAGS -C link-arg=-march=sandybridge -C link-arg=-mcpu=sandybridge -C link-arg=-mtune=sandybridge
$CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl
strip ./a.out
echo "C++ Bin size and runtime with cross-language LTO:"
ls -lha a.out
time ./a.out > /dev/null
else
- echo "WARNING: Building with cross-language LTO is not avilable on OSX or without clang-$RUSTC_LLVM_V"
+ if [ "$CFLAGS_aarch64_apple_darwin" != "" ]; then
+ RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14" CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target aarch64-apple-darwin -- -C lto
+ fi
+ echo "WARNING: Building with cross-language LTO is not avilable without clang-$RUSTC_LLVM_V"
fi