Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow static and dynamic linking #1620

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,10 @@ env:
global:
- CARGO_TARGET_DIR=/tmp/bindgen
matrix:
- LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE=
- LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.8" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE=
- LLVM_VERSION="3.8" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE=
- LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.9" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE=
- LLVM_VERSION="3.9" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE="--release"
- LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE=
- LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
- LLVM_VERSION="4.0" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE=
- LLVM_VERSION="4.0" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE="--release"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions"
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cexpr = "0.3.3"
cfg-if = "0.1.0"
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
clap = { version = "2", optional = true }
clang-sys = { version = "0.28.0", features = ["runtime", "clang_6_0"] }
clang-sys = { version = "0.28.0", features = ["clang_6_0"] }
lazycell = "1"
lazy_static = "1"
peeking_take_while = "0.1.2"
Expand All @@ -71,9 +71,10 @@ optional = true
version = "0.4"

[features]
default = ["logging", "clap", "which-rustfmt"]
default = ["logging", "clap", "runtime", "which-rustfmt"]
logging = ["env_logger", "log"]
static = []
static = ["clang-sys/static"]
runtime = ["clang-sys/runtime"]
# Dynamically discover a `rustfmt` binary using the `which` crate
which-rustfmt = ["which"]

Expand Down
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ use std::fs::{File, OpenOptions};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::{env, iter};

// Some convenient typedefs for a fast hash map and hash set.
Expand Down Expand Up @@ -1720,6 +1719,7 @@ impl Default for BindgenOptions {
}
}

#[cfg(feature = "runtime")]
fn ensure_libclang_is_loaded() {
if clang_sys::is_loaded() {
return;
Expand All @@ -1730,7 +1730,7 @@ fn ensure_libclang_is_loaded() {
// across different threads.

lazy_static! {
static ref LIBCLANG: Arc<clang_sys::SharedLibrary> = {
static ref LIBCLANG: std::sync::Arc<clang_sys::SharedLibrary> = {
clang_sys::load().expect("Unable to find libclang");
clang_sys::get_library().expect(
"We just loaded libclang and it had better still be \
Expand All @@ -1742,6 +1742,10 @@ fn ensure_libclang_is_loaded() {
clang_sys::set_library(Some(LIBCLANG.clone()));
}

#[cfg(not(feature = "runtime"))]
fn ensure_libclang_is_loaded() {
}

/// Generated Rust bindings.
#[derive(Debug)]
pub struct Bindings {
Expand All @@ -1756,10 +1760,13 @@ impl Bindings {
) -> Result<Bindings, ()> {
ensure_libclang_is_loaded();

#[cfg(feature = "runtime")]
debug!(
"Generating bindings, libclang at {}",
clang_sys::get_library().unwrap().path().display()
);
#[cfg(not(feature = "runtime"))]
debug!("Generating bindings, libclang linked");

options.build();

Expand Down Expand Up @@ -2115,10 +2122,7 @@ pub struct ClangVersion {

/// Get the major and the minor semver numbers of Clang's version
pub fn clang_version() -> ClangVersion {
if !clang_sys::is_loaded() {
// TODO(emilio): Return meaningful error (breaking).
clang_sys::load().expect("Unable to find libclang");
}
ensure_libclang_is_loaded();

let raw_v: String = clang::extract_clang_version();
let split_v: Option<Vec<&str>> = raw_v
Expand Down
17 changes: 0 additions & 17 deletions tests/expectations/tests/libclang-3.8/abi_variadic_function.rs

This file was deleted.

37 changes: 0 additions & 37 deletions tests/expectations/tests/libclang-3.8/auto.rs

This file was deleted.

55 changes: 0 additions & 55 deletions tests/expectations/tests/libclang-3.8/call-conv-field.rs

This file was deleted.

37 changes: 0 additions & 37 deletions tests/expectations/tests/libclang-3.8/const_bool.rs

This file was deleted.

37 changes: 0 additions & 37 deletions tests/expectations/tests/libclang-3.8/constant-evaluate.rs

This file was deleted.

This file was deleted.

This file was deleted.

Loading