Skip to content

lib: Return error early if there are any error diagnostics. #330

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
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 0 additions & 25 deletions bindgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,6 @@ pub fn main() {
_ => {}
}

if let Some(clang) = clang_sys::support::Clang::find(None) {
let has_clang_args =
bind_args.iter().rposition(|arg| *arg == "--").is_some();
if !has_clang_args {
bind_args.push("--".to_owned());
}

// If --target is specified, assume caller knows what they're doing and
// don't mess with
// include paths for them
let has_target_arg = bind_args.iter()
.rposition(|arg| arg.starts_with("--target"))
.is_some();
if !has_target_arg {
// TODO: distinguish C and C++ paths? C++'s should be enough, I
// guess.
for path in clang.cpp_search_paths.into_iter() {
if let Ok(path) = path.into_os_string().into_string() {
bind_args.push("-isystem".to_owned());
bind_args.push(path);
}
}
}
}

match builder_from_flags(bind_args.into_iter()) {
Ok((builder, output)) => {
let mut bindings = builder.generate()
Expand Down
19 changes: 19 additions & 0 deletions libbindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,25 @@ impl<'ctx> Bindings<'ctx> {
-> Result<Bindings<'ctx>, ()> {
let span = span.unwrap_or(DUMMY_SP);

// TODO: Make this path fixup configurable?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you can move the has_target_arg to wrap the Clang::find block, so that it is somehow configurable?

if let Some(clang) = clang_sys::support::Clang::find(None) {
// If --target is specified, assume caller knows what they're doing
// and don't mess with include paths for them
let has_target_arg = options.clang_args.iter()
.rposition(|arg| arg.starts_with("--target"))
.is_some();
if !has_target_arg {
// TODO: distinguish C and C++ paths? C++'s should be enough, I
// guess.
for path in clang.cpp_search_paths.into_iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I start wondering (again) why do we need this fixup. What would happen if we don't have it? It doesn't seem to me it would fail to build without this on macOS (since I can run stylo bindgen with --target=x86_64-apple-darwin -stdlib=libc++ specified), and we've already disabled it for stylo build on Windows (because we always specify --target). So Linux?

My guess is that the user of this library should always specify things they need, e.g. -stdlib=libc++ or -stdlib=libstdc++, rather than we doing hacky fixup under the hood.

Also, other than --target, there are many clang arguments can affect search path selection as well, e.g. -stdlib, and -mmacos-version-min on macOS, which means the paths here may not match what user expect, and thus add noise.

The recent example of bustage with MACOSX_DEPOLYMENT_TARGET environment is probably another example of harmfulness this kind of implicit fixup adds. If we have -stdlib=libc++ specified since the very beginning because of the lack of this fixup, that may never happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we remove this hacky fixup and do a breaking version bump, then teach users to add what they need themselves.

if let Ok(path) = path.into_os_string().into_string() {
options.clang_args.push("-isystem".to_owned());
options.clang_args.push(path);
}
}
}
}

if let Some(h) = options.input_header.as_ref() {
options.clang_args.push(h.clone())
}
Expand Down