Skip to content

Conversation

@Enselic
Copy link
Member

@Enselic Enselic commented Jan 19, 2026

With -Zunstable-options it is possible to pass options to --extern. See here for an exhaustive list of possible options:

"priv" => is_private_dep = true,
"noprelude" => {
if let ExternLocation::ExactPaths(_) = &entry.location {
add_prelude = false;
} else {
early_dcx.early_fatal(
"the `noprelude` --extern option requires a file path",
);
}
}
"nounused" => nounused_dep = true,
"force" => force = true,

Using these options works with the aux-crate directive, but only because the options pretend to be part of the name. Make it clearer what aux-crate supports by explicitly handling --extern options.

This PR is step one of splitting up #151258 into smaller pieces.

r? @Zalathar

@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2026

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 19, 2026
@Zalathar
Copy link
Member

Zalathar commented Jan 19, 2026

Ah, so we're talking about these?

“Options” seems like a needlessly confusing term to have been used on that unstable-book page; calling them “modifiers” (as the tracking issue does) is a lot clearer.

Comment on lines 13 to 14
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude`.
pub extern_opts: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

  • I think we should ignore the unstable book and the compiler source, and call these “extern modifiers” instead.
  • This field comment really needs to give a brief explanation of what extern modifiers actually are, perhaps with a link to the tracking issue.

Copy link
Member Author

@Enselic Enselic Jan 19, 2026

Choose a reason for hiding this comment

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

I agree "extern modifiers" is a better name than "extern options". I added some more info and linked to the tracking issue. I don't think we should give too many details though since we don't want that comment to become outdated soon.

I also added references this functionality in the rustc-dev-guide.

Comment on lines 80 to 86
let opts_and_name = parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string();
let path = parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string();
let (opts, name) = match opts_and_name.split_once(':') {
None => (None, opts_and_name),
Some((opts, name)) => (Some(opts.to_string()), name.to_string()),
};
AuxCrate { extern_opts: opts, name, path }
Copy link
Member

Choose a reason for hiding this comment

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

This parsing step is getting complex enough that a regex might be an improvement. Seems worth a try at least.

Copy link
Member Author

@Enselic Enselic Jan 19, 2026

Choose a reason for hiding this comment

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

I tried porting it to a regex but didn't think it ended up being easier to understand, so I kept it as is. I hope that's OK. The diff is small at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

I spent some more time on it and found a way to use a regex that I like. Hopefully you'll like it too.

@Zalathar
Copy link
Member

We should also mention --extern modifiers in the dev-guide docs for //@ aux-crate, precisely because they're so obscure that it's difficult for an unfamiliar reader (e.g. me yesterday) to figure out what they even are.

@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2026

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol, @tshepang

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Jan 19, 2026
@Enselic Enselic changed the title compiletest: Make aux-crate directive explicitly handle --extern options compiletest: Make aux-crate directive explicitly handle --extern modifiers Jan 19, 2026
…modifiers

To make it clearer what happens. In other words, do not silently keep
modifiers as part of `AuxCrate::name`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants