Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dep-info rmeta path is wrong #68839

Closed
ehuss opened this issue Feb 5, 2020 · 5 comments · Fixed by #114750
Closed

dep-info rmeta path is wrong #68839

ehuss opened this issue Feb 5, 2020 · 5 comments · Fixed by #114750
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 5, 2020

The path to the rmeta file in the dep-info file is wrong. It is missing the lib prefix.

rustc --emit=dep-info,metadata --crate-type lib foo.rs

foo.d will contain foo.rmeta: foo.rs, but I think it should be libfoo.rmeta: foo.rs because the filename is libfoo.rmeta.

The crate type doesn't matter. A "bin" type will also emit foo.rmeta, but bin types (confusingly) also use libfoo.rmeta.

(This doesn't really affect Cargo, as it ignores these filenames.)

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2020
@contrun
Copy link
Contributor

contrun commented Mar 11, 2020

Can you please elaborate on why this does not affect cargo and how cargo set the output file name?

It seems the crate type is parsed from

pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
let mut crate_types: Vec<CrateType> = Vec::new();
for unparsed_crate_type in &list_list {
for part in unparsed_crate_type.split(',') {
let new_part = match part {
"lib" => default_lib_output(),
"rlib" => CrateType::Rlib,
"staticlib" => CrateType::Staticlib,
"dylib" => CrateType::Dylib,
"cdylib" => CrateType::Cdylib,
"bin" => CrateType::Executable,
"proc-macro" => CrateType::ProcMacro,
_ => return Err(format!("unknown crate type: `{}`", part)),
};
if !crate_types.contains(&new_part) {
crate_types.push(new_part)
}
}
}
Ok(crate_types)
}

It is a vector. I am not sure how to determine whether I need to add the prefix lib or not.

@ehuss
Copy link
Contributor Author

ehuss commented Mar 11, 2020

I'm not sure I understand the relevance of the note about parsing crate types.

This is where Cargo parses the dep-info file. It only looks at the first line, and ignores the value before the :.

You can look at #49289 to start to investigate why binaries emit a filename with the lib prefix. That PR is what added rmeta output for binaries (the rmeta file is empty, it only exists to signal to Cargo that the compilation finished). I believe this is where the rmeta filename is determined. The dep-info filenames are computed around here. Somehow the two are out of sync.

@TheDreadedAndy
Copy link

According to the documentation for --emit, the default filename for an rmeta file should be CRATE_NAME.rmeta. That would suggest that the actual problem is the file name itself, which I believe is set here. Changing that would likely be breaking for anyone who doesn't use Cargo, though.

A workaround for this problem is to specify the output path for the metadata file. e.g. --emit=metadata=path/to/libfoo.rmeta. The dep-info is generated correctly when that is done.

@ehuss
Copy link
Contributor Author

ehuss commented Mar 20, 2022

Oh, looks like the --emit docs are wrong. The rmeta file needs to start with lib to work with crate discovery, and to match the .rlib naming convention. I posted #95131 with a fix for the docs.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 20, 2022
Fix docs for default rmeta filename.

The docs for the default filename for `--emit=metadata` was wrong, it was missing the `lib` prefix.  The current implementation for that default is [here](https://github.com/rust-lang/rust/blob/f2661cfe341f88bea919daf52a07015dceaf7a6a/compiler/rustc_session/src/output.rs#L140).  Perhaps somewhat confusing, but `lib` is used for all crate types.

cc rust-lang#68839 (comment)
@Enselic
Copy link
Member

Enselic commented Aug 12, 2023

PR with fix: #114750

@bors bors closed this as completed in 8ed1d4a Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants