Skip to content

Commit

Permalink
Support target pointer width. (#233)
Browse files Browse the repository at this point in the history
* Use target pointer width if set

* panic if not 32 or 64 bits
  • Loading branch information
scrogson authored Oct 15, 2019
1 parent 2c7b016 commit 144d89b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rustler_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
//

use std::env;
use std::os::raw::c_ulong;
use std::path::Path;
use std::process::Command;

fn main() {
// use environment escript if available
let escript = env::var("ESCRIPT").unwrap_or("escript".to_string());

// get size of C long
let ulong_size = std::mem::size_of::<c_ulong>();
let target_pointer_width = match env::var("CARGO_CFG_TARGET_POINTER_WIDTH") {
Ok(ref val) if val == "32" => "4",
Ok(ref val) if val == "64" => "8",
Ok(ref val) => panic!("Unsupported target pointer width: {}", val),
Err(err) => panic!(
"An error occurred while determining the pointer width to compile `rustler_sys` for:\n\n{:?}\n\nPlease report a bug.",
err
),
};

// setup output directory
let out_dir = env::var("OUT_DIR")
Expand All @@ -23,7 +28,7 @@ fn main() {
let dst = Path::new(&out_dir);
match Command::new(escript)
.arg("gen_api.erl")
.arg(ulong_size.to_string())
.arg(target_pointer_width.to_string())
.arg(dst)
.status()
.map_err(|_| "Failed to start gen_api.erl. Is 'escript' available in the path?")
Expand Down

0 comments on commit 144d89b

Please sign in to comment.