fix: Consider all produced artifacts for proc-macro dylib search

This commit is contained in:
Lukas Wirth 2025-07-27 23:21:42 +02:00
parent afee0710e1
commit 6b09fbf881
4 changed files with 15 additions and 21 deletions

View file

@ -31,7 +31,7 @@ pub enum ProcMacroLoadingError {
Disabled, Disabled,
FailedToBuild, FailedToBuild,
ExpectedProcMacroArtifact, ExpectedProcMacroArtifact,
MissingDylibPath(Box<[String]>), MissingDylibPath,
NotYetBuilt, NotYetBuilt,
NoProcMacros, NoProcMacros,
ProcMacroSrvError(Box<str>), ProcMacroSrvError(Box<str>),
@ -42,7 +42,7 @@ impl ProcMacroLoadingError {
ProcMacroLoadingError::Disabled | ProcMacroLoadingError::NotYetBuilt => false, ProcMacroLoadingError::Disabled | ProcMacroLoadingError::NotYetBuilt => false,
ProcMacroLoadingError::ExpectedProcMacroArtifact ProcMacroLoadingError::ExpectedProcMacroArtifact
| ProcMacroLoadingError::FailedToBuild | ProcMacroLoadingError::FailedToBuild
| ProcMacroLoadingError::MissingDylibPath(_) | ProcMacroLoadingError::MissingDylibPath
| ProcMacroLoadingError::NoProcMacros | ProcMacroLoadingError::NoProcMacros
| ProcMacroLoadingError::ProcMacroSrvError(_) => true, | ProcMacroLoadingError::ProcMacroSrvError(_) => true,
} }
@ -58,19 +58,12 @@ impl fmt::Display for ProcMacroLoadingError {
} }
ProcMacroLoadingError::Disabled => write!(f, "proc-macro expansion is disabled"), ProcMacroLoadingError::Disabled => write!(f, "proc-macro expansion is disabled"),
ProcMacroLoadingError::FailedToBuild => write!(f, "proc-macro failed to build"), ProcMacroLoadingError::FailedToBuild => write!(f, "proc-macro failed to build"),
ProcMacroLoadingError::MissingDylibPath(candidates) if candidates.is_empty() => { ProcMacroLoadingError::MissingDylibPath => {
write!( write!(
f, f,
"proc-macro crate built but the dylib path is missing, this indicates a problem with your build system." "proc-macro crate built but the dylib path is missing, this indicates a problem with your build system."
) )
} }
ProcMacroLoadingError::MissingDylibPath(candidates) => {
write!(
f,
"proc-macro crate built but the dylib path is missing, this indicates a problem with your build system. Candidates not considered due to not having a dynamic library extension: {}",
candidates.join(", ")
)
}
ProcMacroLoadingError::NotYetBuilt => write!(f, "proc-macro not yet built"), ProcMacroLoadingError::NotYetBuilt => write!(f, "proc-macro not yet built"),
ProcMacroLoadingError::NoProcMacros => { ProcMacroLoadingError::NoProcMacros => {
write!(f, "proc macro library has no proc macros") write!(f, "proc macro library has no proc macros")

View file

@ -35,7 +35,7 @@ pub struct WorkspaceBuildScripts {
#[derive(Debug, Clone, Default, PartialEq, Eq)] #[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum ProcMacroDylibPath { pub enum ProcMacroDylibPath {
Path(AbsPathBuf), Path(AbsPathBuf),
DylibNotFound(Box<[Utf8PathBuf]>), DylibNotFound,
NotProcMacro, NotProcMacro,
#[default] #[default]
NotBuilt, NotBuilt,
@ -251,7 +251,7 @@ impl WorkspaceBuildScripts {
}) { }) {
match proc_macro_dylibs.iter().find(|(name, _)| *name == package.name) { match proc_macro_dylibs.iter().find(|(name, _)| *name == package.name) {
Some((_, path)) => ProcMacroDylibPath::Path(path.clone()), Some((_, path)) => ProcMacroDylibPath::Path(path.clone()),
_ => ProcMacroDylibPath::DylibNotFound(Box::default()), _ => ProcMacroDylibPath::DylibNotFound,
} }
} else { } else {
ProcMacroDylibPath::NotProcMacro ProcMacroDylibPath::NotProcMacro
@ -386,7 +386,11 @@ impl WorkspaceBuildScripts {
if data.proc_macro_dylib_path == ProcMacroDylibPath::NotBuilt { if data.proc_macro_dylib_path == ProcMacroDylibPath::NotBuilt {
data.proc_macro_dylib_path = ProcMacroDylibPath::NotProcMacro; data.proc_macro_dylib_path = ProcMacroDylibPath::NotProcMacro;
} }
if message.target.kind.contains(&cargo_metadata::TargetKind::ProcMacro) if !matches!(data.proc_macro_dylib_path, ProcMacroDylibPath::Path(_))
&& message
.target
.kind
.contains(&cargo_metadata::TargetKind::ProcMacro)
{ {
data.proc_macro_dylib_path = data.proc_macro_dylib_path =
match message.filenames.iter().find(|file| is_dylib(file)) { match message.filenames.iter().find(|file| is_dylib(file)) {
@ -394,9 +398,7 @@ impl WorkspaceBuildScripts {
let filename = AbsPath::assert(filename); let filename = AbsPath::assert(filename);
ProcMacroDylibPath::Path(filename.to_owned()) ProcMacroDylibPath::Path(filename.to_owned())
} }
None => ProcMacroDylibPath::DylibNotFound( None => ProcMacroDylibPath::DylibNotFound,
message.filenames.clone().into_boxed_slice(),
),
}; };
} }
}); });

