Skip to content

Commit c26220f

Browse files
authored
Fix: artifact dependency path needs to be accessed using env::var_os instead of env! (#296)
Artifact dependencies are available through the `env!` macro only in binaries/libraries. In build scripts, the env variable is set at runtime instead.
1 parent 669e3c0 commit c26220f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ To combine your kernel with a bootloader and create a bootable disk image, follo
6161
bindeps = true
6262
```
6363
Alternatively, you can use [`std::process::Command`](https://doc.rust-lang.org/stable/std/process/struct.Command.html) to invoke the build command of your kernel in the `build.rs` script.
64-
- Obtain the path to the kernel executable. When using an artifact dependency, you can retrieve this path using `env!("CARGO_BIN_FILE_MY_KERNEL_my-kernel")`
64+
- Obtain the path to the kernel executable. When using an artifact dependency, you can retrieve this path using `std::env::var_os("CARGO_BIN_FILE_MY_KERNEL_my-kernel")`
6565
- Use `bootloader::UefiBoot` and/or `bootloader::BiosBoot` to create a bootable disk image with your kernel.
6666
- Do something with the bootable disk images in your `main.rs` function. For example, run them with QEMU.
6767

docs/create-disk-image.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ members = ["kernel"]
4040

4141
fn main() {
4242
// set by cargo, build scripts should use this directory for output files
43-
let out_dir = env::var_os("OUT_DIR").unwrap();
43+
let out_dir = std::env::var_os("OUT_DIR").unwrap();
4444
// set by cargo's artifact dependency feature, see
4545
// https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies
46-
let kernel = env!("CARGO_BIN_FILE_KERNEL_kernel");
46+
let kernel = std::env::var_os("CARGO_BIN_FILE_KERNEL_kernel");
4747

4848
// create an UEFI disk image (optional)
4949
let uefi_path = out_dir.join("uefi.img");

0 commit comments

Comments
 (0)