Skip to content

Commit e835591

Browse files
committed
Use CARGO_MANIFEST_DIR variable for bootimage runner
For doctests it's not possible to derive the manifest path from the executable path and the cargo metadata since doctests live under temp and all use the same name ('rust-out'). Fortunately, cargo sets a `CARGO_MANIFEST_DIR` environment variable for runner executables that points to the manifest path of the executable (which can be different from the root manifest path for workpace projects.)
1 parent 65a03a8 commit e835591

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,17 @@ pub(crate) fn runner(args: RunnerArgs) -> Result<i32> {
8585
args.executable.display(),
8686
)
8787
})?;
88+
89+
// Cargo sets a CARGO_MANIFEST_DIR environment variable for all runner
90+
// executables. This variable contains the path to the Cargo.toml of the
91+
// crate that the executable belongs to (i.e. not the project root
92+
// manifest for workspace projects)
93+
let manifest_dir = env::var("CARGO_MANIFEST_DIR")
94+
.context("Failed to read CARGO_MANIFEST_DIR environment variable")?;
95+
let kernel_manifest_path = Path::new(&manifest_dir).join("Cargo.toml");
96+
8897
builder.create_bootimage(
89-
bin_name,
98+
&kernel_manifest_path,
9099
&executable_canonicalized,
91100
&output_bin_path,
92101
args.quiet,

0 commit comments

Comments
 (0)