1
- use anyhow:: { anyhow, Result } ;
1
+ use anyhow:: { anyhow, Context , Result } ;
2
2
use bootimage:: {
3
3
args:: { BuildArgs , BuildCommand } ,
4
4
builder:: Builder ,
@@ -60,8 +60,23 @@ fn build(args: BuildArgs) -> Result<()> {
60
60
. to_str ( )
61
61
. ok_or_else ( || anyhow ! ( "executable file stem not valid utf8" ) ) ?;
62
62
63
+ // We don't have access to a CARGO_MANIFEST_DIR environment variable
64
+ // here because `cargo bootimage` is started directly by the user. We
65
+ // therefore have to find out the path to the Cargo.toml of the
66
+ // executables ourselves. For workspace projects, this can be a
67
+ // different Cargo.toml than the Cargo.toml in the current directory.
68
+ //
69
+ // To retrieve the correct Cargo.toml path, we look for the binary name
70
+ // in the `cargo metadata` output and then get the manifest path from
71
+ // the corresponding package.
72
+ let kernel_package = builder
73
+ . kernel_package_for_bin ( bin_name)
74
+ . context ( "Failed to run cargo metadata to find out kernel manifest path" ) ?
75
+ . ok_or_else ( || anyhow ! ( "Failed to find kernel binary in cargo metadata output" ) ) ?;
76
+ let kernel_manifest_path = & kernel_package. manifest_path . to_owned ( ) ;
77
+
63
78
let bootimage_path = out_dir. join ( format ! ( "bootimage-{}.bin" , bin_name) ) ;
64
- builder. create_bootimage ( bin_name , & executable, & bootimage_path, quiet) ?;
79
+ builder. create_bootimage ( kernel_manifest_path , & executable, & bootimage_path, quiet) ?;
65
80
if !args. quiet ( ) {
66
81
println ! (
67
82
"Created bootimage for `{}` at `{}`" ,
0 commit comments