mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 06:17:49 +00:00
Create the disk image in a build script
This commit is contained in:
@@ -7,5 +7,7 @@ edition = "2021"
|
||||
members = ["kernel"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
[build-dependencies]
|
||||
kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" }
|
||||
bootloader = "0.11.3"
|
||||
|
||||
21
build.rs
Normal file
21
build.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use bootloader::DiskImageBuilder;
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
fn main() {
|
||||
// set by cargo for the kernel artifact dependency
|
||||
let kernel_path = env::var("CARGO_BIN_FILE_KERNEL").unwrap();
|
||||
let disk_builder = DiskImageBuilder::new(PathBuf::from(kernel_path));
|
||||
|
||||
// specify output paths
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
let uefi_path = out_dir.join("blog_os-uefi.img");
|
||||
let bios_path = out_dir.join("blog_os-bios.img");
|
||||
|
||||
// create the disk images
|
||||
disk_builder.create_uefi_image(&uefi_path).unwrap();
|
||||
disk_builder.create_bios_image(&bios_path).unwrap();
|
||||
|
||||
// pass the disk image paths via environment variables
|
||||
println!("cargo:rustc-env=UEFI_IMAGE={}", uefi_path.display());
|
||||
println!("cargo:rustc-env=BIOS_IMAGE={}", bios_path.display());
|
||||
}
|
||||
26
src/main.rs
26
src/main.rs
@@ -1,21 +1,13 @@
|
||||
use bootloader::DiskImageBuilder;
|
||||
use std::{env, error::Error, path::PathBuf};
|
||||
use std::{env, fs};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
// set by cargo for the kernel artifact dependency
|
||||
let kernel_path = PathBuf::from(env!("CARGO_BIN_FILE_KERNEL"));
|
||||
let disk_builder = DiskImageBuilder::new(kernel_path);
|
||||
fn main() {
|
||||
let current_exe = env::current_exe().unwrap();
|
||||
let uefi_target = current_exe.with_file_name("uefi.img");
|
||||
let bios_target = current_exe.with_file_name("bios.img");
|
||||
|
||||
// place the disk image files under target/debug or target/release
|
||||
let target_dir = env::current_exe()?;
|
||||
fs::copy(env!("UEFI_IMAGE"), &uefi_target).unwrap();
|
||||
fs::copy(env!("BIOS_IMAGE"), &bios_target).unwrap();
|
||||
|
||||
let uefi_path = target_dir.with_file_name("blog_os-uefi.img");
|
||||
disk_builder.create_uefi_image(&uefi_path)?;
|
||||
println!("Created UEFI disk image at {}", uefi_path.display());
|
||||
|
||||
let bios_path = target_dir.with_file_name("blog_os-bios.img");
|
||||
disk_builder.create_bios_image(&bios_path)?;
|
||||
println!("Created BIOS disk image at {}", bios_path.display());
|
||||
|
||||
Ok(())
|
||||
println!("UEFI disk image at {}", uefi_target.display());
|
||||
println!("BIOS disk image at {}", bios_target.display());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user