Skip to content

Odd behavior generating clang arguments #1352

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

Closed
joshlf opened this issue Jul 29, 2018 · 3 comments
Closed

Odd behavior generating clang arguments #1352

joshlf opened this issue Jul 29, 2018 · 3 comments

Comments

@joshlf
Copy link
Contributor

joshlf commented Jul 29, 2018

I've discovered odd behavior with how bindgen generates flags to pass to clang. In particular, I added a println! here to print the clang_args variable.

Bindgen Invocation and Results

Here are three different invocations of bindgen along with the value of clang_args that was printed as a result:

  • bindgen bindgen.h
    • ["--target=x86_64-apple-darwin", "-isystem", "/Library/Developer/CommandLineTools/usr/include/c++/v1", "-isystem", "/usr/local/include", "-isystem", "/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include", "-isystem", "/Library/Developer/CommandLineTools/usr/include", "-isystem", "/usr/include", "-isystem", "/System/Library/Frameworks", "-isystem", "/Library/Frameworks", "bindgen.h"]
  • bindgen bindgen.h -- -I foo
    • ["--target=x86_64-apple-darwin", "-I", "foo", "-isystem", "/Library/Developer/CommandLineTools/usr/include/c++/v1", "-isystem", "/usr/local/include", "-isystem", "/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include", "-isystem", "/Library/Developer/CommandLineTools/usr/include", "-isystem", "/usr/include", "-isystem", "/System/Library/Frameworks", "-isystem", "/Library/Frameworks", "bindgen.h"]
  • bindgen bindgen.h -- -foo bar
    • ["--target=x86_64-apple-darwin", "-foo", "bar", "bindgen.h"]
  • bindgen bindgen.h -- --target=foo
    • ["--target=foo", "bindgen.h"]

Expected Results

Unrecognized flags such as -foo shouldn't affect other flags that are passed, such as -isystem. I'm not sure whether --target altering what flags are passed is intentional; at the least, bindgen seems smart enough to realize that the --target argument should replace the default --target=x86_64-apple-darwin.

I found this while debugging #1331, and I suspect that they may be related.

@emilio
Copy link
Contributor

emilio commented Jul 29, 2018

So, this is kind of annoying, but it does matter because we get the include directories from clang itself, but pass the original flags so that clang actually reports the directories that will be used, instead of other random stuff.

So if the original flags are not valid, we won't ever find the include paths. I'm not sure this is a bug, fwiw.

I'm aware that the TranslationUnit::parse error message is not great, it'd be awesome to be able to get a better error from clang, but the API doesn't expose anything sensible, so we could only try to guess.

We'd get the same message for "the file you passed doesn't exist", "the target isn't valid", "some other flag is not known"...

@joshlf
Copy link
Contributor Author

joshlf commented Jul 29, 2018

Ah, that's a shame. Oh well. I understand the limitations, though.

@emilio
Copy link
Contributor

emilio commented Jul 30, 2018

Alright, closing then.

Note that there's #297 to consider moving away from libclang, which presumably would allow us to get better error information... But that's a bigger undertaking as well :)

@emilio emilio closed this as completed Jul 30, 2018
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

No branches or pull requests

2 participants