Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,11 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult

if is_primary {
base.env("CARGO_PRIMARY_PACKAGE", "1");
let file_list = std::env::join_paths(build_runner.sbom_output_files(unit)?)?;
base.env("CARGO_SBOM_PATH", file_list);
let file_list = build_runner.sbom_output_files(unit)?;
if !file_list.is_empty() {
let file_list = std::env::join_paths(file_list)?;
base.env("CARGO_SBOM_PATH", file_list);
}
}

if unit.target.is_test() || unit.target.is_bench() {
Expand Down
23 changes: 15 additions & 8 deletions tests/testsuite/sbom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ fn append_sbom_suffix(link: &PathBuf) -> PathBuf {
fn warn_without_passing_unstable_flag() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", r#"fn main() {}"#)
.file(
"src/main.rs",
r#"fn main() {
eprintln!("{:?}", option_env!("CARGO_SBOM_PATH"));
}"#,
)
.build();

p.cargo("build")
p.cargo("run")
.env("CARGO_BUILD_SBOM", "true")
.masquerade_as_nightly_cargo(&["sbom"])
.with_stderr_data(
"\
[WARNING] ignoring 'sbom' config, pass `-Zsbom` to enable it\n\
[COMPILING] foo v0.5.0 ([..])\n\
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]\n",
)
.with_stderr_data(snapbox::str![[r#"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel like we should move str! to prelude

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for APIs, I tend to focus preludes on traits, rather than concrete items like macros, functions, etc. This being an internal prelude does make it a little different.

[WARNING] ignoring 'sbom' config, pass `-Zsbom` to enable it
[COMPILING] foo v0.5.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`
None

"#]])
.run();

let file = append_sbom_suffix(&p.bin("foo"));
Expand Down