diff --git a/Cargo.lock b/Cargo.lock index 7cdcd172..42e6e1d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + [[package]] name = "cfg-if" version = "1.0.0" @@ -79,6 +85,12 @@ dependencies = [ "paste", ] +[[package]] +name = "nasm-rs" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce095842aee9aa3ecbda7a5d2a4df680375fd128a8596b6b56f8e497e231f483" + [[package]] name = "paste" version = "1.0.7" @@ -133,8 +145,10 @@ version = "0.2.6" dependencies = [ "aarch64", "bitflags", + "cc", "goblin", "multiboot", + "nasm-rs", "static-alloc", "x86", ] diff --git a/Cargo.toml b/Cargo.toml index ead3b003..b6201aa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,10 @@ x86 = { version = "0.47", default-features = false } [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64 = "0.0.7" +[build-dependencies] +cc = "1.0" +nasm-rs = "0.2" + [profile.dev] opt-level = 1 # `opt-level = 0` makes bootloader to large for bootstrapping diff --git a/build.rs b/build.rs index 8ccb6777..abc79f28 100644 --- a/build.rs +++ b/build.rs @@ -1,25 +1,21 @@ use std::env; -use std::path::Path; -use std::process::Command; -fn main() { +fn main() -> Result<(), String> { let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); if target_arch == "x86_64" { - let out_dir = env::var("OUT_DIR").unwrap(); + let mut nasm = nasm_rs::Build::new(); + nasm.file("src/arch/x86_64/entry.asm"); + let objects = nasm.compile_objects()?; - Command::new("nasm") - .args(&["src/arch/x86_64/entry.asm", "-felf64", "-o"]) - .arg(&format!("{}/entry.o", out_dir)) - .status() - .expect("Could not start nasm. Is it installed?"); - Command::new("ar") - .args(&["crus", "libentry.a", "entry.o"]) - .current_dir(&Path::new(&out_dir)) - .status() - .expect("Could not start ar. Is it installed?"); + let mut cc = cc::Build::new(); + for object in objects { + cc.object(object); + } + cc.compile("entry"); - println!("cargo:rustc-link-search=native={}", out_dir); println!("cargo:rustc-link-lib=static=entry"); } + + Ok(()) }