Skip to content

Commit 41c6301

Browse files
committed
compiletest: Make aux-crate directive explicitly handle --extern modifiers
To make it clearer what happens. In other words, do not silently keep modifiers as part of `AuxCrate::name`.
1 parent 9aaa581 commit 41c6301

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

src/tools/compiletest/src/directives/auxiliary.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ use crate::directives::DirectiveLine;
1010
/// The value of an `aux-crate` directive.
1111
#[derive(Clone, Debug, Default)]
1212
pub struct AuxCrate {
13+
/// Contains `--extern` modifiers, if any. See the tracking issue for more
14+
/// info: https://github.com/rust-lang/rust/issues/98405
15+
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude`.
16+
pub extern_modifiers: Option<String>,
1317
/// With `aux-crate: foo=bar.rs` this will be `foo`.
14-
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude:foo`.
18+
/// With `aux-crate: noprelude:foo=bar.rs` this will be `foo`.
1519
pub name: String,
1620
/// With `aux-crate: foo=bar.rs` this will be `bar.rs`.
1721
pub path: String,
@@ -75,8 +79,12 @@ pub(super) fn parse_and_update_aux(
7579

7680
fn parse_aux_crate(r: String) -> AuxCrate {
7781
let mut parts = r.trim().splitn(2, '=');
78-
AuxCrate {
79-
name: parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
80-
path: parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
81-
}
82+
let modifiers_and_name =
83+
parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string();
84+
let path = parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string();
85+
let (modifiers, name) = match modifiers_and_name.split_once(':') {
86+
None => (None, modifiers_and_name),
87+
Some((opts, name)) => (Some(opts.to_string()), name.to_string()),
88+
};
89+
AuxCrate { extern_modifiers: modifiers, name, path }
8290
}

src/tools/compiletest/src/runtest.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,23 +1277,36 @@ impl<'test> TestCx<'test> {
12771277
.replace('-', "_")
12781278
};
12791279

1280-
let add_extern =
1281-
|rustc: &mut Command, aux_name: &str, aux_path: &str, aux_type: AuxType| {
1282-
let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type);
1283-
if let Some(lib_name) = lib_name {
1284-
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir, lib_name));
1285-
}
1286-
};
1280+
let add_extern = |rustc: &mut Command,
1281+
extern_modifiers: Option<&str>,
1282+
aux_name: &str,
1283+
aux_path: &str,
1284+
aux_type: AuxType| {
1285+
let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type);
1286+
if let Some(lib_name) = lib_name {
1287+
let modifiers_and_name = match extern_modifiers {
1288+
Some(modifiers) => format!("{modifiers}:{aux_name}"),
1289+
None => aux_name.to_string(),
1290+
};
1291+
rustc.arg("--extern").arg(format!("{modifiers_and_name}={aux_dir}/{lib_name}"));
1292+
}
1293+
};
12871294

1288-
for AuxCrate { name, path } in &self.props.aux.crates {
1295+
for AuxCrate { extern_modifiers, name, path } in &self.props.aux.crates {
12891296
let aux_type = self.build_auxiliary(&path, &aux_dir, None);
1290-
add_extern(rustc, name, path, aux_type);
1297+
add_extern(rustc, extern_modifiers.as_deref(), name, path, aux_type);
12911298
}
12921299

12931300
for proc_macro in &self.props.aux.proc_macros {
12941301
self.build_auxiliary(proc_macro, &aux_dir, Some(AuxType::ProcMacro));
12951302
let crate_name = path_to_crate_name(proc_macro);
1296-
add_extern(rustc, &crate_name, proc_macro, AuxType::ProcMacro);
1303+
add_extern(
1304+
rustc,
1305+
None, // `extern_modifiers`
1306+
&crate_name,
1307+
proc_macro,
1308+
AuxType::ProcMacro,
1309+
);
12971310
}
12981311

12991312
// Build any `//@ aux-codegen-backend`, and pass the resulting library

0 commit comments

Comments
 (0)