Skip to content

Fix Create Disk Image Example #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 2, 2023
Merged
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
20 changes: 11 additions & 9 deletions docs/create-disk-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test-kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none

[dependencies]
# used for UEFI booting in QEMU
ovmf_prebuilt = "0.1.0-alpha.1"
ovmf-prebuilt = "0.1.0-alpha.1"

[workspace]
members = ["kernel"]
Expand All @@ -38,20 +38,22 @@ members = ["kernel"]
```rust
// build.rs

use std::path::PathBuf;

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

// create an UEFI disk image (optional)
let uefi_path = out_dir.join("uefi.img");
bootloader::UefiBoot::new(&kernel).create_disk_image(uefi_path).unwrap();
bootloader::UefiBoot::new(&kernel).create_disk_image(&uefi_path).unwrap();

// create a BIOS disk image (optional)
let out_bios_path = out_dir.join("bios.img");
bootloader::BiosBoot::new(&kernel).create_disk_image(uefi_path).unwrap();
// create a BIOS disk image
let bios_path = out_dir.join("bios.img");
bootloader::BiosBoot::new(&kernel).create_disk_image(&bios_path).unwrap();

// pass the disk image paths as env variables to the `main.rs`
println!("cargo:rustc-env=UEFI_PATH={}", uefi_path.display());
Expand All @@ -77,8 +79,8 @@ fn main() {
} else {
cmd.arg("-drive").arg(format!("format=raw,file={bios_path}"));
}
let mut child = cmd.spawn()?;
child.wait()?;
let mut child = cmd.spawn().unwrap();
child.wait().unwrap();
}
```

Expand Down