Skip to content

Try to get CI up and running on libclang 9 #1646

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 15 commits into from
Oct 14, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 13 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@ env:
- 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"
- LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="testing_only_extra_assertions"
- 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="expectations" BINDGEN_PROFILE=
- LLVM_VERSION="5.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release"
- LLVM_VERSION="5.0" BINDGEN_JOB="misc"
- LLVM_VERSION="5.0" BINDGEN_JOB="quickchecking"
- 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="expectations" BINDGEN_PROFILE=
- LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release"
- LLVM_VERSION="9.0" BINDGEN_JOB="misc"
- LLVM_VERSION="9.0" BINDGEN_JOB="quickchecking"

matrix:
fast_finish: true
allow_failures:
- env: LLVM_VERSION=5.0 BINDGEN_JOB=rustfmt
- env: LLVM_VERSION=9.0 BINDGEN_JOB=rustfmt

cache:
directories:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ which-rustfmt = ["which"]
# on bindgen!
testing_only_docs = []
testing_only_extra_assertions = []
testing_only_libclang_9 = []
testing_only_libclang_5 = []
testing_only_libclang_4 = []
testing_only_libclang_3_9 = []
Expand Down
8 changes: 7 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ environment:
- TARGET: gnu
LLVM_VERSION: 4.0.0-1
BINDGEN_FEATURES: testing_only_libclang_4
- TARGET: msvc
- TARGET: gnu
LLVM_VERSION: 5.0.0-1
BINDGEN_FEATURES: testing_only_libclang_5
- TARGET: gnu
LLVM_VERSION: 9.0.0-1
BINDGEN_FEATURES: testing_only_libclang_9
- TARGET: msvc
LLVM_VERSION: 3.9.0
BINDGEN_FEATURES: testing_only_libclang_3_9
Expand All @@ -20,6 +23,9 @@ environment:
- TARGET: msvc
LLVM_VERSION: 5.0.0
BINDGEN_FEATURES: testing_only_libclang_5
- TARGET: msvc
LLVM_VERSION: 9.0.0
BINDGEN_FEATURES: testing_only_libclang_9

configuration:
- stable
Expand Down
1 change: 1 addition & 0 deletions bindgen-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bindgen = { path = ".." }
cc = "1.0"

[features]
testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"]
testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"]
testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"]
testing_only_libclang_3_9 = ["bindgen/testing_only_libclang_3_9"]
Expand Down
8 changes: 4 additions & 4 deletions bindgen-integration/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ impl ParseCallbacks for MacroCallback {
}

