Skip to content

Commit e38583b

Browse files
committed
Pass --target/-mcpu/-march/-mtune to all $CC calls
1 parent db75028 commit e38583b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

genbindings.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ if [ "$LDK_TARGET_CPU" = "" ]; then
7575
fi
7676

7777
COMMON_COMPILE="$CC -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-unused-function -Wno-nullability-completeness -Wno-pointer-sign -Wdate-time -ffile-prefix-map=$(pwd)="
78-
[ "$IS_MAC" = "true" -a "$2" != "wasm" ] && COMMON_COMPILE="$COMMON_COMPILE --target=$TARGET_STRING -mcpu=$LDK_TARGET_CPU"
78+
COMMON_CC=""
79+
[ "$IS_MAC" = "true" -a "$2" != "wasm" ] && COMMON_CC="$COMMON_CC --target=$TARGET_STRING -mcpu=$LDK_TARGET_CPU"
80+
[ "$IS_MAC" = "false" -a "$2" != "wasm" ] && COMMON_CC="$COMMON_CC --target=$TARGET_STRING -march=$LDK_TARGET_CPU -mtune=$LDK_TARGET_CPU"
7981

8082
DEBUG_ARG="$3"
8183
if [ "$3" = "leaks" ]; then
@@ -146,16 +148,16 @@ if [ "$2" = "c_sharp" ]; then
146148
fi
147149

148150
echo "Building C# bindings..."
149-
COMPILE="$COMMON_COMPILE -pthread -fPIC"
150-
LINK="-shared"
151+
COMPILE="$COMMON_COMPILE $COMMON_CC -pthread -fPIC"
152+
LINK="$COMMON_CC -shared"
151153
[ "$IS_WIN" = "false" ] && LINK="$LINK -ldl"
152154
[ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined"
153155
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
154156
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
155157
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
156158
[ "$IS_MAC" = "false" -a "$3" != "false" ] && LINK="$LINK -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
157-
[ "$IS_WIN" = "true" ] && LINK="$LINK --target=x86_64-pc-windows-gnu -lbcrypt -lntdll -static-libgcc"
158-
[ "$IS_WIN" = "true" ] && COMPILE="$COMPILE --target=x86_64-pc-windows-gnu -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/ -I/usr/x86_64-w64-mingw32/include/"
159+
[ "$IS_WIN" = "true" ] && LINK="$LINK -lbcrypt -lntdll -static-libgcc"
160+
[ "$IS_WIN" = "true" ] && COMPILE="$COMPILE -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/ -I/usr/x86_64-w64-mingw32/include/"
159161

160162
if [ "$3" = "true" ]; then
161163
$COMPILE $LINK -o libldkcsharp_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
@@ -213,8 +215,8 @@ elif [ "$2" = "python" ]; then
213215
[ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true
214216

215217
echo "Building Python bindings..."
216-
COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -fPIC"
217-
LINK="-ldl -shared"
218+
COMPILE="$COMMON_COMPILE $COMMON_CC -Isrc/main/jni -pthread -fPIC"
219+
LINK="$COMMON_CC -ldl -shared"
218220
[ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined"
219221
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
220222
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
@@ -253,7 +255,7 @@ elif [ "$2" = "wasm" ]; then
253255
cat ts/bindings.c.body >> ts/bindings.c
254256

255257
echo "Building TS bindings..."
256-
COMPILE="$COMMON_COMPILE -flto -Wl,--no-entry -nostdlib --target=wasm32-wasi -Wl,-z -Wl,stack-size=$((8*1024*1024)) -Wl,--initial-memory=$((16*1024*1024)) -Wl,--max-memory=$((1024*1024*1024)) -Wl,--global-base=4096"
258+
COMPILE="$COMMON_COMPILE $COMMON_CC -flto -Wl,--no-entry -nostdlib --target=wasm32-wasi -Wl,-z -Wl,stack-size=$((8*1024*1024)) -Wl,--initial-memory=$((16*1024*1024)) -Wl,--max-memory=$((1024*1024*1024)) -Wl,--global-base=4096"
257259
# We only need malloc and assert/abort, but for now just use WASI for those:
258260
EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a
259261
[ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,aligned_alloc -Wl,-wrap,free"
@@ -320,8 +322,8 @@ else
320322
rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class
321323

322324
echo "Building Java bindings..."
323-
COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -fPIC"
324-
LINK="-shared"
325+
COMPILE="$COMMON_COMPILE $COMMON_CC -Isrc/main/jni -pthread -fPIC"
326+
LINK="$COMMON_CC -shared"
325327
[ "$IS_WIN" = "false" ] && LINK="$LINK -ldl"
326328
[ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined"
327329
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"

0 commit comments

Comments
 (0)