mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.64k stars 1.64k forks source link

dependency() can leak gcc-isms to rustc #9775

Open linkmauve opened 2 years ago

linkmauve commented 2 years ago

Describe the bug When passing dependency() to a Rust target, if the .pc file includes a non-system header, meson passes it to the rustc invocation, making it fail. Here is an example using valgrind.pc:

[1/1] Compiling Rust source ../test.rs
FAILED: libtestcase.so 
rustc -C linker=cc --color=always --crate-type dylib -g -C relocation-model=pic -I/usr/include/valgrind --crate-name testcase --emit dep-info=testcase.d --emit link -o libtestcase.so -C prefer-dynamic ../test.rs
error: Unrecognized option: 'I'

ninja: build stopped: subcommand failed.

To Reproduce

project('testcase', 'rust')
shared_library('testcase', 'test.rs', dependencies: dependency('valgrind'))

test.rs can contain anything, the issue happens before that.

Expected behavior meson would not pass the -I to rustc, nor any other argument this compiler doesn’t know, and the compilation would continue properly.

system parameters

eli-schwartz commented 2 years ago

How should meson know whether any given argument is vital to operation?

I think what you actually want to do is divide the dependency object in two:

... except the unstable_rust module cannot actually process a dependency object? It seems to solely assume you are bindgen'ing a header that is in your project sources.

dcbaker commented 2 years ago

Yeah, right now the bindgen helper in the rust module assumes you're working with a local header (since that's what my use case was when I added it).

We really should figure out the includes though to rust targets automatically, but we really need to do some refactoring of the way dependencies work to fix that I think.

bonzini commented 2 years ago

Are there any compile_args that rustc should receive?

dcbaker commented 2 years ago

Likely yes, but not that we can handle. Our handling of dependencies is currently very C-family centric. We assume that compile_args are C-like in basically every case.

bonzini commented 2 years ago

That's what I thought, so it's easier to just ignore them altogether in rustc command lines.

dcbaker commented 2 years ago

Likely for now, yes. We should mark that ignoring them is a work around

sdroege commented 1 year ago

I think this should be fixed with https://github.com/mesonbuild/meson/pull/11674 ?