Skip to content

Commit 2a08281

Browse files
committed
build: add base build system
1 parent 0aa43f2 commit 2a08281

File tree

8 files changed

+166
-1
lines changed

8 files changed

+166
-1
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[alias]
2-
aero = "run --release --manifest-path ./aero_build/Cargo.toml --"
2+
aero = "run --manifest-path ./src/aero_build/Cargo.toml --"

src/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[workspace]
22
members = ["aero_kernel", "aero_syscall", "aero_proc"]
3+
# if aero_build is part of the workspace, cargo will attempt to build it as no_std
4+
exclude = ["aero_build"]
35

46
[profile.release]
57
debug = true

src/aero_build/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "aero_build"
3+
version = "0.1.0"
4+
authors = ["Joshua Price <[email protected]>"]
5+
edition = "2021"
6+
7+
[dependencies]
8+
# clap = "3.2.22"

src/aero_build/src/build.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::path::Path;
2+
use std::process::Command;
3+
4+
use crate::utils;
5+
use crate::constants;
6+
7+
struct BuildInfo {
8+
args: Vec<String>,
9+
target_arch: String,
10+
}
11+
12+
pub fn build() {
13+
utils::log_info("build test");
14+
15+
let output = utils::run_command(&std::env::current_dir().unwrap(), "/usr/bin/ls", vec![String::from("-l"), String::from("-a")]);
16+
println!("{:?}", output);
17+
output.log_if_exists();
18+
}
19+
20+
fn build_cargo_workspace(cwd: &Path, command: &str, args: Vec<String>, cargo: Option<&str>) {
21+
// let cargo_cmd = cargo.unwrap_or("cargo");
22+
23+
// Command::new(cargo_cmd)
24+
// .arg(command)
25+
// .args(args)
26+
// .current_dir(cwd)
27+
// .spawn()
28+
// .expect("cargo failed to run");
29+
30+
// let code, _, _ = run_command([cargo.unwrap_or("cargo"), command, *args], cwd=cwd);
31+
32+
// if code != 0:
33+
// return None
34+
35+
// _, stdout, _ = run_command([cargo, command, *args, '--message-format=json'],
36+
// stdout=subprocess.PIPE,
37+
// stderr=subprocess.DEVNULL,
38+
// cwd=cwd)
39+
40+
// return extract_artifacts(stdout);
41+
}

src/aero_build/src/constants.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::path::Path;
2+
3+
#[macro_export]
4+
macro_rules! const_str {
5+
($name:ident, $value:expr) => {
6+
pub const $name: &'static str = $value;
7+
};
8+
}
9+
10+
const_str!(OVMF_URL, "https://github.com/aero-os/ovmf-prebuilt");
11+
12+
// pub const OVMF_URL = "https://github.com/aero-os/ovmf-prebuilt";
13+
const_str!(LIMINE_URL, "https://github.com/limine-bootloader/limine");
14+
15+
const_str!(BUILD_DIR, "build");
16+
const_str!(BUNDLED_DIR, "bundled");
17+
const_str!(SYSROOT_DIR, "sysroot");
18+
const_str!(SYSROOT_CARGO_HOME, "sysroot/cargo-home");
19+
const_str!(EXTRA_FILES, "extra-files");
20+
const_str!(BASE_FILES_DIR, "base-files");
21+
const_str!(LIMINE_TEMPLATE, r#"
22+
TIMEOUT=0
23+
VERBOSE=yes
24+
25+
:aero
26+
PROTOCOL=limine
27+
KASLR=no
28+
KERNEL_PATH=boot:///aero.elf
29+
CMDLINE=term-background=background theme-background=0x50000000
30+
31+
MODULE_PATH=boot:///term_background.bmp
32+
MODULE_CMDLINE=background
33+
34+
MODULE_PATH=boot:///initramfs.cpio
35+
MODULE_CMDLINE=initramfs
36+
"#);

src/aero_build/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::env;
2+
3+
mod build;
4+
mod constants;
5+
mod test;
6+
mod utils;
7+
8+
fn main() {
9+
let arg = env::args().nth(1);
10+
match arg.as_ref().map(|x| x.as_str()) {
11+
Some("build") => build::build(),
12+
Some("test") => test::test(),
13+
None => eprintln!("no task specified\navailable tasks: build, test"),
14+
_ => eprintln!("specified task does not exist\navailable tasks: build, test"),
15+
}
16+
}

src/aero_build/src/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn test() {
2+
println!("test");
3+
}

src/aero_build/src/utils.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use std::process::{Command, ExitStatus};
2+
use std::path::Path;
3+
4+
const ANSI_ESCAPE: &str = "\x1b[";
5+
const ANSI_BOLD_RED: &str = "1;31m";
6+
const ANSI_BOLD_GREEN: &str = "1;32m";
7+
const ANSI_RESET: &str = "0m";
8+
9+
pub fn log_info(message: &str) {
10+
println!("{ANSI_ESCAPE}{ANSI_BOLD_GREEN}info: {ANSI_ESCAPE}{ANSI_RESET}{message}");
11+
}
12+
13+
pub fn log_error(message: &str) {
14+
println!("{ANSI_ESCAPE}{ANSI_BOLD_RED}red: {ANSI_ESCAPE}{ANSI_RESET}{message}");
15+
}
16+
17+
#[derive(Debug)]
18+
pub struct CommandOutput {
19+
pub exit_status: ExitStatus,
20+
pub stdout: Option<String>,
21+
pub stderr: Option<String>,
22+
}
23+
24+
impl CommandOutput {
25+
pub fn log_if_exists(&self) {
26+
if let Some(stdout) = &self.stdout {
27+
log_info(&stdout);
28+
}
29+
if let Some(stderr) = &self.stderr {
30+
log_error(&stderr);
31+
}
32+
}
33+
}
34+
35+
pub fn run_command(pwd: &Path, command: &str, args: Vec<String>) -> CommandOutput {
36+
let output = Command::new(command)
37+
.arg(command)
38+
.args(args)
39+
// .current_dir(pwd)
40+
.output()
41+
.expect("todo");
42+
43+
let stdout = if !&output.stdout.is_empty() {
44+
Some(String::from_utf8(output.stdout).unwrap())
45+
} else {
46+
None
47+
};
48+
let stderr = if !&output.stderr.is_empty() {
49+
Some(String::from_utf8(output.stderr).unwrap())
50+
} else {
51+
None
52+
};
53+
54+
CommandOutput {
55+
exit_status: output.status,
56+
stdout: stdout,
57+
stderr: stderr,
58+
}
59+
}

0 commit comments

Comments
 (0)