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
// Matches:
// name=path
// modifiers:name=path
let caps = static_regex!(r"^(?:(?P<modifiers>[^=]*?):)?(?P<name>[^=]*)=(?P<path>.*)$")
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I believe ?P<name> is just a longer form of ?<name>, and in that case we might as well use the shorter syntax without P.

(I notice that compiletest currently uses an inconsistent mixture of both styles.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I wondered if I should have P or not and noticed it was used in other places, so I kept it. I don't mind removing it though. Done.

// modifiers:name=path
let caps = static_regex!(r"^(?:(?P<modifiers>[^=]*?):)?(?P<name>[^=]*)=(?P<path>.*)$")
.captures(r.trim())
.unwrap_or_else(|| panic!("missing aux-crate value (e.g. log=log.rs)"));
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly, this error is shown if the value couldn't be parsed, so it should probably say “couldn't parse aux-crate value” and maybe include the value string, too.

Copy link
Member Author

@Enselic Enselic Jan 24, 2026

Choose a reason for hiding this comment

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

I intentionally didn't want to make this PR change behavior or error message, but I agree it is nicer to print what value that couldn't be parse, so I added that.

Comment on lines 90 to 98
let name = caps.name("name").map(|m| m.as_str().to_string()).unwrap_or_default();
let path = caps.name("path").map(|m| m.as_str().to_string()).unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

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

If the regex match succeeded, then name and path should always be present, so these can probably just be caps["name"].to_owned() or similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I don't think there is something like to_owned()? .name("name") returns an Option<Match>. If there is a simpler way to write this I wasn't able to figure it out.

Copy link
Member

Choose a reason for hiding this comment

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

regex::Captures implements Index<&str>, so instead of writing caps.get("name") it should be possible to write caps["name"] to get a &str (panicking if that named group didn't match), and then convert that to String.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh... Thanks. Done.

@Zalathar
Copy link
Member

Could you please also add at least one unit test for parse_aux_crate with extern modifiers, just to double-check that the modifiers are being parsed as we expect.

(Doesn't need to be super thorough; I just want some explicit assurance that the modifiers don't accidentally end up in the name after all.)

@Zalathar
Copy link
Member

Should be good to go after this last round of nitpicks.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2026
@Enselic
Copy link
Member Author

Enselic commented Jan 24, 2026

Could you please also add at least one unit test for parse_aux_crate with extern modifiers, just to double-check that the modifiers are being parsed as we expect.

Sure, no problem. Done.

Note however that you can be confident that parsing works even without the new tests, because if e.g. modifiers failed to parse properly, a lot of tests that depend on them would fail (like tests/ui/privacy/pub-priv-dep/pub-priv1.rs just to give one example).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 24, 2026
@Zalathar
Copy link
Member

Thanks.

@bors r+

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 24, 2026
compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers

With `-Zunstable-options` it is possible to pass options to `--extern`. See here for an exhaustive list of possible options:
https://github.com/rust-lang/rust/blob/b5dd72d2921500c9d9e15f074e1d831adcaa3dee/compiler/rustc_session/src/config.rs#L2356-L2367

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 rust-lang#151258 into smaller pieces.

r? @Zalathar
rust-bors bot pushed a commit that referenced this pull request Jan 24, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #151346 (add `simd_splat` intrinsic)
 - #151353 (compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers)
 - #151571 (Fix cstring-merging test for Hexagon target)

r? @ghost
@JonathanBrouwer
Copy link
Contributor

@bors r-
#151586 (comment)

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 24, 2026

📋 Only unclosed PRs can be unapproved.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 24, 2026
@JonathanBrouwer
Copy link
Contributor

(Whoops did not mean to close this)
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 24, 2026
compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers

With `-Zunstable-options` it is possible to pass options to `--extern`. See here for an exhaustive list of possible options:
https://github.com/rust-lang/rust/blob/b5dd72d2921500c9d9e15f074e1d831adcaa3dee/compiler/rustc_session/src/config.rs#L2356-L2367

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 rust-lang#151258 into smaller pieces.

r? @Zalathar
…modifiers

To make it clearer what happens. In other words, do not silently keep
modifiers as part of `AuxCrate::name`.
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 24, 2026

⚠️ A new commit 6f767b686044e59e37c31b17a8f00cac7092fa7c was pushed to the branch, the PR will need to be re-approved.

@rust-bors rust-bors bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 24, 2026
@Enselic
Copy link
Member Author

Enselic commented Jan 24, 2026

Trivial fix.

@bors r=Zalathar

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 24, 2026

📌 Commit 6f767b6 has been approved by Zalathar

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 24, 2026
compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers

With `-Zunstable-options` it is possible to pass options to `--extern`. See here for an exhaustive list of possible options:
https://github.com/rust-lang/rust/blob/b5dd72d2921500c9d9e15f074e1d831adcaa3dee/compiler/rustc_session/src/config.rs#L2356-L2367

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 rust-lang#151258 into smaller pieces.

r? @Zalathar
rust-bors bot pushed a commit that referenced this pull request Jan 24, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #151346 (add `simd_splat` intrinsic)
 - #151353 (compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers)
 - #151571 (Fix cstring-merging test for Hexagon target)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 24, 2026
Rollup of 11 pull requests

Successful merges:

 - #149962 (Promote powerpc64-unknown-linux-musl to tier 2 with host tools)
 - #150138 (Add new Tier 3 targets for ARMv6)
 - #150905 (Fix(lib/win/net): Remove hostname support under Win7)
 - #151094 (remote-test-server: Fix compilation on UEFI targets)
 - #151346 (add `simd_splat` intrinsic)
 - #151353 (compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers)
 - #151538 (std: `sleep_until` on Motor and VEX)
 - #151098 (Add Korean translation to Rust By Example)
 - #151157 (Extend build-manifest local test guide)
 - #151403 (std: use 64-bit `clock_nanosleep` on GNU/Linux if available)
 - #151571 (Fix cstring-merging test for Hexagon target)
@rust-bors rust-bors bot merged commit 0a1b437 into rust-lang:main Jan 25, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 25, 2026
rust-timer added a commit that referenced this pull request Jan 25, 2026
Rollup merge of #151353 - Enselic:aux-crate-opts, r=Zalathar

compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers

With `-Zunstable-options` it is possible to pass options to `--extern`. See here for an exhaustive list of possible options:
https://github.com/rust-lang/rust/blob/b5dd72d2921500c9d9e15f074e1d831adcaa3dee/compiler/rustc_session/src/config.rs#L2356-L2367

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
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 25, 2026
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#149962 (Promote powerpc64-unknown-linux-musl to tier 2 with host tools)
 - rust-lang/rust#150138 (Add new Tier 3 targets for ARMv6)
 - rust-lang/rust#150905 (Fix(lib/win/net): Remove hostname support under Win7)
 - rust-lang/rust#151094 (remote-test-server: Fix compilation on UEFI targets)
 - rust-lang/rust#151346 (add `simd_splat` intrinsic)
 - rust-lang/rust#151353 (compiletest: Make `aux-crate` directive explicitly handle `--extern` modifiers)
 - rust-lang/rust#151538 (std: `sleep_until` on Motor and VEX)
 - rust-lang/rust#151098 (Add Korean translation to Rust By Example)
 - rust-lang/rust#151157 (Extend build-manifest local test guide)
 - rust-lang/rust#151403 (std: use 64-bit `clock_nanosleep` on GNU/Linux if available)
 - rust-lang/rust#151571 (Fix cstring-merging test for Hexagon target)
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

4 participants