let remaining: String = seg_iter.map(|seg| {
format!("::{}", seg.ident)
}).collect();
- if let Some((imp, _)) = self.imports.get(&first_seg.ident) {
+ let first_seg_str = format!("{}", first_seg.ident);
+ if first_seg_str == "std" {
+ Some(first_seg_str + &remaining)
+ } else if let Some((imp, _)) = self.imports.get(&first_seg.ident) {
if remaining != "" {
Some(imp.clone() + &remaining)
} else {
"String" if is_ref => Some("crate::c_types::Str"),
"std::time::Duration" => Some("u64"),
+ "std::io::Error" => Some("crate::c_types::IOError"),
"bitcoin::secp256k1::key::PublicKey" => Some("crate::c_types::PublicKey"),
"bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature"),
"String" => Some(""),
"std::time::Duration" => Some(""),
+ "std::io::Error" if !is_ref => Some("crate::c_types::IOError::from_rust("),
"bitcoin::secp256k1::key::PublicKey" => Some("crate::c_types::PublicKey::from_rust(&"),
"bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature::from_rust(&"),
"String" if is_ref => Some(".as_str().into()"),
"std::time::Duration" => Some(".as_secs()"),
+ "std::io::Error" if !is_ref => Some(")"),
"bitcoin::secp256k1::key::PublicKey" => Some(")"),
"bitcoin::secp256k1::Signature" => Some(")"),
# On reasonable systems, we can use realpath here, but OSX is a diva with 20-year-old software.
ORIG_PWD="$(pwd)"
-cd "$1/lightning"
+cd "$1"
LIGHTNING_PATH="$(pwd)"
cd "$ORIG_PWD"
OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp"
BIN="$(pwd)/c-bindings-gen/target/release/c-bindings-gen"
-pushd "$LIGHTNING_PATH"
+pushd "$LIGHTNING_PATH/lightning"
RUSTC_BOOTSTRAP=1 cargo rustc $FEATURES_ARGS --profile=check -- -Zunstable-options --pretty=expanded > /tmp/lightning-crate-source.txt
+popd
HOST_PLATFORM="$(rustc --version --verbose | grep "host:")"
if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
fi
echo "}" >> /tmp/lightning-crate-source.txt
+if [ "$2" = "true" ]; then
+ pushd "$LIGHTNING_PATH/lightning-persister"
+ RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded > /tmp/lightning-persist-crate-source.txt
+ popd
+ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
+ sed -i".original" '1i\
+pub mod lightning_persister {
+' /tmp/lightning-persist-crate-source.txt
+ else
+ sed -i '1ipub mod lightning_persister {\n' /tmp/lightning-persist-crate-source.txt
+ fi
+ echo "}" >> /tmp/lightning-persist-crate-source.txt
+ cat /tmp/lightning-persist-crate-source.txt >> /tmp/lightning-crate-source.txt
+ rm /tmp/lightning-persist-crate-source.txt
+fi
+
cat /tmp/lightning-crate-source.txt | RUST_BACKTRACE=1 "$BIN" "$OUT/" "$OUT_TEMPL" "$OUT_F" "$OUT_CPP"
-popd
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"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml
+ sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH/lightning"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml
+ sed -E -i '' 's|lightning-(.*) = \{ .*|lightning-\1 = \{ path = "'"$LIGHTNING_PATH"'/lightning-\1" }|' lightning-c-bindings/Cargo.toml
else
- sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml
+ sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH/lightning"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml
+ sed -E -i 's|lightning-(.*) = \{ .*|lightning-\1 = \{ path = "'"$LIGHTNING_PATH"'/lightning-\1" }|' lightning-c-bindings/Cargo.toml
fi
# Set path to include our rustc wrapper as well as cbindgen
secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] }
# Note that the following line is matched by genbindings to update the path
lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "52f1d45bb20114bf89880e8128d0f570e426f0a6", features = ["allow_wallclock_use"] }
+lightning-persister = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "52f1d45bb20114bf89880e8128d0f570e426f0a6" }
[patch.crates-io]
# Rust-Secp256k1 PR 279. Should be dropped once merged.
}
}
+#[repr(C)]
+#[allow(missing_docs)] // If there's no docs upstream, that's good enough for us
+/// Represents an IO Error. Note that some information is lost in the conversion from Rust.
+pub enum IOError {
+ NotFound,
+ PermissionDenied,
+ ConnectionRefused,
+ ConnectionReset,
+ ConnectionAborted,
+ NotConnected,
+ AddrInUse,
+ AddrNotAvailable,
+ BrokenPipe,
+ AlreadyExists,
+ WouldBlock,
+ InvalidInput,
+ InvalidData,
+ TimedOut,
+ WriteZero,
+ Interrupted,
+ Other,
+ UnexpectedEof,
+}
+impl IOError {
+ pub(crate) fn from_rust(err: std::io::Error) -> Self {
+ match err.kind() {
+ std::io::ErrorKind::NotFound => IOError::NotFound,
+ std::io::ErrorKind::PermissionDenied => IOError::PermissionDenied,
+ std::io::ErrorKind::ConnectionRefused => IOError::ConnectionRefused,
+ std::io::ErrorKind::ConnectionReset => IOError::ConnectionReset,
+ std::io::ErrorKind::ConnectionAborted => IOError::ConnectionAborted,
+ std::io::ErrorKind::NotConnected => IOError::NotConnected,
+ std::io::ErrorKind::AddrInUse => IOError::AddrInUse,
+ std::io::ErrorKind::AddrNotAvailable => IOError::AddrNotAvailable,
+ std::io::ErrorKind::BrokenPipe => IOError::BrokenPipe,
+ std::io::ErrorKind::AlreadyExists => IOError::AlreadyExists,
+ std::io::ErrorKind::WouldBlock => IOError::WouldBlock,
+ std::io::ErrorKind::InvalidInput => IOError::InvalidInput,
+ std::io::ErrorKind::InvalidData => IOError::InvalidData,
+ std::io::ErrorKind::TimedOut => IOError::TimedOut,
+ std::io::ErrorKind::WriteZero => IOError::WriteZero,
+ std::io::ErrorKind::Interrupted => IOError::Interrupted,
+ std::io::ErrorKind::Other => IOError::Other,
+ std::io::ErrorKind::UnexpectedEof => IOError::UnexpectedEof,
+ _ => IOError::Other,
+ }
+ }
+}
+
#[repr(C)]
/// A serialized transaction, in (pointer, length) form.
///