@@ -21,7 +21,8 @@ cd "$ORIG_PWD"
21
21
# Generate (and reasonably test) C bindings
22
22
23
23
# First we set various compiler flags...
24
- HOST_PLATFORM=" $( rustc --version --verbose | grep " host:" ) "
24
+ HOST_PLATFORM=" $( rustc --version --verbose | grep " host:" | awk ' { print $2 }' ) "
25
+ ENV_TARGET=$( echo $HOST_PLATFORM | sed ' s/-/_/g' )
25
26
26
27
# Set path to include our rustc wrapper as well as cbindgen
27
28
export LDK_RUSTC_PATH=" $( which rustc) "
@@ -44,18 +45,18 @@ BASE_CFLAGS="$BASE_CFLAGS -frandom-seed=42"
44
45
LOCAL_CFLAGS=" -Wall -Wno-nullability-completeness -pthread -Iinclude/"
45
46
46
47
HOST_OSX=false
47
- if [ " $HOST_PLATFORM " = " host: x86_64-apple-darwin" ]; then
48
+ if [ " $HOST_PLATFORM " = " x86_64-apple-darwin" ]; then
48
49
HOST_OSX=true
49
- elif [ " $HOST_PLATFORM " = " host: aarch64-apple-darwin" ]; then
50
+ elif [ " $HOST_PLATFORM " = " aarch64-apple-darwin" ]; then
50
51
HOST_OSX=true
51
52
fi
52
53
53
54
BASE_HOST_CFLAGS=" $BASE_CFLAGS "
54
55
55
56
if [ " $HOST_OSX " = " true" ]; then
56
57
export MACOSX_DEPLOYMENT_TARGET=10.9
57
- LOCAL_CFLAGS=" $LOCAL_CFLAGS -isysroot$( xcrun --show-sdk-path) -mmacosx-version-min=10.9"
58
- BASE_HOST_CFLAGS=" $BASE_HOST_CFLAGS -isysroot$( xcrun --show-sdk-path) -mmacosx-version-min=10.9"
58
+ LOCAL_CFLAGS=" $LOCAL_CFLAGS --target= $HOST_PLATFORM - isysroot$( xcrun --show-sdk-path) -mmacosx-version-min=10.9"
59
+ BASE_HOST_CFLAGS=" $BASE_HOST_CFLAGS --target= $HOST_PLATFORM - isysroot$( xcrun --show-sdk-path) -mmacosx-version-min=10.9"
59
60
# Targeting aarch64 appears to be supported only starting with Big Sur, so check it before use
60
61
clang -o /dev/null $BASE_HOST_CFLAGS --target=aarch64-apple-darwin -mcpu=apple-a14 genbindings_path_map_test_file.c &&
61
62
export CFLAGS_aarch64_apple_darwin=" $BASE_HOST_CFLAGS --target=aarch64-apple-darwin -mcpu=apple-a14" ||
64
65
65
66
rm genbindings_path_map_test_file.c
66
67
67
- ENV_TARGET=$( rustc --version --verbose | grep host | awk ' { print $2 }' | sed ' s/-/_/g' )
68
68
case " $ENV_TARGET " in
69
69
" x86_64" * )
70
70
export RUSTFLAGS=" $BASE_RUSTFLAGS -C target-cpu=sandybridge"
71
71
export CFLAGS_$ENV_TARGET =" $BASE_HOST_CFLAGS -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
72
72
;;
73
+ " aarch64_apple_darwin" )
74
+ export RUSTFLAGS=" $BASE_RUSTFLAGS -C target-cpu=apple-a14"
75
+ export CFLAGS_$ENV_TARGET =" $BASE_HOST_CFLAGS -mcpu=apple-a14"
76
+ ;;
73
77
* )
74
78
# Assume this isn't targeted at another host and build for the host's CPU.
75
79
export RUSTFLAGS=" $BASE_RUSTFLAGS -C target-cpu=native"
225
229
fi
226
230
227
231
# Build C++ class methods which call trait methods
232
+ echo " Updating C++ header, this may take some time, especially on macOS"
228
233
set +x # Echoing every command is very verbose here
229
234
OLD_IFS=" $IFS "
230
235
export IFS=' '
@@ -328,7 +333,7 @@ if [ "$2" = "true" ]; then
328
333
fi
329
334
330
335
# Then, check with memory sanitizer, if we're on Linux and have rustc nightly
331
- if [ " $HOST_PLATFORM " = " host: x86_64-unknown-linux-gnu" ]; then
336
+ if [ " $HOST_PLATFORM " = " x86_64-unknown-linux-gnu" ]; then
332
337
if cargo +nightly --version > /dev/null 2>&1 ; then
333
338
LLVM_V=$( rustc +nightly --version --verbose | grep " LLVM version" | awk ' { print substr($3, 0, 2); }' )
334
339
if [ -x " $( which clang-$LLVM_V ) " ]; then
@@ -431,7 +436,7 @@ if [ "$CLANG" != "" -a "$CLANGPP" = "" ]; then
431
436
fi
432
437
433
438
# Finally, if we're on OSX or on Linux, build the final debug binary with address sanitizer (and leave it there)
434
- if [ " $HOST_PLATFORM " = " host: x86_64-unknown-linux-gnu" -o " $HOST_PLATFORM " = " host: x86_64-apple-darwin" ]; then
439
+ if [ " $HOST_PLATFORM " = " x86_64-unknown-linux-gnu" -o " $HOST_PLATFORM " = " x86_64-apple-darwin" ]; then
435
440
if [ " $CLANGPP " != " " ]; then
436
441
if [ " $HOST_OSX " = " true" ]; then
437
442
# OSX sed is for some reason not compatible with GNU sed
@@ -536,17 +541,20 @@ if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
536
541
LINK_ARG_FLAGS=" $LINK_ARG_FLAGS -C link-arg=" -isysroot$( xcrun --show-sdk-path) " -C link-arg=-mmacosx-version-min=10.9"
537
542
RUSTFLAGS=" $BASE_RUSTFLAGS -C target-cpu=apple-a14 -C embed-bitcode=yes -C linker-plugin-lto -C lto -C linker=$CLANG $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
538
543
fi
539
- export CFLAGS_$ENV_TARGET =" $BASE_HOST_CFLAGS -O3 -fPIC -fembed-bitcode -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
540
- # Rust doesn't recognize CFLAGS changes, so we need to clean build artifacts
541
- cargo clean --release
542
- 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
543
-
544
- if [ " $2 " = " true" ]; then
545
- $CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=$LLD -O2 demo.cpp target/release/libldk.a -ldl
546
- strip ./a.out
547
- echo " C++ Bin size and runtime with cross-language LTO:"
548
- ls -lha a.out
549
- time ./a.out > /dev/null
544
+ # If we're on an M1 don't bother building X86 binaries
545
+ if [ " $HOST_PLATFORM " != " aarch64-apple-darwin" ]; then
546
+ export CFLAGS_$ENV_TARGET =" $BASE_HOST_CFLAGS -O3 -fPIC -fembed-bitcode -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
547
+ # Rust doesn't recognize CFLAGS changes, so we need to clean build artifacts
548
+ cargo clean --release
549
+ 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
550
+
551
+ if [ " $2 " = " true" ]; then
552
+ $CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=$LLD -O2 demo.cpp target/release/libldk.a -ldl
553
+ strip ./a.out
554
+ echo " C++ Bin size and runtime with cross-language LTO:"
555
+ ls -lha a.out
556
+ time ./a.out > /dev/null
557
+ fi
550
558
fi
551
559
else
552
560
if [ " $CFLAGS_aarch64_apple_darwin " != " " ]; then
0 commit comments