***: add initial initrd build

This commit is contained in:
Mark Poliakov 2023-07-19 21:57:18 +03:00
commit 0ca54f28e0
6 changed files with 75 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "init"
version = "0.1.0"

4
Cargo.toml Normal file
View File

@ -0,0 +1,4 @@
[workspace]
members = [
"init"
]

52
build.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/sh
set -e
if [ "${ARCH}" = "" ]; then
ARCH=aarch64
fi
if [ "${PROFILE}" = "" ]; then
PROFILE=debug
fi
USER_TARGET=${ARCH}-unknown-yggdrasil
USER_CARGO_OPTS="--target=${USER_TARGET}"
USER_FILES=init
pstatus() {
echo -e "[BUILD] \033[32;1m$@\033[0m"
}
die() {
echo -e "[ERROR] \033[31;1m$@\033[0m" >&2
exit 1
}
check_toolchain() {
pstatus "Checking toolchain"
if ! cargo +ygg-stage1 --version; then
die "Yggdrasil OS Rust toolchain is not built/installed, see https://git.alnyan.me/yggdrasil/yggdrasil-rust"
fi
}
pack_initrd() {
cd "target/${USER_TARGET}/${PROFILE}"
tar --xform='s/^/\//' -cf initrd.tar ${USER_FILES}
cd -
}
check_toolchain
case "$1" in
build|"")
pstatus "Building userspace programs"
cargo +ygg-stage1 build ${USER_CARGO_OPTS}
pstatus "Creating initrd.tar"
pack_initrd
;;
**)
;;
esac

8
init/Cargo.toml Normal file
View File

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

3
init/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello!");
}