Merge pull request #29 from TheBlueMatt/main
[ldk-c-bindings] / genbindings.sh
index a51f04a81fde7c72f40a6798a3ba9544205beeef..0e426022ca334c03420239475f31fbb6bb07193f 100755 (executable)
@@ -15,7 +15,7 @@ export LC_ALL=C
 ORIG_PWD="$(pwd)"
 cd "$1"
 LIGHTNING_PATH="$(pwd)"
-LIGHTNING_GIT="$(git describe --tag --dirty)"
+LIGHTNING_GIT="$(git describe --tag --dirty --abbrev=16)"
 cd "$ORIG_PWD"
 
 # Generate (and reasonably test) C bindings
@@ -33,7 +33,7 @@ mv lightning-c-bindings/src/bitcoin ./
 
 git checkout lightning-c-bindings/src
 git checkout lightning-c-bindings/include
-BINDINGS_GIT="$(git describe --tag --dirty)"
+BINDINGS_GIT="$(git describe --tag --dirty --abbrev=16)"
 echo -e "#ifndef _LDK_HEADER_VER" > lightning-c-bindings/include/ldk_ver.h
 echo -e "static inline int _ldk_strncmp(const char *s1, const char *s2, uint64_t n) {" >> lightning-c-bindings/include/ldk_ver.h
 echo -e "\tif (n && *s1 != *s2) return 1;" >> lightning-c-bindings/include/ldk_ver.h
@@ -147,7 +147,17 @@ clang -o /dev/null -ffile-prefix-map=$HOME/.cargo= genbindings_path_map_test_fil
 # Now that we've done our last non-LTO build, turn on LTO in CFLAGS as well
 export BASE_CFLAGS="-ffile-prefix-map=$HOME/.cargo= -frandom-seed=42"
 ENV_TARGET=$(rustc --version --verbose | grep host | awk '{ print $2 }' | sed 's/-/_/g')
-export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
+case "$ENV_TARGET" in
+       "x86_64"*)
+               export RUSTFLAGS="$RUSTFLAGS -C target-cpu=sandybridge"
+               export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -march=sandybridge -mcpu=sandybridge -mtune=sandybridge"
+               ;;
+       *)
+               # Assume this isn't targeted at another host and build for the host's CPU.
+               export RUSTFLAGS="$RUSTFLAGS -C target-cpu=native"
+               export CFLAGS_$ENV_TARGET="$BASE_CFLAGS -mcpu=native"
+               ;;
+esac
 rm genbindings_path_map_test_file.c
 
 cargo build