View file

@ -65,6 +65,7 @@ fn rustc_print_cfg(
let (sysroot, current_dir) = match config { let (sysroot, current_dir) = match config {
QueryConfig::Cargo(sysroot, cargo_toml, _) => { QueryConfig::Cargo(sysroot, cargo_toml, _) => {
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env); let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env);
cmd.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS); cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS);
if let Some(target) = target { if let Some(target) = target {
cmd.args(["--target", target]); cmd.args(["--target", target]);

View file

@ -1639,7 +1639,7 @@ fn add_target_crate_root(
match proc_macro_dylib_path { match proc_macro_dylib_path {
ProcMacroDylibPath::Path(path) => Ok((cargo_name.to_owned(), path.clone())), ProcMacroDylibPath::Path(path) => Ok((cargo_name.to_owned(), path.clone())),
ProcMacroDylibPath::NotBuilt => Err(ProcMacroLoadingError::NotYetBuilt), ProcMacroDylibPath::NotBuilt => Err(ProcMacroLoadingError::NotYetBuilt),
ProcMacroDylibPath::NotProcMacro | ProcMacroDylibPath::DylibNotFound(_) ProcMacroDylibPath::NotProcMacro | ProcMacroDylibPath::DylibNotFound
if has_errors => if has_errors =>
{ {
Err(ProcMacroLoadingError::FailedToBuild) Err(ProcMacroLoadingError::FailedToBuild)
@ -1647,10 +1647,8 @@ fn add_target_crate_root(
ProcMacroDylibPath::NotProcMacro => { ProcMacroDylibPath::NotProcMacro => {
Err(ProcMacroLoadingError::ExpectedProcMacroArtifact) Err(ProcMacroLoadingError::ExpectedProcMacroArtifact)
} }
ProcMacroDylibPath::DylibNotFound(candidates) => { ProcMacroDylibPath::DylibNotFound => {
Err(ProcMacroLoadingError::MissingDylibPath( Err(ProcMacroLoadingError::MissingDylibPath)
candidates.iter().map(ToString::to_string).collect(),
))
} }
} }
} }