Next Generation WASM Microkernel Operating System
1##!/usr/bin/env just --justfile
2
3set windows-shell := ["powershell.exe", "-c"]
4
5# Overrides the default Rust toolchain set in `rust-toolchain.toml`.
6toolchain := ""
7
8# disables cargo nextest
9no-nextest := ''
10
11_docstring := "
12justfile for k23
13see https://just.systems/man/en/
14
15Available variables:
16 toolchain # overrides the default Rust toolchain set in the
17 # rust-toolchain.toml file.
18 profile # configures what Cargo profile (release or debug) to use
19 # for builds.
20 no-nextest # disable running tests with cargo-nextest, use the regular test runner instead.
21
22Variables can be set using `just VARIABLE=VALUE ...` or
23`just --set VARIABLE VALUE ...`.
24"
25
26# default recipe to display help information
27_default:
28 @echo '{{ _docstring }}'
29 @just --list
30
31# Alias for `cargo xtask qemu`
32run profile args="" *qemu_args="":
33 {{ _cargo }} xtask run {{ profile }} {{ args }} -- {{ qemu_args }}
34
35# Alias for `cargo xtask build`
36build profile args="" *qemu_args="":
37 {{ _cargo }} xtask build {{ profile }} {{ args }} -- {{ qemu_args }}
38
39# quick check for development
40check crate="" *cargo_args="":
41 {{ _cargo }} check \
42 {{ if crate == "" { "--workspace --exclude loader --exclude xtask --exclude toml-patch" } else { "-p" } }} {{ crate }} \
43 --target profile/riscv64/riscv64gc-k23-none-kernel.json \
44 --locked \
45 {{ _buildstd }} \
46 {{ _fmt }} \
47 {{ cargo_args }}
48 KERNEL=Cargo.toml {{ _cargo }} check \
49 -p loader \
50 --target riscv64gc-unknown-none-elf \
51 {{ _buildstd }} \
52 {{ _fmt }} \
53 {{ cargo_args }}
54
55# run all tests and checks
56preflight crate="" *cargo_args="": (lint crate cargo_args) (test crate cargo_args) (miri crate cargo_args) (loom crate cargo_args)
57 typos
58
59# run lints (clippy, rustfmt, docs) for a crate or the entire for the workspace.
60lint crate="" *cargo_args="": (clippy crate cargo_args) (check-fmt crate cargo_args)
61
62# run clippy on a crate or the entire workspace.
63clippy crate="" *cargo_args="":
64 {{ _cargo }} clippy \
65 {{ if crate == "" { "--workspace --exclude loader --exclude xtask --exclude toml-patch" } else { "-p" } }} {{ crate }} \
66 --target profile/riscv64/riscv64gc-k23-none-kernel.json \
67 --locked \
68 {{ _buildstd }} \
69 {{ _fmt_clippy }} \
70 {{ cargo_args }}
71 KERNEL=Cargo.toml {{ _cargo }} clippy \
72 -p loader \
73 --target riscv64gc-unknown-none-elf \
74 --locked \
75 {{ _buildstd }} \
76 {{ _fmt_clippy }} \
77 {{ cargo_args }}
78
79# check formatting for a crate or the entire workspace.
80check-fmt crate="" *cargo_args="":
81 {{ _cargo }} fmt --check \
82 {{ if crate == "" { "--all" } else { "-p" } }} {{ crate }} \
83 {{ _fmt }} \
84 {{ cargo_args }}
85
86# ==============================================================================
87# Hosted Testing
88# ==============================================================================
89
90# crates that have hosted tests
91_hosted_crates := "-p kaddr2line -p cpu-local -p fastrand -p fdt -p kasync --features counters -p ksharded-slab -p spin -p wast@228.0.0 -p wavltree"
92# run hosted tests
93test crate="" *cargo_args="": _get-nextest
94 {{ _cargo }} {{ _testcmd }} \
95 {{ if crate == "" { _hosted_crates } else { "-p" + crate } }} \
96 --lib \
97 --no-fail-fast \
98 {{ cargo_args }}
99
100# crates that have miri tests
101_miri_crates := "-p kasync --features counters -p ksharded-slab -p spin -p wavltree"
102# run hosted tests under miri
103miri crate="" *cargo_args="": _get-nextest
104 MIRIFLAGS="{{ env_var_or_default("MIRIFLAGS", "-Zmiri-strict-provenance -Zmiri-disable-isolation") }} -Zmiri-env-forward=RUST_BACKTRACE -Zmiri-env-forward=RUST_LOG" \
105 RUSTFLAGS="{{ env_var_or_default("RUSTFLAGS", "-Zrandomize-layout") }}" \
106 {{ _cargo }} miri {{ _testcmd }} \
107 {{ if crate == "" { _miri_crates } else { "-p" + crate } }} \
108 --lib \
109 --no-fail-fast \
110 {{ cargo_args }}
111
112# crates that have loom tests
113_loom_crates := "-p kasync --features counters"
114# run hosted tests under loom
115loom crate="" *cargo_args='': _get-nextest
116 #!/usr/bin/env bash
117 set -euo pipefail
118 source "./util/shell.sh"
119
120 export RUSTFLAGS="--cfg loom ${RUSTFLAGS:-}"
121 export LOOM_LOG="${LOOM_LOG:-kasync=trace,cordyceps=trace,debug}"
122 export LOOM_MAX_PREEMPTIONS=2
123
124 # if logging is enabled, also enable location tracking.
125 if [[ "${LOOM_LOG}" != "off" ]]; then
126 export LOOM_LOCATION=true
127 status "Enabled" "logging, LOOM_LOG=${LOOM_LOG}"
128 else
129 status "Disabled" "logging and location tracking"
130 fi
131
132 if [[ "${LOOM_CHECKPOINT_FILE:-}" ]]; then
133 export LOOM_CHECKPOINT_FILE="${LOOM_CHECKPOINT_FILE:-}"
134 export LOOM_CHECKPOINT_INTERVAL="${LOOM_CHECKPOINT_INTERVAL:-100}"
135 status "Saving" "checkpoints to ${LOOM_CHECKPOINT_FILE} every ${LOOM_CHECKPOINT_INTERVAL} iterations"
136 fi
137
138 # if the loom tests fail, we still want to be able to print the checkpoint
139 # location before exiting.
140 set +e
141
142 # run loom tests
143 {{ _cargo }} {{ _testcmd }} \
144 {{ _loom-profile }} \
145 {{ if crate == "" { _loom_crates } else { "-p" + crate } }} \
146 --lib \
147 --no-fail-fast \
148 {{ cargo_args }}
149 status="$?"
150
151 if [[ "${LOOM_CHECKPOINT_FILE:-}" ]]; then
152 status "Checkpoints" "saved to ${LOOM_CHECKPOINT_FILE}"
153 fi
154
155 exit "$status"
156
157# ==============================================================================
158# On-Target Testing
159# ==============================================================================
160
161# run on-target tests for RISCV 64-bit
162test-riscv64 *args='':
163 cargo xtask test profile/riscv64/qemu.toml --release {{ args }}
164
165# ==============================================================================
166# Documentation
167# ==============================================================================
168
169# open the manual in development mode
170manual:
171 cd manual && mdbook serve --open
172
173## build documentation for a crate or the entire workspace.
174#build-docs crate="" *cargo_args="":
175# {{ _rustdoc }} \
176# {{ if crate == "" { _hosted_crates } else { "-p" + crate } }} \
177# --target profile/riscv64/riscv64gc-k23-none-kernel.json \
178# {{ _buildstd }} \
179# {{ _fmt }} \
180# {{ cargo_args }}
181# KERNEL=Cargo.toml {{ _rustdoc }} \
182# -p loader \
183# --target riscv64gc-unknown-none-elf \
184# {{ _buildstd }} \
185# {{ _fmt }} \
186# {{ cargo_args }}
187#
188## check documentation for a crate or the entire workspace.
189#check-docs crate="" *cargo_args="": (build-docs crate cargo_args) (test-docs crate cargo_args)
190#
191## test documentation for a crate or the entire workspace.
192#test-docs crate="" *cargo_args="":
193# {{ _cargo }} test --doc \
194# {{ if crate == "" { _hosted_crates } else { "-p" + crate } }} \
195# --locked \
196# {{ _buildstd }} \
197# {{ _fmt }} \
198# {{ cargo_args }}
199
200# ==============================================================================
201# Private state and commands
202# ==============================================================================
203
204# configures what profile to use for builds.
205_cargo := "cargo" + if toolchain != "" { " +" + toolchain } else { "" }
206_buildstd := "-Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem"
207_rustdoc := _cargo + " doc --no-deps --all-features"
208
209# as of recent Rust nightly versions the old `CARGO_RUSTC_CURRENT_DIR` we used to locate the kernel artifact from the
210# loader build script got removed :/ This is a stopgap until they come up with a replacement.
211# https://github.com/rust-lang/cargo/issues/3946
212export __K23_CARGO_RUSTC_CURRENT_DIR := `dirname "$(cargo locate-project --workspace --message-format plain)"`
213
214# If we're running in Github Actions and cargo-action-fmt is installed, then add
215# a command suffix that formats errors.
216_fmt_clippy := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "" } else { ```
217 if command -v cargo-action-fmt >/dev/null 2>&1; then
218 echo "--message-format=json -- -Dwarnings | cargo-action-fmt"
219 fi
220 ``` }
221_fmt := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "" } else { ```
222 if command -v cargo-action-fmt >/dev/null 2>&1; then
223 echo "--message-format=json | cargo-action-fmt"
224 fi
225 ``` }
226_testcmd := if no-nextest == "" { "nextest run" } else { "test" }
227_loom-profile := if no-nextest == '' { '--cargo-profile loom' } else { '--profile loom' }
228
229_get-nextest:
230 #!/usr/bin/env bash
231 set -euo pipefail
232 source "./util/shell.sh"
233
234 if [ -n "{{ no-nextest }}" ]; then
235 status "Configured" "not to use cargo nextest"
236 exit 0
237 fi
238
239 if {{ _cargo }} --list | grep -q 'nextest'; then
240 status "Found" "cargo nextest"
241 exit 0
242 fi
243
244 err "missing cargo-nextest executable"
245 if confirm " install it?"; then
246 cargo install cargo-nextest
247 fi