Skip to content
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

Change flag ordering #1403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Change flag ordering #1403

wants to merge 1 commit into from

Conversation

madsmtm
Copy link
Collaborator

@madsmtm madsmtm commented Feb 14, 2025

To allow flags set on the builder with Build::flag/Build::flag_if_supported to override other flags, and to allow CFLAGS to override all other flags.

Found while doing #1401.

Now the order of flags are as follows, with later flags overriding previous ones. I've also here shown who "controls" which flag, to make it clear why we want the ordering to be like this.

  1. Default flags
    • Controlled by cc-rs.
  2. rustc-inherited flags
    • Controlled by rustc.
  3. Builder flags
    • Controlled by the developer using cc-rs in e.g. their build.rs.
  4. Environment flags
    • Controlled by the end user.

To allow flags set on the builder to override other flags, and to allow
CFLAGS to override _all_ other flags.
Comment on lines +1926 to 1934
// Specify various flags that are not considered part of the default flags above.
// FIXME(madsmtm): Should these be considered part of the defaults? If no, why not?
if let Some(ref std) = self.std {
let separator = match cmd.family {
ToolFamily::Msvc { .. } => ':',
ToolFamily::Gnu | ToolFamily::Clang { .. } => '=',
};
cmd.push_cc_arg(format!("-std{}{}", separator, std).into());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is Builder flags, std version is specified in Builder

Comment on lines +29 to +30
// FIXME(madsmtm): Re-enable once `is_flag_supported` works in CI regardless of `target`.
// unsafe { std::env::set_var("CARGO_ENCODED_RUSTFLAGS", "-Cdwarf-version=5") };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there another issue/PR for this?

Comment on lines +50 to +56
.must_have_in_order("-static", "-Lbuilder-flag1")
.must_have_in_order("-Lbuilder-flag1", "-Lbuilder-flag2")
.must_have_in_order("-Lbuilder-flag2", "-Larbitrary1")
.must_have_in_order("-Larbitrary1", "-Larbitrary2")
.must_have_in_order("-Larbitrary1", "-Larbitrary2")
.must_have_in_order("-Larbitrary2", "-Larbitrary3")
.must_have_in_order("-Larbitrary3", "-Larbitrary4");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: maybe we could access .args directly?

pub args: Vec<String>,

Suggested change
.must_have_in_order("-static", "-Lbuilder-flag1")
.must_have_in_order("-Lbuilder-flag1", "-Lbuilder-flag2")
.must_have_in_order("-Lbuilder-flag2", "-Larbitrary1")
.must_have_in_order("-Larbitrary1", "-Larbitrary2")
.must_have_in_order("-Larbitrary1", "-Larbitrary2")
.must_have_in_order("-Larbitrary2", "-Larbitrary3")
.must_have_in_order("-Larbitrary3", "-Larbitrary4");
.args == [
"-static",
"-Lbuilder-flag1",
"-Lbuilder-flag2",
"-Larbitrary1",
"-Larbitrary2",
"-Larbitrary3",
"-Larbitrary4",
]

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.

2 participants