diff --git a/src/tools/compiletest/src/directives/auxiliary.rs b/src/tools/compiletest/src/directives/auxiliary.rs index 1b72931949c54..dd82f14dcffa5 100644 --- a/src/tools/compiletest/src/directives/auxiliary.rs +++ b/src/tools/compiletest/src/directives/auxiliary.rs @@ -10,13 +10,24 @@ use crate::directives::DirectiveLine; /// The value of an `aux-crate` directive. #[derive(Clone, Debug, Default)] pub struct AuxCrate { + /// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude`. + pub extern_opts: Option, /// With `aux-crate: foo=bar.rs` this will be `foo`. - /// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude:foo`. + /// With `aux-crate: noprelude:foo=bar.rs` this will be `foo`. pub name: String, /// With `aux-crate: foo=bar.rs` this will be `bar.rs`. pub path: String, } +/// The value of a `proc-macro` directive. +#[derive(Clone, Debug, Default)] +pub(crate) struct ProcMacro { + /// With `proc-macro: bar.rs` this will be `bar.rs`. + pub path: String, + /// With `proc-macro: noprelude:bar.rs` this will be `noprelude`. + pub extern_opts: Option, +} + /// Properties parsed from `aux-*` test directives. #[derive(Clone, Debug, Default)] pub(crate) struct AuxProps { @@ -29,7 +40,7 @@ pub(crate) struct AuxProps { /// to build and pass with the `--extern` flag. pub(crate) crates: Vec, /// Same as `builds`, but for proc-macros. - pub(crate) proc_macros: Vec, + pub(crate) proc_macros: Vec, /// Similar to `builds`, but also uses the resulting dylib as a /// `-Zcodegen-backend` when compiling the test file. pub(crate) codegen_backend: Option, @@ -45,7 +56,7 @@ impl AuxProps { .chain(builds.iter().map(String::as_str)) .chain(bins.iter().map(String::as_str)) .chain(crates.iter().map(|c| c.path.as_str())) - .chain(proc_macros.iter().map(String::as_str)) + .chain(proc_macros.iter().map(|p| p.path.as_str())) .chain(codegen_backend.iter().map(String::as_str)) } } @@ -66,8 +77,8 @@ pub(super) fn parse_and_update_aux( config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string()); config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string()); config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate); - config - .push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, |r| r.trim().to_string()); + config.push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, parse_proc_macro); + if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) { aux.codegen_backend = Some(r.trim().to_owned()); } @@ -75,8 +86,22 @@ pub(super) fn parse_and_update_aux( fn parse_aux_crate(r: String) -> AuxCrate { let mut parts = r.trim().splitn(2, '='); - AuxCrate { - name: parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(), - path: parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(), - } + 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 } +} + +fn parse_proc_macro(r: String) -> ProcMacro { + let r = r.trim(); + + let (opts, path): (Option, String) = match r.split_once(':') { + None => (None, r.to_string()), + Some((opts, name)) => (Some(opts.to_string()), name.to_string()), + }; + + ProcMacro { path: path.to_string(), extern_opts: opts } } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 901ce8421ebf4..981f609bb6c16 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1277,23 +1277,36 @@ impl<'test> TestCx<'test> { .replace('-', "_") }; - let add_extern = - |rustc: &mut Command, aux_name: &str, aux_path: &str, aux_type: AuxType| { - let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type); - if let Some(lib_name) = lib_name { - rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir, lib_name)); - } - }; + let add_extern = |rustc: &mut Command, + extern_opts: Option<&str>, + aux_name: &str, + aux_path: &str, + aux_type: AuxType| { + let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type); + if let Some(lib_name) = lib_name { + let opts_and_name = match extern_opts { + Some(opts) => format!("{opts}:{aux_name}"), + None => aux_name.to_string(), + }; + rustc.arg("--extern").arg(format!("{opts_and_name}={aux_dir}/{lib_name}")); + } + }; - for AuxCrate { name, path } in &self.props.aux.crates { + for AuxCrate { extern_opts, name, path } in &self.props.aux.crates { let aux_type = self.build_auxiliary(&path, &aux_dir, None); - add_extern(rustc, name, path, aux_type); + add_extern(rustc, extern_opts.as_deref(), name, path, aux_type); } for proc_macro in &self.props.aux.proc_macros { - self.build_auxiliary(proc_macro, &aux_dir, Some(AuxType::ProcMacro)); - let crate_name = path_to_crate_name(proc_macro); - add_extern(rustc, &crate_name, proc_macro, AuxType::ProcMacro); + self.build_auxiliary(&proc_macro.path, &aux_dir, Some(AuxType::ProcMacro)); + let crate_name = path_to_crate_name(&proc_macro.path); + add_extern( + rustc, + proc_macro.extern_opts.as_deref(), + &crate_name, + &proc_macro.path, + AuxType::ProcMacro, + ); } // Build any `//@ aux-codegen-backend`, and pass the resulting library diff --git a/tests/ui/privacy/pub-priv-dep/auxiliary/pm.rs b/tests/ui/privacy/pub-priv-dep/auxiliary/pm.rs index 9e2aa898afe8d..d45f2639d182f 100644 --- a/tests/ui/privacy/pub-priv-dep/auxiliary/pm.rs +++ b/tests/ui/privacy/pub-priv-dep/auxiliary/pm.rs @@ -1,8 +1,3 @@ -//@ force-host -//@ no-prefer-dynamic - -#![crate_type = "proc-macro"] - extern crate proc_macro; use proc_macro::TokenStream; diff --git a/tests/ui/privacy/pub-priv-dep/pub-priv1.rs b/tests/ui/privacy/pub-priv-dep/pub-priv1.rs index eae0f9756a10e..09ad59582d845 100644 --- a/tests/ui/privacy/pub-priv-dep/pub-priv1.rs +++ b/tests/ui/privacy/pub-priv-dep/pub-priv1.rs @@ -1,6 +1,6 @@ //@ aux-crate:priv:priv_dep=priv_dep.rs //@ aux-build:pub_dep.rs -//@ aux-crate:priv:pm=pm.rs +//@ proc-macro:priv:pm.rs //@ compile-flags: -Zunstable-options // Basic behavior check of exported_private_dependencies from either a public