@@ -141,6 +141,10 @@ OUT_F="$(pwd)/lightning-c-bindings/include/ldk_rust_types.h"
141
141
OUT_CPP=" $( pwd) /lightning-c-bindings/include/lightningpp.hpp"
142
142
BIN=" $( pwd) /c-bindings-gen/target/release/c-bindings-gen"
143
143
144
+ function is_gnu_sed(){
145
+ sed --version > /dev/null 2>&1
146
+ }
147
+
144
148
function add_crate() {
145
149
pushd " $LIGHTNING_PATH /$1 "
146
150
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 {
155
159
echo " }" >> /tmp/$1 -crate-source.txt
156
160
cat /tmp/$1 -crate-source.txt >> /tmp/crate-source.txt
157
161
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
159
165
# OSX sed is for some reason not compatible with GNU sed
160
166
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
163
167
fi
164
168
}
165
169
166
170
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
168
174
# OSX sed is for some reason not compatible with GNU sed
169
175
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
172
176
fi
173
177
}
174
178
@@ -213,19 +217,19 @@ cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1
213
217
# cbindgen is relatively braindead when exporting typedefs -
214
218
# it happily exports all our typedefs for private types, even with the
215
219
# 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
219
222
220
223
# stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
221
224
# 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
223
226
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
225
229
226
230
# stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
227
231
# 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
229
233
fi
230
234
231
235
# Build C++ class methods which call trait methods
438
442
# Finally, if we're on OSX or on Linux, build the final debug binary with address sanitizer (and leave it there)
439
443
if [ " $HOST_PLATFORM " = " x86_64-unknown-linux-gnu" -o " $HOST_PLATFORM " = " x86_64-apple-darwin" ]; then
440
444
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
442
448
# OSX sed is for some reason not compatible with GNU sed
443
449
sed -i .bk ' s/,"cdylib"]/]/g' Cargo.toml
444
- else
445
- sed -i.bk ' s/,"cdylib"]/]/g' Cargo.toml
446
450
fi
451
+
447
452
if [ " $CFLAGS_aarch64_apple_darwin " != " " ]; then
448
453
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)
449
454
fi
0 commit comments