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

Conversation

emilio
Copy link
Contributor

@emilio emilio commented Dec 11, 2016

r? @fitzgen

This is a rebase of #280

@emilio
Copy link
Contributor Author

emilio commented Dec 11, 2016

Added other kinda random fixups that I found as user of the library.

span: Option<Span>)
-> 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?

use clang::Diagnostic;
use clangll::*;

let mut any_error = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be easier to get context.translation_unit().diags() first, and if it is not empty, iterate it and return Err.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In diags there can be warnings too, so we'd need to filter them.

@@ -168,8 +168,8 @@ impl Builder {
/// Set the input C/C++ header.
pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
let header = header.into();
self.options.input_header = Some(header.clone());
self.clang_arg(header)
self.options.input_header = Some(header);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the only effect of this function is setting input_header, I guess it probably makes sense to assert that input_header is None before assigning it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't quite fit with the rest of the builder methods, I think overriding it, albeit uncommon, should be fine?

@@ -0,0 +1,6 @@
// bindgen-flags: -- -x c++ --std=c++11
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how this test is related to this commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is related because before that, that gives an error due to us sending the header before -x c++, and treats it as C because it's a .h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That being said that's probably a clang bug.

@emilio
Copy link
Contributor Author

emilio commented Dec 12, 2016

@bors-servo r=xidorn

@bors-servo
Copy link

📌 Commit 8a60512 has been approved by xidorn

@bors-servo
Copy link

⚡ Test exempted - status

@bors-servo bors-servo merged commit 8a60512 into rust-lang:master Dec 12, 2016
bors-servo pushed a commit that referenced this pull request Dec 12, 2016
lib: Return error early if there are any error diagnostics.

r? @fitzgen

This is a rebase of #280
@emilio emilio deleted the error branch December 12, 2016 10:19
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.

@emilio
Copy link
Contributor Author

emilio commented Feb 3, 2017 via email

@upsuper
Copy link
Contributor

upsuper commented Feb 5, 2017

I suppose libclang should have the same path searching behavior as the command line clang, so doing this doesn't add much value. Is that not true? Do you mean that libclang may not add system search path by default? Could you share some examples that things would not work without this fixup but works fine when using the command line clang?

@emilio
Copy link
Contributor Author

emilio commented Feb 5, 2017

I suppose libclang should have the same path searching behavior as the command line clang, so doing this doesn't add much value. Is that not true?

Nope, unfortunately. see #242 for an issue fixed by this path fixup. I'm sure there are more in the backlog of issues and the old repo.

@upsuper
Copy link
Contributor

upsuper commented Feb 5, 2017

The issue doesn't mention the code and the arguments they use (thus not reproducible), so it isn't very convincing to me. It is possible that some environment or argument they provide (or lack) affects the search path decision, and the hacky fixup happens to fill the gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants