Skip to content

Do not put RUSTFLAGS into rust_link_args#15627

Open
bonzini wants to merge 3 commits intomesonbuild:masterfrom
bonzini:rust-no-env-to-link-args
Open

Do not put RUSTFLAGS into rust_link_args#15627
bonzini wants to merge 3 commits intomesonbuild:masterfrom
bonzini:rust-no-env-to-link-args

Conversation

@bonzini
Copy link
Contributor

@bonzini bonzini commented Mar 16, 2026

Environment.add_lang_args adds RUSTFLAGS to rust_link_args just like it does so for CFLAGS. However, this breaks compilation because RustCompiler treats linker arguments specially by prepending -Clink-arg= to them.

For Rust specifically, the compiler and linker invocations are one and the same and there's no separate -c phase; therefore, having RUSTFLAGS in both rust_args and rust_link_args is pointless.

This is handled just fine by the existing INVOKES_LINKER attribute of Compiler, but the name does not really apply to rustc so rename it as a preparatory step.

This has the same purpose as #15621, which however has a broader impact—the contents of the rust_link_args option lose the -Clink-arg= prefix altogether, which I think is unwanted because it makes add_project_link_arguments behave differently from rust_link_args.

bonzini added 3 commits March 16, 2026 10:53
Instead of monkeypatching the compiler, just check that the
compiler (whichever it is) does the right thing for its
INVOKES_LINKER setting.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Use a name that can be applied to rustc as well (because
RUSTFLAGS need not be added to rust_link_args and in fact
it breaks).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Also add a test which is a copy of basic with RUSTFLAGS set.

Test case by tytan652 <tytan652@tytanium.xyz>.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant