-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (121 loc) · 5.37 KB
/
Copy pathMakefile
File metadata and controls
134 lines (121 loc) · 5.37 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
.PHONY: build run tidy test clean wasm wasm-serve core-wasm core-smoke codelab-wasm codelab codelab-smoke host-wasm
PORT ?= 8765
WEB := web
WASM_OUT := $(WEB)/sim.wasm
CORE_OUT := $(WEB)/core.wasm
GOASM_OUT := $(WEB)/go6asm.wasm
GOASM_DIR ?= ../go6asm
EXEC_OUT := $(WEB)/wasm_exec.js
FOXPRO_OUT := $(WEB)/foxpro.js
HOST_DIR := $(WEB)/cpu-host
HOST_WASM := $(HOST_DIR)/host.wasm
GOROOT := $(shell go env GOROOT)
EXEC_SRC := $(firstword $(wildcard $(GOROOT)/lib/wasm/wasm_exec.js $(GOROOT)/misc/wasm/wasm_exec.js))
build:
go build -o bin/6502-sim ./cmd/6502-sim
run: build
./bin/6502-sim
# wasm — compile the browser build into web/ and copy the JS shim from
# the active Go toolchain. Re-run after editing any Go file; `go build`
# does its own dependency check so this is fast on no-op builds.
#
# foxpro.js is resolved at recipe time inside a single shell invocation:
# `go mod download` first guarantees the module is in $(GOMODCACHE),
# then `go list -m -f '{{.Dir}}'` returns the cache path. Computing
# this with `:=` at parse time fails on a fresh CI runner because the
# module isn't yet in the cache; computing with `=` (deferred) still
# proved unreliable when `go list -m` didn't populate the graph cache
# without an explicit `go mod download` first. So we just do both
# steps in one shell command, fail loudly if either step missed.
wasm:
@mkdir -p $(WEB)
GOOS=js GOARCH=wasm go build -o $(WASM_OUT) ./cmd/6502-wasm
@if [ -z "$(EXEC_SRC)" ]; then \
echo "ERROR: wasm_exec.js not found under $(GOROOT)/{lib,misc}/wasm/"; \
exit 1; \
fi
@cp $(EXEC_SRC) $(EXEC_OUT)
@set -e; \
go mod download github.com/carledwards/foxpro-go; \
src="$$(go list -m -f '{{.Dir}}' github.com/carledwards/foxpro-go)/wasm/foxpro.js"; \
if [ ! -f "$$src" ]; then \
echo "ERROR: foxpro.js not found at $$src"; \
exit 1; \
fi; \
cp "$$src" $(FOXPRO_OUT)
@ls -lh $(WASM_OUT) | awk '{print " built " $$NF " (" $$5 ")"}'
# core-wasm — the headless instrument bridge (cmd/6502-core-wasm). No
# foxpro.js: it ships no TUI, just the deterministic core behind a JS
# API. Only needs the Go wasm + the wasm_exec.js shim.
core-wasm:
@mkdir -p $(WEB)
GOOS=js GOARCH=wasm go build -o $(CORE_OUT) ./cmd/6502-core-wasm
@if [ -z "$(EXEC_SRC)" ]; then \
echo "ERROR: wasm_exec.js not found under $(GOROOT)/{lib,misc}/wasm/"; \
exit 1; \
fi
@cp $(EXEC_SRC) $(EXEC_OUT)
@ls -lh $(CORE_OUT) | awk '{print " built " $$NF " (" $$5 ")"}'
# core-smoke — build the core wasm and exercise the JS API end-to-end
# under Node (no browser needed). The carve's CI gate for the bridge.
core-smoke: core-wasm
@command -v node >/dev/null || { echo "node not installed"; exit 1; }
node $(WEB)/core-smoke.js
# codelab-wasm — build BOTH wasms the local CodeLab page drives: the
# go6sim headless core (this repo) and the go6asm assembler (sibling
# repo at $(GOASM_DIR)), into web/ next to wasm_exec.js. Local dev
# harness only — the deployed site builds these in CI from tags.
codelab-wasm: core-wasm
@if [ ! -d "$(GOASM_DIR)" ]; then \
echo "ERROR: go6asm not found at $(GOASM_DIR) (set GOASM_DIR=/path)"; exit 1; \
fi
cd $(GOASM_DIR) && GOOS=js GOARCH=wasm go build -o "$(CURDIR)/$(GOASM_OUT)" ./cmd/go6asm-wasm
@ls -lh $(GOASM_OUT) | awk '{print " built " $$NF " (" $$5 ")"}'
# codelab-smoke — headless end-to-end proof: both wasms on one runtime,
# assemble the 8-LED seed, run it, assert VIA Port B changes. The
# pipeline gate before any deploy wiring.
codelab-smoke: codelab-wasm
@command -v node >/dev/null || { echo "node not installed"; exit 1; }
node $(WEB)/codelab-smoke.js
# codelab — serve the local spike page (open codelab.html).
codelab: codelab-wasm
@echo "open http://localhost:$(PORT)/codelab.html"
@cd $(WEB) && python3 -m http.server $(PORT)
# wasm-serve — rebuild then local static server on PORT (default 8765).
# Depends on `wasm` so a one-step `make wasm-serve` always serves the
# latest binary. Open http://localhost:$(PORT)/ once it starts and
# HARD-REFRESH the browser (Cmd-Shift-R / Ctrl-Shift-R) to dodge the
# .wasm cache that otherwise loads stale builds.
wasm-serve: wasm
@echo "serving $(WEB)/ at http://localhost:$(PORT)/ (hard-refresh the browser)"
@cd $(WEB) && python3 -m http.server $(PORT)
# host-wasm — build the Remote-CPU host wasm (cmd/cpu-host-wasm) into
# web/cpu-host/ alongside the same JS shims wasm-serve uses. The
# files end up embedded into the TUI binary (web/cpu-host/embed.go)
# so a subsequent `go build ./cmd/6502-sim` bakes the latest host
# wasm into the TUI binary; then `./bin/6502-sim -cpu=remote
# -remote-addr :7777` serves the host page + the /cpu WebSocket from
# one port (open http://localhost:7777 in your browser).
host-wasm:
@mkdir -p $(HOST_DIR)
GOOS=js GOARCH=wasm go build -o $(HOST_WASM) ./cmd/cpu-host-wasm
@if [ -z "$(EXEC_SRC)" ]; then \
echo "ERROR: wasm_exec.js not found under $(GOROOT)/{lib,misc}/wasm/"; \
exit 1; \
fi
@cp $(EXEC_SRC) $(HOST_DIR)/wasm_exec.js
@set -e; \
go mod download github.com/carledwards/foxpro-go; \
src="$$(go list -m -f '{{.Dir}}' github.com/carledwards/foxpro-go)/wasm/foxpro.js"; \
if [ ! -f "$$src" ]; then \
echo "ERROR: foxpro.js not found at $$src"; \
exit 1; \
fi; \
cp "$$src" $(HOST_DIR)/foxpro.js
@ls -lh $(HOST_WASM) | awk '{print " built " $$NF " (" $$5 ")"}'
tidy:
go mod tidy
test:
go test ./...
clean:
rm -rf bin $(WASM_OUT) $(CORE_OUT) $(GOASM_OUT) $(EXEC_OUT) $(FOXPRO_OUT)