tg-syscall 0.1.0-preview.1

System call definitions and interfaces for rCore tutorial OS.
Documentation
fn main() {
    use std::{
        env,
        fs::{self, File},
        io::Write,
        path::PathBuf,
    };

    const SYSCALL_H_IN: &str = "src/syscall.h.in";
    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:rerun-if-changed={SYSCALL_H_IN}");

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let mut fout = File::create(out_dir.join("syscalls.rs")).unwrap();
    writeln!(
        fout,
        "\
// Generated by build.rs. DO NOT EDIT.

impl crate::SyscallId {{"
    )
    .unwrap();
    fs::read_to_string(SYSCALL_H_IN)
        .unwrap()
        .lines()
        .filter_map(|line| line.strip_prefix("#define __NR_"))
        .filter_map(|line| line.split_once(' '))
        .for_each(|(name, num)| {
            writeln!(
                fout,
                "    pub const {name}: Self = Self({num});",
                name = name.to_uppercase()
            )
            .unwrap();
        });
    writeln!(fout, "}}").unwrap();
}