Skip to content

Commit

Permalink
Use a custom env variable to get the clang flags
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricedesre committed Jun 8, 2018
1 parent a110347 commit 7f91e52
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ extern crate bindgen;
extern crate cc;

use std::env;
use std::path::PathBuf;
use std::ffi::{OsStr, OsString};
use std::path::PathBuf;
use std::process::{Command, Stdio};

fn main() {
Expand All @@ -33,24 +33,14 @@ fn find_make() -> OsString {
}

fn cc_flags() -> Vec<&'static str> {
let mut result = vec![
"-DRUST_BINDGEN",
"-DSTATIC_JS_API",
];
let mut result = vec!["-DRUST_BINDGEN", "-DSTATIC_JS_API"];

if cfg!(feature = "debugmozjs") {
result.extend(&[
"-DJS_GC_ZEAL",
"-DDEBUG",
"-DJS_DEBUG",
]);
result.extend(&["-DJS_GC_ZEAL", "-DDEBUG", "-DJS_DEBUG"]);
}

if cfg!(windows) {
result.extend(&[
"-std=c++14",
"-DWIN32",
]);
result.extend(&["-std=c++14", "-DWIN32"]);
} else {
result.extend(&[
"-std=gnu++11",
Expand Down Expand Up @@ -88,7 +78,8 @@ fn build_jsapi() {
cmd.env("MAKEFLAGS", makeflags);
}

let result = cmd.args(&["-R", "-f", "makefile.cargo"])
let result = cmd
.args(&["-R", "-f", "makefile.cargo"])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
Expand All @@ -111,10 +102,9 @@ fn build_jsapi() {
println!("cargo:outdir={}", out_dir);
}


fn build_jsglue() {
let out = PathBuf::from(env::var("OUT_DIR").unwrap());

let mut build = cc::Build::new();
build.cpp(true);

Expand Down Expand Up @@ -142,7 +132,7 @@ fn build_jsapi_bindings() {
config.constructors = false;
config.destructors = false;
config.methods = false;

let mut builder = bindgen::builder()
.rust_target(bindgen::RustTarget::Stable_1_19)
.header("./src/jsglue.hpp")
Expand All @@ -159,7 +149,7 @@ fn build_jsapi_bindings() {
builder = builder.clang_arg("-fms-compatibility");
}

if let Ok(flags) = env::var("CXXFLAGS") {
if let Ok(flags) = env::var("BINDGEN_CXXFLAGS") {
for flag in flags.split_whitespace() {
builder = builder.clang_arg(flag);
}
Expand Down Expand Up @@ -199,10 +189,12 @@ fn build_jsapi_bindings() {
builder = builder.module_raw_line(module, raw_line);
}

let bindings = builder.generate()
.expect("Should generate JSAPI bindings OK");
let bindings = builder
.generate()
.expect("Should generate JSAPI bindings OK.");

bindings.write_to_file(out.join("jsapi.rs"))
bindings
.write_to_file(out.join("jsapi.rs"))
.expect("Should write bindings to file OK");

println!("cargo:rerun-if-changed=src/jsglue.hpp");
Expand All @@ -219,11 +211,7 @@ const UNSAFE_IMPL_SYNC_TYPES: &'static [&'static str] = &[

/// Types which we want to generate bindings for (and every other type they
/// transitively use).
const WHITELIST_TYPES: &'static [&'static str] = &[
"JS.*",
"js::.*",
"mozilla::.*",
];
const WHITELIST_TYPES: &'static [&'static str] = &["JS.*", "js::.*", "mozilla::.*"];

/// Global variables we want to generate bindings to.
const WHITELIST_VARS: &'static [&'static str] = &[
Expand All @@ -240,7 +228,7 @@ const WHITELIST_VARS: &'static [&'static str] = &[

/// Functions we want to generate bindings to.
const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
"ExceptionStackOrNull",
"ExceptionStackOrNull",
"glue::.*",
"JS::.*",
"js::.*",
Expand Down Expand Up @@ -287,5 +275,8 @@ const MODULE_RAW_LINES: &'static [(&'static str, &'static str)] = &[
("root", "pub type FILE = ::libc::FILE;"),
("root", "pub type JSJitInfo = ::jsjit::JSJitInfo;"),
("root::JS", "pub type Heap<T> = ::jsgc::Heap<T>;"),
("root::JS", "pub type AutoGCRooterTag = AutoGCRooter__bindgen_ty_1;"),
(
"root::JS",
"pub type AutoGCRooterTag = AutoGCRooter__bindgen_ty_1;",
),
];

0 comments on commit 7f91e52

Please sign in to comment.