+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
+}