-if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
- # OSX sed is for some reason not compatible with GNU sed
- sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml
+
+function add_crate() {
+ pushd "$LIGHTNING_PATH/$1"
+ RUSTC_BOOTSTRAP=1 cargo rustc --profile=check $3 -- -Zunstable-options --pretty=expanded > /tmp/$1-crate-source.txt
+ popd
+ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
+ sed -i".original" "1i\\
+pub mod $2 {
+" /tmp/$1-crate-source.txt
+ else
+ sed -i "1ipub mod $2 {\n" /tmp/$1-crate-source.txt
+ fi
+ echo "}" >> /tmp/$1-crate-source.txt
+ cat /tmp/$1-crate-source.txt >> /tmp/crate-source.txt
+ rm /tmp/$1-crate-source.txt
+ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
+ # OSX sed is for some reason not compatible with GNU sed
+ sed -E -i '' 's|#?'$1' = \{ .*|'$1' = \{ path = "'"$LIGHTNING_PATH"'/'$1'" '"$4"' }|' lightning-c-bindings/Cargo.toml
+ else
+ sed -E -i 's|#?'$1' = \{ .*|'$1' = \{ path = "'"$LIGHTNING_PATH"'/'$1'" '"$4"' }|' lightning-c-bindings/Cargo.toml
+ fi
+}
+
+function drop_crate() {
+ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
+ # OSX sed is for some reason not compatible with GNU sed
+ sed -E -i '' 's|'$1' = \{ (.*)|#'$1' = \{ \1|' lightning-c-bindings/Cargo.toml
+ else
+ sed -E -i 's|'$1' = \{ (.*)|#'$1' = \{ \1|' lightning-c-bindings/Cargo.toml
+ fi
+}
+
+echo > /tmp/crate-source.txt
+if [ "$2" = "true" ]; then
+ add_crate lightning lightning --features=allow_wallclock_use ', features = ["allow_wallclock_use"]'
+ add_crate "lightning-persister" "lightning_persister"