Skip to content

Commit b3fd5ea

Browse files
committed
Check if GNU sed is available on macOS
Check if is_gnu_sed is true
1 parent 31641dd commit b3fd5ea

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

genbindings.sh

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ OUT_F="$(pwd)/lightning-c-bindings/include/ldk_rust_types.h"
141141
OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp"
142142
BIN="$(pwd)/c-bindings-gen/target/release/c-bindings-gen"
143143

144+
function is_gnu_sed(){
145+
sed --version >/dev/null 2>&1
146+
}
147+
144148
function add_crate() {
145149
pushd "$LIGHTNING_PATH/$1"
146150
RUSTC_BOOTSTRAP=1 cargo rustc --profile=check --no-default-features $3 -- --cfg=c_bindings -Zunpretty=expanded > /tmp/$1-crate-source.txt
@@ -155,20 +159,20 @@ pub mod $2 {
155159
echo "}" >> /tmp/$1-crate-source.txt
156160
cat /tmp/$1-crate-source.txt >> /tmp/crate-source.txt
157161
rm /tmp/$1-crate-source.txt
158-
if [ "$HOST_OSX" = "true" ]; then
162+
if is_gnu_sed; then
163+
sed -E -i 's|#*'$1' = \{ .*|'$1' = \{ path = "'"$LIGHTNING_PATH"'/'$1'", default-features = false }|' lightning-c-bindings/Cargo.toml
164+
else
159165
# OSX sed is for some reason not compatible with GNU sed
160166
sed -E -i '' 's|#*'$1' = \{ .*|'$1' = \{ path = "'"$LIGHTNING_PATH"'/'$1'", default-features = false }|' lightning-c-bindings/Cargo.toml
161-
else
162-
sed -E -i 's|#*'$1' = \{ .*|'$1' = \{ path = "'"$LIGHTNING_PATH"'/'$1'", default-features = false }|' lightning-c-bindings/Cargo.toml
163167
fi
164168
}
165169

166170
function drop_crate() {
167-
if [ "$HOST_OSX" = "true" ]; then
171+
if is_gnu_sed; then
172+
sed -E -i 's|'$1' = \{ (.*)|#'$1' = \{ \1|' lightning-c-bindings/Cargo.toml
173+
else
168174
# OSX sed is for some reason not compatible with GNU sed
169175
sed -E -i '' 's|'$1' = \{ (.*)|#'$1' = \{ \1|' lightning-c-bindings/Cargo.toml
170-
else
171-
sed -E -i 's|'$1' = \{ (.*)|#'$1' = \{ \1|' lightning-c-bindings/Cargo.toml
172176
fi
173177
}
174178

@@ -213,19 +217,19 @@ cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1
213217
# cbindgen is relatively braindead when exporting typedefs -
214218
# it happily exports all our typedefs for private types, even with the
215219
# generics we specified in C mode! So we drop all those types manually here.
216-
if [ "$HOST_OSX" = "true" ]; then
217-
# OSX sed is for some reason not compatible with GNU sed
218-
sed -i '' 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
220+
if is_gnu_sed; then
221+
sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
219222

220223
# stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
221224
# doesn't actually use it anyway, so drop the import.
222-
sed -i '' 's/#include <stdlib.h>/#include "ldk_rust_types.h"/g' include/lightning.h
225+
sed -i 's/#include <stdlib.h>/#include "ldk_rust_types.h"/g' include/lightning.h
223226
else
224-
sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
227+
# OSX sed is for some reason not compatible with GNU sed
228+
sed -i '' 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
225229

226230
# stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
227231
# doesn't actually use it anyway, so drop the import.
228-
sed -i 's/#include <stdlib.h>/#include "ldk_rust_types.h"/g' include/lightning.h
232+
sed -i '' 's/#include <stdlib.h>/#include "ldk_rust_types.h"/g' include/lightning.h
229233
fi
230234

231235
# Build C++ class methods which call trait methods
@@ -438,12 +442,13 @@ fi
438442
# Finally, if we're on OSX or on Linux, build the final debug binary with address sanitizer (and leave it there)
439443
if [ "$HOST_PLATFORM" = "x86_64-unknown-linux-gnu" -o "$HOST_PLATFORM" = "x86_64-apple-darwin" ]; then
440444
if [ "$CLANGPP" != "" ]; then
441-
if [ "$HOST_OSX" = "true" ]; then
445+
if is_gnu_sed; then
446+
sed -i.bk 's/,"cdylib"]/]/g' Cargo.toml
447+
else
442448
# OSX sed is for some reason not compatible with GNU sed
443449
sed -i .bk 's/,"cdylib"]/]/g' Cargo.toml
444-
else
445-
sed -i.bk 's/,"cdylib"]/]/g' Cargo.toml
446450
fi
451+
447452
if [ "$CFLAGS_aarch64_apple_darwin" != "" ]; then
448453
RUSTFLAGS="$BASE_RUSTFLAGS -C target-cpu=apple-a14" RUSTC_BOOTSTRAP=1 cargo rustc $CARGO_BUILD_ARGS --target aarch64-apple-darwin -v -- -Zsanitizer=address -Cforce-frame-pointers=yes || ( mv Cargo.toml.bk Cargo.toml; exit 1)
449454
fi

0 commit comments

Comments
 (0)