Skip to content

Instantly share code, notes, and snippets.

@RCasatta
Last active July 17, 2019 15:15
Show Gist options
  • Save RCasatta/9b5a01db5e8520b77e553b1b9879b895 to your computer and use it in GitHub Desktop.
Save RCasatta/9b5a01db5e8520b77e553b1b9879b895 to your computer and use it in GitHub Desktop.
➜ rust-libwally cat Cargo.toml
[package]
name = "rust-libwally"
version = "0.1.0"
authors = ["Riccardo Casatta <riccardo@casatta.it>"]
build = "build.rs"
[dependencies]
libc = "0.2"
[build-dependencies]
cc = "1.0"
➜ rust-libwally cat build.rs
extern crate cc;
use std::process::Command;
fn main() {
Command::new("./tools/cleanup.sh")
.current_dir("./depend/libwally-core/")
.status()
.expect("failed to execute cleanup");
Command::new("./tools/autogen.sh")
.current_dir("./depend/libwally-core/")
.status()
.expect("failed to execute autogen");
Command::new("./configure")
.arg("--enable-elements")
.current_dir("./depend/libwally-core/")
.status()
.expect("failed to execute configure");
cc::Build::new()
.include("depend/libwally-core/")
.include("depend/libwally-core/src")
.include("depend/libwally-core/include")
.file("depend/libwally-core/src/aes.c")
.file("depend/libwally-core/src/base58.c")
.file("depend/libwally-core/src/bech32.c")
.file("depend/libwally-core/src/bip32.c")
.file("depend/libwally-core/src/bip38.c")
.file("depend/libwally-core/src/bip39.c")
.file("depend/libwally-core/src/elements.c")
.file("depend/libwally-core/src/hex.c")
.file("depend/libwally-core/src/hmac.c")
.file("depend/libwally-core/src/internal.c")
.file("depend/libwally-core/src/mnemonic.c")
//.file("depend/libwally-core/src/pbkdf2.c")
.file("depend/libwally-core/src/script.c")
.file("depend/libwally-core/src/scrypt.c")
.file("depend/libwally-core/src/sign.c")
.file("depend/libwally-core/src/transaction.c")
.file("depend/libwally-core/src/wif.c")
.file("depend/libwally-core/src/wordlist.c")
.debug(true)
.compile("libwally.a");
}
➜ rust-libwally cat src/main.rs
extern crate libc;
use std::ffi::CString;
use std::ffi::CStr;
use std::os::raw::c_char;
extern {
fn wally_is_elements_build() -> libc::c_int;
//fn bip39_get_languages(output : *const c_char) -> libc::c_int;
}
fn main() {
let output = unsafe { wally_is_elements_build() };
println!("is_elements_build:{}", output);
/*
let s = CString::new("data data data data").unwrap();
let output = unsafe { bip39_get_languages(s.as_ref().as_ptr()) };
println!("mnemonic:{:?}", s);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment