- export CFLAGS_$ENV_TARGET="$BASE_HOST_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 RUSTFLAGS="$RUSTFLAGS -C embed-bitcode=yes -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" cargo build $CARGO_BUILD_ARGS -v --release
-
- if [ "$2" = "true" ]; then
- $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
+ # If we're on an M1 don't bother building X86 binaries
+ if [ "$HOST_PLATFORM" != "aarch64-apple-darwin" ]; then
+ [ "$HOST_OSX" != "true" ] && export CLANG="$LDK_CLANG_PATH"
+ export CFLAGS_$ENV_TARGET="$BASE_HOST_CFLAGS -O3 -fPIC -fembed-bitcode"
+ # Rust doesn't recognize CFLAGS changes, so we need to clean build artifacts
+ cargo clean --release
+ CARGO_PROFILE_RELEASE_LTO=true RUSTFLAGS="$RUSTFLAGS -C embed-bitcode=yes -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" cargo build $CARGO_BUILD_ARGS -v --release
+
+ if [ "$2" = "true" ]; then
+ $CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=$LLD -O2 -c demo.cpp -o demo.o
+ $CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=$LLD -Wl,--lto-O2 -Wl,-O2 -O2 demo.o target/release/libldk.a -ldl
+ strip ./a.out
+ time ./a.out
+ echo "C++ Bin size and runtime with cross-language LTO:"
+ ls -lha a.out
+ fi