fn str_macro(&self, name: &str, value: &[u8]) {
match &name {
&"TESTMACRO_STRING_EXPANDED"
| &"TESTMACRO_STRING"
| &"TESTMACRO_INTEGER" => {
match name {
"TESTMACRO_STRING_EXPANDED" |
"TESTMACRO_STRING" |
"TESTMACRO_INTEGER" => {
// The integer test macro is, actually, not expected to show up here at all -- but
// should produce an error if it does.
assert_eq!(
Expand Down
2 changes: 2 additions & 0 deletions ci/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function llvm_version_triple() {
echo "4.0.0"
elif [ "$1" == "5.0" ]; then
echo "5.0.0"
elif [ "$1" == "9.0" ]; then
echo "9.0.0"
fi
}

Expand Down
3 changes: 1 addition & 2 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ case "$BINDGEN_JOB" in
./ci/assert-docs.sh
./ci/test-book.sh
./ci/no-includes.sh
# Disabled because https://github.com/rust-lang/rustfmt/issues/3799.
# ./ci/assert-rustfmt.sh
./ci/assert-rustfmt.sh
;;

"quickchecking")
Expand Down
41 changes: 25 additions & 16 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,25 +527,32 @@ impl Cursor {
}
}

/// Does this cursor have the given simple attribute?
/// Whether this cursor has the `warn_unused_result` attribute.
pub fn has_warn_unused_result_attr(&self) -> bool {
// FIXME(emilio): clang-sys doesn't expose this (from clang 9).
const CXCursor_WarnUnusedResultAttr: CXCursorKind = 440;
self.has_attr("warn_unused_result", Some(CXCursor_WarnUnusedResultAttr))
}

/// Does this cursor have the given attribute?
///
/// Note that this will only work for attributes that don't have an existing libclang
/// CursorKind, e.g. pure, const, etc.
pub fn has_simple_attr(&self, attr: &str) -> bool {
/// `name` is checked against unexposed attributes.
fn has_attr(&self, name: &str, clang_kind: Option<CXCursorKind>) -> bool {
let mut found_attr = false;
self.visit(|cur| {
if cur.kind() == CXCursor_UnexposedAttr {
found_attr = cur.tokens().iter().any(|t| {
t.kind == CXToken_Identifier &&
t.spelling() == attr.as_bytes()
});

if found_attr {
return CXChildVisit_Break;
}
let kind = cur.kind();
found_attr = clang_kind.map_or(false, |k| k == kind) ||
(kind == CXCursor_UnexposedAttr &&
cur.tokens().iter().any(|t| {
t.kind == CXToken_Identifier &&
t.spelling() == name.as_bytes()
}));

if found_attr {
CXChildVisit_Break
} else {
CXChildVisit_Continue
}

CXChildVisit_Continue
});

found_attr
Expand Down Expand Up @@ -726,7 +733,9 @@ impl Cursor {
if file.is_null() {
None
} else {
Some(unsafe { cxstring_into_string(clang_sys::clang_getFileName(file)) })
Some(unsafe {
cxstring_into_string(clang_sys::clang_getFileName(file))
})
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ macro_rules! rust_feature_def {
}

rust_feature_def!(
Stable_1_1 {
/// [c_void available in core](https://doc.rust-lang.org/core/ffi/enum.c_void.html)
=> core_ffi_c_void;
}
Stable_1_19 {
/// Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md))
=> untagged_union;
Expand Down Expand Up @@ -204,6 +200,8 @@ rust_feature_def!(
/// `const fn` support for limited cases
/// ([PR](https://github.com/rust-lang/rust/pull/54835/)
=> min_const_fn;
/// [c_void available in core](https://doc.rust-lang.org/core/ffi/enum.c_void.html)
=> core_ffi_c_void;
}
Stable_1_33 {
/// repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049))
Expand Down Expand Up @@ -242,7 +240,7 @@ mod test {
);
let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21);
assert!(
f_1_21.core_ffi_c_void &&
!f_1_21.core_ffi_c_void &&
f_1_21.untagged_union &&
f_1_21.associated_const &&
f_1_21.builtin_clone_impls &&
Expand Down
4 changes: 2 additions & 2 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ impl BindgenContext {
clang_sys::CXTranslationUnit_DetailedPreprocessingRecord;

let translation_unit = {
let _t = Timer::new("translation_unit")
.with_output(options.time_phases);
let _t =
Timer::new("translation_unit").with_output(options.time_phases);
let clang_args = if explicit_target {
Cow::Borrowed(&options.clang_args)
} else {
Expand Down
6 changes: 1 addition & 5 deletions src/ir/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ where
&mut dot_file,
r#"{} [fontname="courier", color={}, label=< <table border="0" align="left">"#,
id.as_usize(),
if is_whitelisted {
"black"
} else {
"gray"
}
if is_whitelisted { "black" } else { "gray" }
)?;
item.dot_attributes(ctx, &mut dot_file)?;
writeln!(&mut dot_file, r#"</table> >];"#)?;
Expand Down
2 changes: 1 addition & 1 deletion src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl FunctionSig {
};

let must_use = ctx.options().enable_function_attribute_detection &&
cursor.has_simple_attr("warn_unused_result");
cursor.has_warn_unused_result_attr();
let is_method = kind == CXCursor_CXXMethod;
let is_constructor = kind == CXCursor_Constructor;
let is_destructor = kind == CXCursor_Destructor;
Expand Down
28 changes: 16 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ pub fn main() {
let bind_args: Vec<_> = env::args().collect();

let version = clang_version();
let expected_version = if cfg!(feature = "testing_only_libclang_4") {
(4, 0)
let expected_version = if cfg!(feature = "testing_only_libclang_9") {
Some((9, 0))
} else if cfg!(feature = "testing_only_libclang_5") {
Some((5, 0))
} else if cfg!(feature = "testing_only_libclang_4") {
Some((4, 0))
} else if cfg!(feature = "testing_only_libclang_3_9") {
Some((3, 9))
} else if cfg!(feature = "testing_only_libclang_3_8") {
(3, 8)
Some((3, 8))
} else {
// Default to 3.9.
(3, 9)
None
};

info!("Clang Version: {}", version.full);
info!(
"Clang Version: {}, parsed: {:?}",
version.full, version.parsed
);

match version.parsed {
None => warn!("Couldn't parse libclang version"),
Some(version) if version != expected_version => {
warn!("Using clang {:?}, expected {:?}", version, expected_version);
}
_ => {}
if expected_version.is_some() {
assert_eq!(version.parsed, version.parsed);
}

match builder_from_flags(bind_args.into_iter()) {
Expand Down
9 changes: 7 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use bindgen::{builder, Builder, CodegenConfig, EnumVariation, RustTarget, RUST_TARGET_STRINGS};
use bindgen::{
builder, Builder, CodegenConfig, EnumVariation, RustTarget,
RUST_TARGET_STRINGS,
};
use clap::{App, Arg};
use std::fs::File;
use std::io::{self, stderr, Error, ErrorKind, Write};
use std::path::PathBuf;
use std::str::FromStr;

/// Construct a new [`Builder`](./struct.Builder.html) from command line flags.
pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<dyn io::Write>, bool), io::Error>
pub fn builder_from_flags<I>(
args: I,
) -> Result<(Builder, Box<dyn io::Write>, bool), io::Error>
where
I: Iterator<Item = String>,
{
Expand Down
18 changes: 13 additions & 5 deletions tests/expectations/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ use std::fs;
use std::io::Write;
use std::path::Path;

const LIBCLANG_VERSION_DIRS: &'static [&'static str] =
&["libclang-3.8", "libclang-3.9", "libclang-4", "libclang-5"];
const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[
"libclang-3.8",
"libclang-3.9",
"libclang-4",
"libclang-5",
"libclang-9",
];

fn main() {
println!("cargo:rerun-if-changed=build.rs");
Expand All @@ -27,17 +32,20 @@ fn main() {
let entry = entry.unwrap();
let path = entry.path();
let path = path.canonicalize().unwrap_or_else(|_| path.into());
if path.extension().map(|e| e.to_string_lossy()) != Some("rs".into()) {
if path.extension().map(|e| e.to_string_lossy()) !=
Some("rs".into())
{
continue;
}

println!("cargo:rerun-if-changed={}", path.display());

let module_name: String = path.display()
let module_name: String = path
.display()
.to_string()
.chars()
.map(|c| match c {
'a'...'z' | 'A'...'Z' | '0'...'9' => c,
'a'..='z' | 'A'..='Z' | '0'..='9' => c,
_ => '_',
})
.collect();
Expand Down
1 change: 1 addition & 0 deletions tests/expectations/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading