-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
29 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |