Skip to content

Commit 34875f6

Browse files
committed
Fix Create Disk Image Example
The example code didn't compile. This patch fixes that.
1 parent c26220f commit 34875f6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/create-disk-image.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,28 @@ members = ["kernel"]
3838
```rust
3939
// build.rs
4040

41+
use std::path::Path;
42+
4143
fn main() {
4244
// set by cargo, build scripts should use this directory for output files
4345
let out_dir = std::env::var_os("OUT_DIR").unwrap();
46+
let out_dir_path = Path::new(&out_dir);
4447
// set by cargo's artifact dependency feature, see
4548
// https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies
46-
let kernel = std::env::var_os("CARGO_BIN_FILE_KERNEL_kernel");
49+
let kernel = std::env::var_os("CARGO_BIN_FILE_KERNEL_kernel").unwrap();
50+
let kernel_path = Path::new(&kernel);
4751

4852
// create an UEFI disk image (optional)
49-
let uefi_path = out_dir.join("uefi.img");
50-
bootloader::UefiBoot::new(&kernel).create_disk_image(uefi_path).unwrap();
53+
let uefi_path = out_dir_path.join("uefi.img");
54+
bootloader::UefiBoot::new(&kernel_path)
55+
.create_disk_image(&uefi_path)
56+
.unwrap();
5157

52-
// create a BIOS disk image (optional)
53-
let out_bios_path = out_dir.join("bios.img");
54-
bootloader::BiosBoot::new(&kernel).create_disk_image(uefi_path).unwrap();
58+
// create a BIOS disk image
59+
let bios_path = out_dir_path.join("bios.img");
60+
bootloader::BiosBoot::new(&kernel_path)
61+
.create_disk_image(&bios_path)
62+
.unwrap();
5563

5664
// pass the disk image paths as env variables to the `main.rs`
5765
println!("cargo:rustc-env=UEFI_PATH={}", uefi_path.display());
@@ -77,8 +85,8 @@ fn main() {
7785
} else {
7886
cmd.arg("-drive").arg(format!("format=raw,file={bios_path}"));
7987
}
80-
let mut child = cmd.spawn()?;
81-
child.wait()?;
88+
let mut child = cmd.spawn().unwrap();
89+
child.wait().unwrap();
8290
}
8391
```
8492

0 commit comments

Comments
 (0)