Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·157 lines (144 loc) · 6.41 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·157 lines (144 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
# Set up unkernel from a fresh clone: check prerequisites, then build
# everything (kwemu, patched wasm-ld, the UP and SMP kernels + their
# 32-bit-memory variants, Alpine initramfs and the bundle with the patch
# to the SMP kernel, Alpine disk image). The browser page (web/)
# needs its npm dependencies, which this script does not install: run
# bun install, then bun run dev.
#
# ./setup.sh check, then build (idempotent; re-run to resume)
# ./setup.sh --check only check prerequisites
#
# Environment: JOBS=n (parallelism), ZIG=/path/to/zig, KWEMU_JIT=0 (kwemu
# without its JIT tier), KW_SMP=0 (no SMP kernel; see kernel/build.sh). Downloads go to
# vendor/ (gitignored); nothing is installed outside the repository and
# nothing runs as root. Missing system packages are reported, not installed.
set -euo pipefail
. "$(dirname "$0")/kernel/tools/env.sh" # root, vendor, zig, real_bin, ...
cd "$root"
export PATH="$PATH:/usr/sbin:/sbin" # e2fsprogs live in sbin on some distros
missing=()
note() { printf ' %-13s %s\n' "$1" "$2"; }
fail() { note "$1" "MISSING: $2"; missing+=("$1"); }
# tool NAME [HINT]: NAME must be on PATH as a real executable; sets $bin.
# Only ELF binaries are run for version checks, so a wrapper script that
# installs packages on first use is never triggered by this script.
tool() {
bin="$(real_bin "$1")"
if [ -z "$bin" ]; then
fail "$1" "${2:-install it}"
return 1
fi
if [ "$(head -c 4 "$bin" | od -An -tx1 | tr -d ' \n')" != 7f454c46 ]; then
fail "$1" "only a wrapper script was found ($bin); install the real tool"
return 1
fi
}
check() {
local v t avail
echo "Checking prerequisites:"
if tool "${ZIG:-zig}" "Zig 0.17 from https://ziglang.org/download/ (or set ZIG=)"; then
v="$("$bin" version)"
case "$v" in 0.17.*) note zig "$v"; zig="$bin" ;; *) fail zig "need 0.17.x, have $v" ;; esac
fi
if tool bun "Bun >= 1.4.5 from https://bun.com/"; then
v="$("$bin" --version)"
if [[ ! "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || [ "$(printf '%s\n' 1.4.5 "$v" | sort -V | head -1)" != 1.4.5 ]; then
fail bun "need >= 1.4.5, have $v"
elif ! "$bin" -e 'import { checkJspi } from "./js/core/support.ts"; const result = await checkJspi(); if (!result.ok) throw new Error(result.why);'; then
fail bun "$v cannot suspend and resume WebAssembly with JSPI"
else
note bun "$v (JSPI ok)"
fi
fi
if tool clang "clang >= 21 with the WebAssembly target (22 tested)"; then
v="$("$bin" --version | sed -n 's/.*clang version \([0-9][0-9.]*\).*/\1/p' | head -1)"
if [ -z "$v" ] || [ "${v%%.*}" -lt 21 ]; then
fail clang "need >= 21, have ${v:-unknown}"
elif ! "$bin" --target=wasm64-unknown-unknown -c -x c /dev/null -o /dev/null 2>/dev/null; then
fail clang "$v cannot target wasm64 (no WebAssembly backend)"
else
note clang "$v (wasm64 ok)"
fi
fi
# clang++ and ld.lld build the patched wasm-ld; the llvm-* tools are used
# by the kernel build (ideally from the same LLVM as clang).
for t in clang++ ld.lld llvm-ar llvm-nm llvm-objcopy llvm-objdump llvm-ranlib llvm-readelf llvm-strip; do
tool "$t" "part of LLVM (clang, lld, llvm packages)" && note "$t" ok
done
for t in cmake ninja gcc make flex bison bc m4 python3 git curl tar gzip bzip2 sha256sum; do
tool "$t" && note "$t" ok
done
for t in mke2fs debugfs e2fsck; do
tool "$t" "e2fsprogs >= 1.43" && note "$t" ok
done
# kernel/guest/alpine-opt.sh, the guest packages rebuilt for kwemu (run by
# alpine.sh): meson for apk-tools (a Python program: only looked up),
# lua for apk's help text, perl modules for openssl's Configure.
for t in patch perl; do
tool "$t" && note "$t" ok
done
# Fedora's pkg-config is a shell script around the pkgconf binary.
t="$(real_bin pkgconf)"; [ -n "$t" ] || t="$(real_bin pkg-config)"
if [ -n "$t" ] && [ "$(head -c 4 "$t" | od -An -tx1 | tr -d ' \n')" = 7f454c46 ]; then
note pkg-config ok
else
fail pkg-config "install pkg-config or pkgconf"
fi
if [ -n "$(type -P meson)" ]; then
note meson ok
else
fail meson "install meson (alpine-opt.sh builds apk-tools with it)"
fi
if [ "$(uname -m)" != x86_64 ]; then
note alpine-opt "WARNING: its gcc toolchain is for x86_64 hosts; build with KW_ALPINE_OPT=0 (Alpine's builds)"
fi
t="$(real_bin lua5.4)"; [ -n "$t" ] || t="$(real_bin lua)"
if [ -n "$t" ] && [ "$(head -c 4 "$t" | od -An -tx1 | tr -d ' \n')" = 7f454c46 ]; then
note lua ok
else
fail lua "install lua 5.x (apk's help text)"
fi
if [ -n "$(real_bin perl)" ] && "$(real_bin perl)" -MFindBin -MIPC::Cmd -MFile::Compare -e 1 2>/dev/null; then
note perl-modules ok
else
fail perl-modules "perl with FindBin, IPC::Cmd and File::Compare (openssl's Configure)"
fi
avail="$(df -Pk "$root" | awk 'NR == 2 {print int($4 / 1048576)}')"
if [ ! -d "$vendor/src/llvm22" ] && [ "${avail:-0}" -lt 10 ]; then
note disk "WARNING: ${avail} GiB free; a full setup needs about 5 GiB"
fi
# Optional: the browser tests (web/test/*.mjs) need Chromium.
if [ -n "${CHROME:-}" ] || [ -n "$(real_bin chromium)" ] ||
ls "$HOME"/.cache/ms-playwright/chromium*/chrome*-linux64/chrome* >/dev/null 2>&1; then
note chromium "found (browser tests can run)"
else
note chromium "not found (optional, for browser tests: bunx --bun playwright install chromium-headless-shell, or set CHROME=)"
fi
if [ ${#missing[@]} -gt 0 ]; then
echo
echo "Missing or unusable: ${missing[*]}"
echo "Install them with your package manager, then re-run ./setup.sh."
return 1
fi
echo "All prerequisites found."
}
check || exit 1
[ "${1:-}" = --check ] && exit 0
start=$SECONDS
export ZIG="$zig"
echo
echo "== zig build (kwemu library with the JIT tier, test harness, test guests)"
# The same option kernel/build.sh passes, so it does not rebuild libkwemu.a.
"$zig" build -Dkwemu-jit="$([ "${KWEMU_JIT:-1}" = 0 ] && echo false || echo true)"
echo
echo "== kernel/build.sh all"
"$root/kernel/build.sh" all
echo
echo "Done in $(( (SECONDS - start) / 60 )) min $(( (SECONDS - start) % 60 )) s. Try:"
echo " bun js/cli.ts # Alpine shell, Ctrl-] quits"
echo ' bun js/cli.ts --append "console=hvc0 rdinit=/usr/bin/kwtest" # smoke test (kwtest as /init)'
echo " bun js/cli.ts --disk vendor/build/disk/alpine.ext4 # Alpine on ext4 (persistent)"
echo " bun install && bun run dev # browser: http://localhost:8080/"