Skip to content

Static linking #1649

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

Merged
merged 3 commits into from
Oct 21, 2019
Merged
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
45 changes: 32 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,55 @@ env:
- 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="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1"

- 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="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1"

- 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= BINDGEN_NO_DEFAULT_FEATURES="1"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1"

- 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="integration" BINDGEN_PROFILE=
- LLVM_VERSION="5.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
- LLVM_VERSION="5.0" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE=
- LLVM_VERSION="5.0" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE="--release"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1"

# FIXME: There are no pre-built static libclang libraries, so this is not testable at the moment.
# - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1"
# - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1"

- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions"
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="testing_only_extra_assertions"
- LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE=
- LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
- LLVM_VERSION="9.0" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE=
- LLVM_VERSION="9.0" BINDGEN_JOB="nofeatures" BINDGEN_PROFILE="--release"
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1"
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1"

# FIXME: There are no pre-built static libclang libraries, so this is not testable at the moment.
# - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1"
# - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1"

# Testing with extra asserts enabled
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions"
- LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="testing_only_extra_assertions"


# Test the expectations build and pass tests.
- LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE=
- LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release"

# Miscellaneous tests.
- LLVM_VERSION="9.0" BINDGEN_JOB="misc"
- LLVM_VERSION="9.0" BINDGEN_JOB="quickchecking"

Expand All @@ -60,7 +79,7 @@ cache:
before_install: . ./ci/before_install.sh

script:
- BINDGEN_JOB="$BINDGEN_JOB" BINDGEN_PROFILE="$BINDGEN_PROFILE" BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/script.sh
- BINDGEN_JOB="$BINDGEN_JOB" BINDGEN_PROFILE="$BINDGEN_PROFILE" BINDGEN_FEATURES="$BINDGEN_FEATURES" BINDGEN_NO_DEFAULT_FEATURES="$BINDGEN_NO_DEFAULT_FEATURES" ./ci/script.sh

after_success:
- test "$TRAVIS_PULL_REQUEST" == "false" &&
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
19 changes: 7 additions & 12 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ cd "$(dirname "$0")/.."

export RUST_BACKTRACE=1

NO_DEFAULT_FEATURES=""
if [ ! -z $BINDGEN_NO_DEFAULT_FEATURES ]; then
NO_DEFAULT_FEATURES=--no-default-features
fi

case "$BINDGEN_JOB" in
"test")
# Need rustfmt to compare the test expectations.
Expand All @@ -17,23 +22,13 @@ case "$BINDGEN_JOB" in
rustup component add --toolchain nightly rustfmt
RUSTFMT="$(rustup which rustfmt)"
export RUSTFMT
cargo test "$BINDGEN_PROFILE" --features "$BINDGEN_FEATURES"
cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES"
./ci/assert-no-diff.sh
;;

"integration")
cd ./bindgen-integration
cargo test "$BINDGEN_PROFILE" --features "$BINDGEN_FEATURES"
;;

"nofeatures")
rustup update nightly
rustup component add rustfmt
rustup component add --toolchain nightly rustfmt
RUSTFMT="$(rustup which rustfmt)"
export RUSTFMT
cargo test "$BINDGEN_PROFILE" --no-default-features
./ci/assert-no-diff.sh
cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES"
;;

"expectations")
Expand Down
15 changes: 9 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,9 @@ 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 +1759,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 +2121,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