1 #!/bin/bash
2 # Phase 1c: js/wasm compile sweep. Each package is its own unit.
3 #
4 # The wasm target has its own build tags (`//:build js && wasm`, `//:build unix
5 # || (js && wasm)`), so a package can compile natively and not for js - and
6 # phase 5 only builds fixtures with a main(), which never pulls in syscall/js or
7 # the js arms of internal/poll. Nothing compiled src/syscall/js at all until
8 # round 77, which is why its ten uses of `any` (a type Moxie does not have) sat
9 # unnoticed.
10 #
11 # A wasm library links without a main.main, so rc==0 is the pass condition.
12 set -uo pipefail
13 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
14 ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
15 source "$SCRIPT_DIR/util.sh"
16 source "$SCRIPT_DIR/split-util.sh"
17 18 # Packages that must compile for -target wasm.
19 UNITS=(
20 net/http
21 path/filepath
22 syscall/js
23 )
24 25 # A directory fixture is a unit too, with a `fixture:` prefix so the dispatch
26 # below knows to run it through run_fixture instead of the package path. The js
27 # bridge's mutator spelling lives here: the four mutators are package functions,
28 # and the fixture pins every one of them plus the non-addressable chain shape
29 # that a pointer receiver could not serve. It must be in UNITS, because that
30 # array IS the phase's unit list (tests/split-util.sh unit_list).
31 UNITS+=(
32 fixture:tests/wasmfixtures/jsbridge
33 )
34 35 # Packages known not to compile for wasm, with the reason. SKIP, never FAIL:
36 # the suite must not encode today's breakage as acceptable, but it must not go
37 # red for a defect that is already recorded either.
38 SWEEP_KNOWN=(
39 )
40 41 run_one() {
42 local pkg="$1" rc=0
43 unit_begin
44 MOXIEROOT="$ROOT" "$MOXIE" build -target wasm -o "$UNIT_WORK/out.wasm" "$ROOT/src/$pkg" \
45 >"$UNIT_WORK/build.log" 2>&1 || rc=$?
46 if [ "$rc" -eq 0 ]; then
47 unit_ok "wasm:$pkg" "compiles"
48 else
49 unit_no "wasm:$pkg" "$(first_error "$UNIT_WORK/build.log")"
50 fi
51 unit_exit
52 }
53 54 run_fixture() {
55 local dir="$1" rc=0
56 unit_begin
57 MOXIEROOT="$ROOT" "$MOXIE" build -target wasm -o "$UNIT_WORK/out.wasm" "$ROOT/$dir" \
58 >"$UNIT_WORK/build.log" 2>&1 || rc=$?
59 if [ "$rc" -eq 0 ]; then
60 unit_ok "wasm-fixture:$(basename "$dir")" "compiles"
61 else
62 unit_no "wasm-fixture:$(basename "$dir")" "$(first_error "$UNIT_WORK/build.log")"
63 fi
64 unit_exit
65 }
66 67 unit_args "$@"
68 69 echo ""
70 echo "=== Phase 1c: js/wasm compile sweep ==="
71 72 if [ -n "$UNIT_NAME" ]; then
73 case "$UNIT_NAME" in
74 fixture:*) run_fixture "${UNIT_NAME#fixture:}" ;;
75 *) run_one "$UNIT_NAME" ;;
76 esac
77 exit $?
78 fi
79 80 for u in "${UNITS[@]}"; do
81 case "$u" in
82 fixture:*) run_fixture "${u#fixture:}" ;;
83 *) run_one "$u" ;;
84 esac
85 done
86 87 if [ "${#SWEEP_KNOWN[@]}" -gt 0 ]; then
88 for entry in "${SWEEP_KNOWN[@]}"; do
89 pkg="${entry%%|*}"
90 reason="${entry#*|}"
91 log_skip "wasm:$pkg" "$reason"
92 done
93 fi
94