Added an example C program to debug
This commit is contained in:
parent
72470c5435
commit
e929354975
17
build.rs
17
build.rs
|
|
@ -1,14 +1,21 @@
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let test_prog_exe_path = &format!("{}/prog", std::env::var("OUT_DIR").unwrap());
|
let assembly_exe_path = &format!("{}/asmprog", std::env::var("OUT_DIR").unwrap());
|
||||||
let test_prog_obj_path = &format!("{}.o", test_prog_exe_path);
|
let assembly_obj_path = &format!("{}.o", assembly_exe_path);
|
||||||
Command::new("nasm")
|
Command::new("nasm")
|
||||||
.args(&["-f", "elf64", "src/prog.nasm", "-o", test_prog_obj_path])
|
.args(&["-f", "elf64", "src/prog.nasm", "-o", assembly_obj_path])
|
||||||
.spawn().expect("nasm build failed");
|
.spawn().expect("nasm build failed");
|
||||||
Command::new("ld")
|
Command::new("ld")
|
||||||
.args(&[test_prog_obj_path, "-o", test_prog_exe_path])
|
.args(&[assembly_obj_path, "-o", assembly_exe_path])
|
||||||
.spawn().expect("linking failed");
|
.spawn().expect("linking failed");
|
||||||
println!("cargo:rerun-if-changed=src/prog.nasm");
|
println!("cargo:rerun-if-changed=src/prog.nasm");
|
||||||
println!("cargo:rustc-env=TEST_PROG_PATH={}", test_prog_exe_path);
|
|
||||||
|
let c_exe_path = &format!("{}/cprog", std::env::var("OUT_DIR").unwrap());
|
||||||
|
Command::new("gcc")
|
||||||
|
.args(&["-o", c_exe_path, "src/prog.c"])
|
||||||
|
.spawn().expect("C program compilation failed");
|
||||||
|
println!("cargo:rerun-if-changed=src/prog.c");
|
||||||
|
|
||||||
|
println!("cargo:rustc-env=TEST_PROG_PATH={}", assembly_exe_path);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("Hello world\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue