1
0
Fork 0
forked from AbleOS/ableos

feat: repbuild2 minimum viable product

This commit is contained in:
TheOddGarlic 2022-08-03 10:11:51 +03:00
parent d75875afaf
commit 0ec08d7460
7 changed files with 304 additions and 15 deletions

78
Cargo.lock generated
View file

@ -97,6 +97,17 @@ dependencies = [
"logos", "logos",
] ]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -150,6 +161,17 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colored"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]] [[package]]
name = "conquer-once" name = "conquer-once"
version = "0.3.2" version = "0.3.2"
@ -249,6 +271,15 @@ dependencies = [
"ahash", "ahash",
] ]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "kernel" name = "kernel"
version = "0.1.2" version = "0.1.2"
@ -282,7 +313,7 @@ checksum = "da83a57f3f5ba3680950aa3cbc806fc297bc0b289d42e8942ed528ace71b8145"
[[package]] [[package]]
name = "libwasm" name = "libwasm"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/able/libwasm.git#e50b7beb8a2087f5a9e527c3ebac31fd3ff42aff" source = "git+https://git.ablecorp.us/able/libwasm.git#4ffcd290f8bc918ca4adf5e23ce2097968e4a8b2"
[[package]] [[package]]
name = "linked_list_allocator" name = "linked_list_allocator"
@ -450,9 +481,9 @@ checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.42" version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -483,9 +514,9 @@ version = "0.12.0"
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.20" version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -511,6 +542,13 @@ version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "repbuild"
version = "0.1.0"
dependencies = [
"colored",
]
[[package]] [[package]]
name = "riscv" name = "riscv"
version = "0.8.0" version = "0.8.0"
@ -562,9 +600,9 @@ dependencies = [
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.8" version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24c8ad4f0c00e1eb5bc7614d236a7f1300e3dbd76b68cac8e06fb00b015ad8d8" checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
@ -624,9 +662,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.98" version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -762,6 +800,28 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d1a10e1dedffff9cfcbdd33c289c65b87da634259a460a3f23d513649fa7a8c" checksum = "1d1a10e1dedffff9cfcbdd33c289c65b87da634259a460a3f23d513649fa7a8c"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "x86_64" name = "x86_64"
version = "0.14.10" version = "0.14.10"

View file

@ -5,4 +5,5 @@ members = [
"ext2-rs", "ext2-rs",
"kernel", "kernel",
"facepalm", "facepalm",
"repbuild"
] ]

View file

@ -1,4 +1,4 @@
use crate::arch::{drivers::sysinfo::master}; use crate::arch::drivers::sysinfo::master;
use crate::systeminfo::{KERNEL_VERSION, RELEASE_TYPE}; use crate::systeminfo::{KERNEL_VERSION, RELEASE_TYPE};
use crate::{filesystem::FILE_SYSTEM, time::fetch_time, KERNEL_STATE}; use crate::{filesystem::FILE_SYSTEM, time::fetch_time, KERNEL_STATE};
use genfs::{Fs, OpenOptions}; use genfs::{Fs, OpenOptions};

View file

@ -1,11 +1,7 @@
//! Ext2 crate for ableOS //! Ext2 crate for ableOS
#![deny(missing_docs)] #![deny(missing_docs)]
#![feature( #![feature(min_specialization, step_trait, associated_type_defaults)]
min_specialization,
step_trait,
associated_type_defaults
)]
#![cfg_attr(all(not(test), feature = "no_std"), no_std)] #![cfg_attr(all(not(test), feature = "no_std"), no_std)]
extern crate alloc; extern crate alloc;

9
repbuild/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "repbuild"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
colored = "2.0"

10
repbuild/README.md Normal file
View file

@ -0,0 +1,10 @@
# Repbuild
Repbuild is the AbleOS build system.
# Usage
TODO
## Why is it named Repbuild?
The first Repbuild was originally ripped from repnop's xtask build system in
the risc-v kernel (hence the name). However Repbuild has since been rewritten
but the name has been kept.

213
repbuild/src/main.rs Normal file
View file

