Skip to content

Commit

Permalink
make bingen a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kali committed Mar 12, 2018
1 parent 74191cb commit abd8970
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ on the platform you want to test.
* Dinghy offers an [overlay](docs/overlay.md) system to "add" stuff to your toolchain
sysroot. This allows you to add "stuff" to your build dependencies, like static libraries or headers
without altering the sysroot toolchain.
* The [`dinghy-helper` crate](docs/helper.md) offers some `build.rs` features that are useful in
* The [`dinghy-build` crate](docs/dinghy-build.md) offers some `build.rs` features that are useful in
the context of cross-compilation.

# License
Expand Down
5 changes: 4 additions & 1 deletion dinghy-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ keywords = [
categories = [ "development-tools::cargo-plugins", "development-tools::testing" , "development-tools::profiling" ]

[dependencies]
bindgen = "0"
bindgen = { version = "0", optional = true }
error-chain = { version = "0.11.0", default-features = false }
gcc = "0.3"
log="0.3"

[features]
with-bindgen = [ "bindgen" ]
18 changes: 16 additions & 2 deletions dinghy-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
//! shared wisdom and conventions across build.rs scripts, cargo, dinghy,
//! cc-rs, pkg-config-rs, bindgen, and others. It also helps providing
//! cross-compilation arguments to autotools `./configure` scripts.
//!
//! As an optional feature, it offers `with-bindgen`, which helps dealing with
//! some idiosyncrasies of `bindgen` code generation.
#[cfg(features="with-bindgen")]
extern crate bindgen;
#[macro_use]
extern crate error_chain;
Expand All @@ -22,7 +26,6 @@ use build::is_cross_compiling;
use build_env::sysroot_path;
use build_env::target_env;
use std::env;
use std::env::current_dir;
use std::ffi::OsStr;
use std::path::Path;
use std::path::PathBuf;
Expand Down Expand Up @@ -112,7 +115,11 @@ impl CommandExt for Command {
}
}


/// Omnibus helper for bindgen crosscompilation patches.
///
/// Crate a bindgen builder for the target toolchain, with Apple patch and
/// gcc_system patch.
#[cfg(features="with-bindgen")]
pub fn new_bindgen_with_cross_compilation_support() -> Result<bindgen::Builder> {
Ok(bindgen::Builder::default()
.clang_arg("--verbose")
Expand All @@ -121,7 +128,10 @@ pub fn new_bindgen_with_cross_compilation_support() -> Result<bindgen::Builder>
.apple_patch()?)
}

#[cfg(features="with-bindgen")]
pub trait BindGenBuilderExt {
/// Change target arch name `aarch64` to `arm64` for better CLang
/// compatibility.
fn apple_patch(self) -> Result<bindgen::Builder>;

fn detect_toolchain(self) -> Result<bindgen::Builder>;
Expand All @@ -130,9 +140,13 @@ pub trait BindGenBuilderExt {

fn header_in_current_dir(self, header_file_name: &str) -> Result<bindgen::Builder>;

/// Ugly hack to include gcc system headers from the target computer inside
/// the search path of the CLang compiler that will be used to build
/// bindings.
fn include_gcc_system_headers(self) -> Result<bindgen::Builder>;
}

#[cfg(features="with-bindgen")]
impl BindGenBuilderExt for bindgen::Builder {
fn apple_patch(self) -> Result<bindgen::Builder> {
if is_cross_compiling()? {
Expand Down
File renamed without changes.

0 comments on commit abd8970

Please sign in to comment.