|
| 1 | +#!/usr/bin/env bash |
| 2 | +# requires: llvm unix-shell |
| 3 | +# One source, one host, every machine the ecosystem serves. |
| 4 | +# |
| 5 | +# ⭐⭐ THIS IS CHEAP BECAUSE OF WHAT THE ECOSYSTEM IS, AND THAT IS THE POINT. |
| 6 | +# |
| 7 | +# A traditional stack needs a macOS runner to test macOS and a Windows runner |
| 8 | +# to test Windows, because the target side comes from a payload that only |
| 9 | +# exists there. Over openkal it comes from PACKAGES built from source by one |
| 10 | +# retargetable clang — so a single Linux machine can produce an artefact for |
| 11 | +# every target, and the shape of that artefact is checkable without leaving it. |
| 12 | +# Coverage that would cost six runners costs one loop. |
| 13 | +# |
| 14 | +# ⚠️ WHAT THIS FILE IS FOR IS BREADTH, NOT DEPTH. 286, 287 and 288 each go deep |
| 15 | +# on one arrangement — the native stack, the aarch64 cross with its |
| 16 | +# outline-atomics helpers, the machine with no operating system. This asserts |
| 17 | +# the one property they cannot: that a change to the engine did not silently |
| 18 | +# stop serving a target nobody happened to build that day. |
| 19 | +# |
| 20 | +# ⚠️ A TARGET THAT CANNOT BE BUILT HERE IS SKIPPED WITH ITS REASON, NEVER |
| 21 | +# PASSED OVER SILENTLY. A sweep whose failure mode is "produced no output" |
| 22 | +# would report success on a run that swept nothing. |
| 23 | +set -e |
| 24 | + |
| 25 | +MCPP="${MCPP:-mcpp}" |
| 26 | +work="$(mktemp -d)" |
| 27 | +trap 'rm -rf "$work"' EXIT |
| 28 | + |
| 29 | +# target | extra dependency lines | what `file` must say |
| 30 | +# |
| 31 | +# The dependency list is per-target because the platform layer is: openkal is |
| 32 | +# an interface and each machine has its own implementation of it. That the C |
| 33 | +# library and C++ runtime lines are IDENTICAL across every row is the claim the |
| 34 | +# ecosystem makes, and it is visible here as repetition rather than stated. |
| 35 | +rows=' |
| 36 | +x86_64-linux-musl|openkal-musl = "0.3.5"\nopenkal-llvm-runtime = "0.1.3"|ELF 64-bit LSB executable, x86-64|statically linked |
| 37 | +aarch64-linux-musl|openkal-musl = "0.3.5"\nopenkal-llvm-runtime = "0.1.3"|ELF 64-bit LSB executable, ARM aarch64|statically linked |
| 38 | +x86_64-windows-gnu|openkal-musl = "0.3.5"\nopenkal-llvm-runtime = "0.1.3"\nopenkal-windows = "0.1.5"|PE32+| |
| 39 | +riscv64-none-elf|openkal = "0.7.0"\nopenkal-opensbi = { version = "0.1.5", features = ["standalone"] }|ELF 64-bit LSB executable, UCB RISC-V|statically linked |
| 40 | +' |
| 41 | + |
| 42 | +built=0; skipped=0; failed=0 |
| 43 | +printf '\n' |
| 44 | +while IFS='|' read -r target deps want_fmt want_link; do |
| 45 | + [ -n "$target" ] || continue |
| 46 | + |
| 47 | + d="$work/$target"; mkdir -p "$d/src"; cd "$d" |
| 48 | + { |
| 49 | + printf '[package]\nname = "sweep"\nversion = "0.1.0"\n\n' |
| 50 | + printf '[toolchain]\ndefault = "llvm@22.1.8"\n\n' |
| 51 | + # ⚠️ `sysroot = ""` IS HOW A PROJECT SAYS "NO C LIBRARY", AND IT IS NOT |
| 52 | + # IMPLIED BY THE TARGET. `riscv64-none-elf` names a machine with no |
| 53 | + # operating system; whether the program has a C library is a separate |
| 54 | + # statement, and the ecosystem's own bare-metal example makes it. Left |
| 55 | + # out, the spec package's modules are compiled with exceptions enabled |
| 56 | + # and the platform package's `-fno-exceptions` sources then cannot read |
| 57 | + # the BMI: |
| 58 | + # |
| 59 | + # error: exception handling was enabled in precompiled file |
| 60 | + # 'openkal.stream.pcm' but is currently disabled |
| 61 | + case "$target" in |
| 62 | + *-none-*) printf '[target.%s]\nsysroot = ""\n\n' "$target" ;; |
| 63 | + esac |
| 64 | + printf '[dependencies]\n' |
| 65 | + printf "$deps\n" |
| 66 | + } > mcpp.toml |
| 67 | + |
| 68 | + # ⚠️ TWO SOURCES, BECAUSE TWO OF THESE TARGETS HAVE NO C LIBRARY TO PRINT |
| 69 | + # WITH. The bare-metal row reaches the platform interface directly; every |
| 70 | + # other row is an ordinary hosted program. Writing one source that works |
| 71 | + # everywhere would mean writing to the lowest common denominator, which is |
| 72 | + # not what a user of a hosted target does. |
| 73 | + case "$target" in |
| 74 | + *-none-*) |
| 75 | + cat > src/main.cpp <<'CPP' |
| 76 | +import openkal.stream; |
| 77 | +// `extern "C"` with the signature the platform's entry point calls: with |
| 78 | +// `-ffreestanding` the name is an ordinary symbol, not a special one. |
| 79 | +extern "C" int main(int, char**, char**) { |
| 80 | + const char m[] = "sweep\n"; |
| 81 | + kal_stream_write(kal_stdout(), m, sizeof m - 1); |
| 82 | + return 0; |
| 83 | +} |
| 84 | +CPP |
| 85 | + ;; |
| 86 | + *) |
| 87 | + cat > src/main.cpp <<'CPP' |
| 88 | +#include <cstdio> |
| 89 | +#include <string> |
| 90 | +int main() { |
| 91 | + std::string s = "sweep"; |
| 92 | + std::printf("%s\n", s.c_str()); |
| 93 | + return s.size() == 5 ? 0 : 1; |
| 94 | +} |
| 95 | +CPP |
| 96 | + ;; |
| 97 | + esac |
| 98 | + |
| 99 | + if ! out="$("$MCPP" build --target "$target" 2>&1)"; then |
| 100 | + case "$out" in |
| 101 | + *"not found in the synced index"*|*"install_packages failed"*) |
| 102 | + echo " SKIP $target — its packages are not reachable from here" |
| 103 | + skipped=$((skipped+1)); continue ;; |
| 104 | + *"cannot be built on this host"*) |
| 105 | + echo " SKIP $target — this host cannot build it" |
| 106 | + skipped=$((skipped+1)); continue ;; |
| 107 | + esac |
| 108 | + echo " FAIL $target — the build failed" |
| 109 | + printf '%s\n' "$out" | grep -iE 'error' | head -3 | sed 's/^/ /' |
| 110 | + failed=$((failed+1)); continue |
| 111 | + fi |
| 112 | + |
| 113 | + bin="$(find target -type f \( -name sweep -o -name sweep.exe \) | head -1)" |
| 114 | + if [ -z "$bin" ]; then |
| 115 | + echo " FAIL $target — the build reported success and produced nothing" |
| 116 | + failed=$((failed+1)); continue |
| 117 | + fi |
| 118 | + |
| 119 | + desc="$(file -b "$bin")" |
| 120 | + ok=1 |
| 121 | + case "$desc" in *"$want_fmt"*) ;; *) ok=0 ;; esac |
| 122 | + if [ -n "$want_link" ]; then |
| 123 | + case "$desc" in *"$want_link"*) ;; *) ok=0 ;; esac |
| 124 | + fi |
| 125 | + if [ "$ok" = 1 ]; then |
| 126 | + echo " ok $target → $want_fmt${want_link:+, $want_link}" |
| 127 | + built=$((built+1)) |
| 128 | + else |
| 129 | + echo " FAIL $target — wrong artefact" |
| 130 | + echo " want: $want_fmt${want_link:+ + $want_link}" |
| 131 | + echo " got: $desc" |
| 132 | + failed=$((failed+1)) |
| 133 | + fi |
| 134 | +done <<EOF |
| 135 | +$rows |
| 136 | +EOF |
| 137 | + |
| 138 | +printf '\n built %d, skipped %d, failed %d\n' "$built" "$skipped" "$failed" |
| 139 | + |
| 140 | +[ "$failed" = 0 ] || exit 1 |
| 141 | +# ⭐ AND A SWEEP THAT SWEPT NOTHING IS NOT A PASS. Every row skipping is the |
| 142 | +# signature of a machine that cannot reach the index at all, which is worth |
| 143 | +# reporting as a skip of the whole file rather than as success. |
| 144 | +if [ "$built" = 0 ]; then |
| 145 | + echo "SKIP: no target could be built here" |
| 146 | + exit 0 |
| 147 | +fi |
| 148 | + |
| 149 | +echo "OK: one host reached $built of the ecosystem's targets" |
0 commit comments