yac
/
coreutils
Archived
2
0
Fork 0

build assembly true/false with cargo

This commit is contained in:
silt! 2022-12-05 09:39:57 -05:00 committed by emma
parent 799e96e267
commit a1cb1175d4
4 changed files with 47 additions and 56 deletions

View File

@ -12,12 +12,4 @@ authors = [
[[bin]]
name = "cat"
path = "src/bin/cat.rs"
[[bin]]
name = "false"
path = "src/bin/false.rs"
[[bin]]
name = "true"
path = "src/bin/true.rs"
path = "src/bin/cat.rs"

View File

@ -1,4 +1,47 @@
fn main() {
println!("cargo:rustc-link-arg-bin=true=-nostartfiles");
println!("cargo:rustc-link-arg-bin=false=-nostartfiles");
use std::env;
use std::process::{Command, exit};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR")?;
let mut handler_nasm_true = Command::new("nasm").args([
"-f", "elf",
"src/asm/true.asm",
"-o", &(out_dir.clone() + "/true.o")
]).spawn()?;
let mut handler_nasm_false = Command::new("nasm").args([
"-f", "elf",
"src/asm/false.asm",
"-o", &(out_dir.clone() + "/false.o")
]).spawn()?;
if !handler_nasm_true.wait_with_output()?.stderr.is_empty() {
exit(1);
}
let mut handler_ld_true = Command::new("ld").args([
"-m", "elf_i386",
"src/asm/true.asm",
"-s",
&(out_dir.clone() + "/true.o"),
"-o", &(out_dir.clone() + "/true"),
]).spawn()?;
if !handler_nasm_false.wait_with_output()?.stderr.is_empty() {
exit(1)
}
let mut handler_ld_false = Command::new("ld").args([
"-m", "elf_i386",
"src/asm/false.asm",
"-s",
&(out_dir.clone() + "/false.o"),
"-o", &(out_dir.clone() + "/false"),
]).spawn()?;
handler_ld_true.wait();
handler_ld_false.wait();
Ok(())
}

View File

@ -1,22 +0,0 @@
// Copyright (c) 2022 silt <silt@tebibyte.media>
// SPDX-License-Identifier: AGPL-3.0-or-later
#![feature(lang_items, start)]
#![no_main]
#![no_std]
use core::panic::PanicInfo;
use core::arch::asm;
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
#[lang = "panic_impl"] extern fn rust_begin_panic(_: &PanicInfo) -> ! { loop {} }
#[no_mangle]
pub unsafe fn _start() -> ! {
asm!(
"syscall",
in("rax") 60, // Syscall number
in("rdi") 1, // Exit code
options(noreturn)
)
}

View File

@ -1,22 +0,0 @@
// Copyright (c) 2022 silt <silt@tebibyte.media>
// SPDX-License-Identifier: AGPL-3.0-or-later
#![feature(lang_items, start)]
#![no_main]
#![no_std]
use core::panic::PanicInfo;
use core::arch::asm;
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
#[lang = "panic_impl"] extern fn rust_begin_panic(_: &PanicInfo) -> ! { loop {} }
#[no_mangle]
pub unsafe fn _start() -> ! {
asm!(
"syscall",
in("rax") 60, // Syscall number
in("rdi") 0, // Exit code
options(noreturn)
)
}