-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from GabrielMajeri/manual-bindings
Use libc for `libdl` bindings on Linux
- Loading branch information
Showing
6 changed files
with
113 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,37 @@ | ||
extern crate bindgen; | ||
#[macro_use] | ||
extern crate cfg_if; | ||
|
||
use std::env; | ||
use std::path::PathBuf; | ||
cfg_if! { | ||
if #[cfg(target_os = "macos")] { | ||
extern crate bindgen; | ||
|
||
fn main() { | ||
if cfg!(target_os = "linux") { | ||
generate_linux_bindings(); | ||
} else if cfg!(target_os = "macos") { | ||
generate_macos_bindings(); | ||
} | ||
} | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
fn generate_linux_bindings() { | ||
let bindings = bindgen::Builder::default() | ||
.header("./src/linux/bindings.h") | ||
.whitelist_function("dl_iterate_phdr") | ||
.whitelist_type(r#"Elf\d*.*"#) | ||
.whitelist_var("PT_.*") | ||
.generate() | ||
.expect("Should generate linux FFI bindings OK"); | ||
fn main() { | ||
generate_macos_bindings(); | ||
} | ||
|
||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("linux_bindings.rs")) | ||
.expect("Should write linux_bindings.rs OK"); | ||
} | ||
fn generate_macos_bindings() { | ||
let bindings = bindgen::Builder::default() | ||
.header("./src/macos/bindings.h") | ||
.whitelist_function("_dyld_.*") | ||
.whitelist_type("mach_header.*") | ||
.whitelist_type("load_command.*") | ||
.whitelist_type("uuid_command.*") | ||
.whitelist_type("segment_command.*") | ||
.whitelist_var("MH_MAGIC.*") | ||
.whitelist_var("LC_SEGMENT.*") | ||
.whitelist_var("LC_UUID.*") | ||
.generate() | ||
.expect("Should generate macOS FFI bindings OK"); | ||
|
||
fn generate_macos_bindings() { | ||
let bindings = bindgen::Builder::default() | ||
.header("./src/macos/bindings.h") | ||
.whitelist_function("_dyld_.*") | ||
.whitelist_type("mach_header.*") | ||
.whitelist_type("load_command.*") | ||
.whitelist_type("uuid_command.*") | ||
.whitelist_type("segment_command.*") | ||
.whitelist_var("MH_MAGIC.*") | ||
.whitelist_var("LC_SEGMENT.*") | ||
.whitelist_var("LC_UUID.*") | ||
.generate() | ||
.expect("Should generate macOS FFI bindings OK"); | ||
|
||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("macos_bindings.rs")) | ||
.expect("Should write macos_bindings.rs OK"); | ||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("macos_bindings.rs")) | ||
.expect("Should write macos_bindings.rs OK"); | ||
} | ||
} else { | ||
fn main() {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters