Skip to content

Commit

Permalink
Merge #79
Browse files Browse the repository at this point in the history
79: Replace manual assembly with nasm-rs and cc r=mkroening a=mkroening



Co-authored-by: Martin Kröning <mkroening@posteo.net>
  • Loading branch information
bors[bot] and mkroening authored May 13, 2022
2 parents 710f70e + cfe962b commit e98fbae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 11 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit e98fbae

Please # to comment.