build assembly true/false with cargo
This commit is contained in:
parent
799e96e267
commit
a1cb1175d4
10
Cargo.toml
10
Cargo.toml
@ -12,12 +12,4 @@ authors = [
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "cat"
|
name = "cat"
|
||||||
path = "src/bin/cat.rs"
|
path = "src/bin/cat.rs"
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "false"
|
|
||||||
path = "src/bin/false.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "true"
|
|
||||||
path = "src/bin/true.rs"
|
|
49
build.rs
49
build.rs
@ -1,4 +1,47 @@
|
|||||||
fn main() {
|
use std::env;
|
||||||
println!("cargo:rustc-link-arg-bin=true=-nostartfiles");
|
use std::process::{Command, exit};
|
||||||
println!("cargo:rustc-link-arg-bin=false=-nostartfiles");
|
|
||||||
|
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(())
|
||||||
}
|
}
|
@ -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)
|
|
||||||
)
|
|
||||||
}
|
|
@ -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)
|
|
||||||
)
|
|
||||||
}
|
|
Reference in New Issue
Block a user