@ -0,0 +1,213 @@
/*
* Copyright (c) 2022, Umut İnan Erdoğan <umutinanerdogan@pm.me>
*
* SPDX-License-Identifier: MPL-2.0
*/
use std::{fs, process::Command};
use colored::*;
struct Options {
pub subcommand: Subcommand,
pub arguments: Vec<String>,
}
enum Subcommand {
Doc,
Help,
Run,
Empty,
Unknown(String),
}
impl Subcommand {
fn from_str<S: AsRef<str>>(str: S) -> Subcommand {
match str.as_ref() {
"doc" => Subcommand::Doc,
"help" => Subcommand::Help,
"run" => Subcommand::Run,
"" => Subcommand::Empty,
unknown => Subcommand::Unknown(unknown.to_string()),
}
}
}
enum MachineType {
X86_64,
RiscV64,
AArch64,
Unknown(String),
}
fn main() {
let options = options();
match options.subcommand {
Subcommand::Doc => {
let machine_text = options
.arguments
.get(0)
.cloned()
.unwrap_or_else(|| String::new());
match machine(machine_text) {
MachineType::X86_64 => {
Command::new("cargo")
.args(["doc", "--open"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::RiscV64 => {
Command::new("cargo")
.args(["doc", "--open", "--target=riscv64gc-unknown-none-elf"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::AArch64 => {
Command::new("cargo")
.args(["doc", "--open", "--target=json_targets/aarch64-ableos.json"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::Unknown(unknown) => {
eprintln!(
"{}: unknown machine type `{}`",
"error".red().bold(),
unknown.bold(),
);
eprintln!("expected one of x86_64, riscv64 or aarch64");
}
}
}
Subcommand::Help => help(),
Subcommand::Run => {
let machine_text = options.arguments.get(0).cloned().unwrap_or_default();
let debug = options.arguments.get(1).cloned().unwrap_or_default();
let debug = matches!(debug.as_str(), "--debug" | "--dbg" | "-d");
match machine(machine_text) {
MachineType::X86_64 if debug => {
Command::new("cargo")
.args(["run", "--", "-S", "-gdb", "tcp:9000"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::X86_64 => {
Command::new("cargo")
.args(["run", "--release"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::RiscV64 if debug => {
eprintln!(
"{}: debug is not implemented for riscv64",
"error".red().bold()
);
}
MachineType::RiscV64 => {
Command::new("cargo")
.args(["build", "--release", "--target=riscv64gc-unknown-none-elf"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
Command::new("qemu-system-riscv64")
.args(["-machine", "virt"])
.args(["-cpu", "rv64"])
.args(["-smp", "8"])
.args(["-m", "128M"])
.arg("-bios")
.arg("src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin")
.arg("-kernel")
.arg("target/riscv64gc-unknown-none-elf/release/ableos")
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::AArch64 if debug => {
eprintln!(
"{}: debug is not implemented for aarch64",
"error".red().bold()
);
}
MachineType::AArch64 => {
Command::new("cargo")
.args([
"build",
"--release",
"--target=json_targets/aarch64-ableos.json",
])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
Command::new("qemu-system-aarch64")
.args(["-machine", "virt"])
.args(["-m", "1024M"])
.args(["-cpu", "cortex-a53"])
.args(["-kernel", "target/aarch64-ableos/release/ableos"])
.args(["-device", "virtio-keyboard"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
}
MachineType::Unknown(unknown) => {
eprintln!(
"{}: unknown machine type `{}`",
"error".red().bold(),
unknown.bold(),
);
eprintln!("expected one of x86_64, riscv64 or aarch64");
}
}
}
Subcommand::Empty => {
eprintln!("{}: no subcommand passed", "error".red().bold());
help();
}
Subcommand::Unknown(unknown) => {
eprintln!(
"{}: unknown subcommand `{}`",
"error".red().bold(),
unknown.bold()
);
help();
}
}
}
fn options() -> Options {
let subcommand = std::env::args().nth(1).unwrap_or_default();
let arguments = std::env::args().skip(2).collect();
Options {
subcommand: Subcommand::from_str(subcommand),
arguments,
}
}
fn machine<S: AsRef<str>>(text: S) -> MachineType {
match text.as_ref() {
"x86" | "x86_64" => MachineType::X86_64,
"riscv" | "riscv64" => MachineType::RiscV64,
"arm" | "arm64" | "aarch64" => MachineType::AArch64,
"" => {
eprintln!(
"{}: no machine type passed, defaulting to x86_64",
"warning".yellow().bold()
);
MachineType::X86_64
}
unknown => MachineType::Unknown(unknown.to_string()),
}
}
fn help() {
todo!("`help`")
}