Skip to content

Commit

Permalink
Add xtask crate for loader building
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed May 13, 2022
1 parent 4e33233 commit d335241
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 76 deletions.
18 changes: 2 additions & 16 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
[unstable]
build-std = ["core", "alloc"]
build-std-features = ["compiler-builtins-mem"]

[target.x86_64-unknown-hermit-loader]
rustflags = [
"-C", "link-arg=-Tsrc/arch/x86_64/link.ld"
]

[target.aarch64-unknown-hermit-loader]
rustflags = [
"-C", "link-arg=-Tsrc/arch/aarch64/link.ld"
]

[build]
target = "targets/x86_64-unknown-hermit-loader.json"
[alias]
xtask = "run --package xtask --"
22 changes: 13 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
sudo apt-get install nasm
- uses: actions/checkout@v3
- name: Clippy
run: cargo clippy
run: cargo xtask clippy
env:
RUSTFLAGS: -Dwarnings

Expand Down Expand Up @@ -55,18 +55,20 @@ jobs:
run: |
brew update
brew install qemu nasm
- name: Install QEMU, NASM, GNU make (windows)
- name: Install QEMU, NASM (windows)
if: matrix.os == 'windows-latest'
run: |
choco install qemu --version 2021.12.15
echo "C:\Program Files\qemu" >> $GITHUB_PATH
choco install nasm make
choco install nasm
echo "C:\Program Files\NASM" >> $GITHUB_PATH
- uses: actions/checkout@v3
with:
lfs: true
- name: Build
run: make arch=${{ matrix.arch }}
run: cargo xtask build --arch ${{ matrix.arch }}
env:
HERMIT_APP: ${{ github.workspace }}/data/${{ matrix.arch }}/hello_world
- name: Run loader (x86_64)
if: matrix.arch == 'x86_64'
run: |
Expand All @@ -75,17 +77,19 @@ jobs:
-smp 1 -m 64M \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
-display none -serial stdio \
-kernel target/x86_64-unknown-hermit-loader/debug/rusty-loader \
-kernel target/x86_64/debug/rusty-loader \
-initrd data/x86_64/hello_world
- name: Run loader (aarch64)
if: matrix.arch == 'aarch64'
run: |
qemu-system-aarch64 \
-machine virt,gic-version=max -cpu max -smp 1 -m 512M \
-display none -serial stdio -semihosting \
-kernel target/aarch64-unknown-hermit-loader/debug/rusty-loader
-kernel target/aarch64/debug/rusty-loader
- name: Build (release)
run: make arch=${{ matrix.arch }} release=1
run: cargo xtask build --arch ${{ matrix.arch }} --release
env:
HERMIT_APP: ${{ github.workspace }}/data/${{ matrix.arch }}/hello_world
- name: Run loader (release, x86_64)
if: matrix.arch == 'x86_64'
run: |
Expand All @@ -94,15 +98,15 @@ jobs:
-smp 1 -m 64M \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
-display none -serial stdio \
-kernel target/x86_64-unknown-hermit-loader/release/rusty-loader \
-kernel target/x86_64/release/rusty-loader \
-initrd data/x86_64/hello_world
- name: Run loader (release, aarch64)
if: matrix.arch == 'aarch64'
run: |
qemu-system-aarch64 \
-machine virt,gic-version=max -cpu max -smp 1 -m 512M \
-display none -serial stdio -semihosting \
-kernel target/aarch64-unknown-hermit-loader/release/rusty-loader
-kernel target/aarch64/release/rusty-loader


6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ build:loader:
stage: build
image: ${CI_REGISTRY_IMAGE}
script:
- make release=1
- cargo xtask build --arch x86_64 --release
artifacts:
paths:
- target/x86_64-unknown-hermit-loader/release/rusty-loader
- target/x86_64/release/rusty-loader

.deploy:loader: &loader
stage: deploy
Expand All @@ -51,7 +51,7 @@ build:loader:
cat << END > ${DOCKER_FILE}
FROM alpine:3.14
RUN apk add --no-cache qemu-system-x86_64 qemu-modules
ADD target/x86_64-unknown-hermit-loader/release/rusty-loader /hermit/
ADD target/x86_64/release/rusty-loader /hermit/
END
- docker build -f ${DOCKER_FILE} -t ${DOCKER_IMAGE}/loader:latest .
- docker push ${DOCKER_IMAGE}/loader:latest
Expand Down
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ opt-level = 1 # `opt-level = 0` makes bootloader to large for bootstrapping
strip = "debuginfo"
lto = true
codegen-units = 1

[workspace]
members = [
"xtask",
]
46 changes: 0 additions & 46 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ You also need `nasm` and `ar` installed on your machine.
Afterwards, the loader can be built as follows:

```bash
$ make
$ cargo xtask build --arch x86_64
```

Afterwards, the loader is stored in `target/x86_64-unknown-hermit-loader/debug/` as `rusty-loader`.
Afterwards, the loader is stored in `target/x86_64/debug/` as `rusty-loader`.
As final step the unikernel application `app` can be booted with following command:

```bash
Expand Down
1 change: 1 addition & 0 deletions xtask/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
10 changes: 10 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
rustc_version = "0.4"
xflags = "0.2"
xshell = "0.2"
75 changes: 75 additions & 0 deletions xtask/src/flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::path::PathBuf;

xflags::xflags! {
src "./src/flags.rs"

/// Run custom build command.
cmd xtask {
default cmd help {
/// Print help information.
optional -h, --help
}

/// Build the kernel.
cmd build
{
/// Build for the architecture.
required --arch arch: String
/// Directory for all generated artifacts.
optional --target-dir target_dir: PathBuf
/// Build artifacts in release mode, with optimizations.
optional -r, --release
/// Build artifacts with the specified profile.
optional --profile profile: String
}

/// Run clippy for all targets.
cmd clippy {}
}
}

// generated start
// The following code is generated by `xflags` macro.
// Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
#[derive(Debug)]
pub struct Xtask {
pub subcommand: XtaskCmd,
}

#[derive(Debug)]
pub enum XtaskCmd {
Help(Help),
Build(Build),
Clippy(Clippy),
}

#[derive(Debug)]
pub struct Help {
pub help: bool,
}

#[derive(Debug)]
pub struct Build {
pub arch: String,
pub target_dir: Option<PathBuf>,
pub release: bool,
pub profile: Option<String>,
}

#[derive(Debug)]
pub struct Clippy;

impl Xtask {
pub const HELP: &'static str = Self::HELP_;

#[allow(dead_code)]
pub fn from_env() -> xflags::Result<Self> {
Self::from_env_()
}

#[allow(dead_code)]
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
Self::from_vec_(args)
}
}
// generated end
Loading

0 comments on commit d335241

Please sign in to comment.