Merge pull request #29 from TheBlueMatt/main
[ldk-c-bindings] / genbindings.sh
index 5b1713506c4b87e520784717345808b4bdf1177c..0e426022ca334c03420239475f31fbb6bb07193f 100755 (executable)
@@ -9,11 +9,13 @@ if [ ! -d "$1/lightning" -o "$2" != "true" -a "$2" != "false" ]; then
        exit 1
 fi
 
+export LC_ALL=C
+
 # On reasonable systems, we can use realpath here, but OSX is a diva with 20-year-old software.
 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
@@ -31,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
@@ -143,9 +145,19 @@ export RUSTFLAGS="--remap-path-prefix $LIGHTNING_PATH=rust-lightning --remap-pat
 echo "int main() {}" > genbindings_path_map_test_file.c
 clang -o /dev/null -ffile-prefix-map=$HOME/.cargo= genbindings_path_map_test_file.c > /dev/null 2>&1 &&
 # 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="
+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