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

core/compiler: report executable paths for all binary crates #13605

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cargo/core/compiler/build_runner/mod.rs
Expand Up @@ -312,11 +312,13 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {

/// Returns the executable for the specified unit (if any).
pub fn get_executable(&mut self, unit: &Unit) -> CargoResult<Option<PathBuf>> {
let is_binary = unit.target.is_executable();
let crate_types = unit.target.rustc_crate_types();
let is_binary = crate_types.contains(&compiler::CrateType::Bin);
let is_test = unit.mode.is_any_test();
if !unit.mode.generates_executable() || !(is_binary || is_test) {
return Ok(None);
}

Ok(self
.outputs(unit)?
.iter()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build.rs
Expand Up @@ -4266,7 +4266,7 @@ fn compiler_json_error_format() {
"overflow_checks": true,
"test": false
},
"executable": null,
"executable": "[..]/build-script-build[EXE]",
"features": [],
"filenames": "{...}",
"fresh": $FRESH
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/metabuild.rs
Expand Up @@ -709,7 +709,7 @@ fn metabuild_json_artifact() {
.with_json_contains_unordered(
r#"
{
"executable": null,
"executable": "[..]/metabuild-foo[EXE]",
"features": [],
"filenames": "{...}",
"fresh": false,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/pkgid.rs
Expand Up @@ -318,7 +318,7 @@ fn pkgid_json_message_metadata_consistency() {
"profile": "{...}",
"features": [],
"filenames": "{...}",
"executable": null,
"executable": "[..]",
"fresh": false
}

Expand Down
34 changes: 34 additions & 0 deletions tests/testsuite/rustc.rs
Expand Up @@ -269,6 +269,40 @@ fn build_with_crate_types_for_foo() {
.run();
}

#[cargo_test]
fn build_lib_with_crate_type_bin() {
let p = project().file("src/lib.rs", "fn main() {}").build();

p.cargo("rustc -v --crate-type bin --message-format=json --jobs=1")
.with_json_contains_unordered(
r#"
{
"executable": "[..]/debug/foo[EXE]",
"features": [],
"filenames": "{...}",
"fresh": false,
"manifest_path": "[..]",
"package_id": "[..]",
"profile": "{...}",
"reason": "compiler-artifact",
"target": {
"crate_types": ["bin"],
"doc": true,
"doctest": false,
"edition": "2015",
"kind": ["bin"],
"name": "foo",
"src_path": "[..]",
"test": true
}
}

{"reason": "build-finished", "success": true}
"#,
)
.run();
}

#[cargo_test]
fn build_with_crate_type_to_example() {
let p = project()
Expand Down