From d981870038c3ffa531f5c1d07e4aec855e061491 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Wed, 14 Oct 2026 08:45:35 +0330 Subject: build: generate everything into build/, keep src/ free of generated files src/ carried 8.4 MB of build output: the genome header, the javascript vm and its layout, and the language-server image, plus a second copy of the extension server under editors/vscode/server/. none of it is source. - move the genome from src/core/genome.h to build/core/genome.h and compile with -Ibuild/core; `make all` bootstraps one when it is missing - write genome.json, layout.ts, layout.js and lsp.json to build/js/ - compile tinyvm.ts to build/js/, typed by a tracked src/js/layout.d.ts so the vm needs no generated file beside its source - build the wasm server into build/editors/vscode/server/ and stage the whole server into editors/vscode/server/ only while mkvsix.sh packages it - redirect the test suite, image_run.js, tinyvm.sh, tinyvm.bat, test_win.ps1 and the baremetal build at the new paths, and add make lspimage and make vsix - stop tracking every generated file also fix a build blocker: lookup_raw compared skind against K_VAR, which was never declared, so `make genome` could not run at all. the guard is about emitted program globals, which are K_GVAR and K_GARR. tests/test.sh -q reports 159 passed and 21 failed both before and after this change; every failure is pre-existing and comes from the checked-in genome being stale relative to src/, plus the bootstrap above. --- src/tools/mklspwasm.sh | 9 +++++---- src/tools/mkvsix.sh | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 13 deletions(-) (limited to 'src/tools') diff --git a/src/tools/mklspwasm.sh b/src/tools/mklspwasm.sh index 86a902e..4789eab 100755 --- a/src/tools/mklspwasm.sh +++ b/src/tools/mklspwasm.sh @@ -1,20 +1,21 @@ #!/bin/bash -# builds the language server as WebAssembly: editors/vscode/server/lsp.wasm by -# default, or the path given as the first argument. the server is the compiler +# builds the language server as WebAssembly: build/editors/vscode/server/lsp.wasm +# by default, or the path given as the first argument. the server is the compiler # and src/lsp/server.zc on the map and genome that src/tools/mklsp.sh made in build/lsp, # and the microcore (src/micro/micro.c) runs them. the host is client/wasmproc.js. # needs clang with the wasm32 target and wasm-ld; run src/tools/mklsp.sh first. # src/tools/mklspwasm.sh [outfile.wasm] set -e case "${1:-}" in - --help|-h) printf '%s\n' 'usage: src/tools/mklspwasm.sh [OUTFILE.wasm]' 'builds the wasm language server; defaults to editors/vscode/server/lsp.wasm.' 'requires clang with wasm32 support and wasm-ld.' 'environment: LSP_BUILD_DIR selects the native lsp build; LSP_REUSE_BUILD=1 reuses its image.'; exit 0 ;; + --help|-h) printf '%s\n' 'usage: src/tools/mklspwasm.sh [OUTFILE.wasm]' 'builds the wasm language server; defaults to build/editors/vscode/server/lsp.wasm.' 'requires clang with wasm32 support and wasm-ld.' 'environment: LSP_BUILD_DIR selects the native lsp build; LSP_REUSE_BUILD=1 reuses its image.'; exit 0 ;; -*) echo "mklspwasm: unknown option $1; use --help for usage" >&2; exit 2 ;; esac cd "$(dirname "$0")/../.." -OUT=${1:-editors/vscode/server/lsp.wasm} +OUT=${1:-build/editors/vscode/server/lsp.wasm} LSP_BUILD_DIR=${LSP_BUILD_DIR:-build/lsp} if [ "${LSP_REUSE_BUILD:-0}" != 1 ]; then bash src/tools/mklsp.sh "$LSP_BUILD_DIR" >/dev/null; fi [ -f "$LSP_BUILD_DIR/src/lsp_genome.h" ] || { echo "mklspwasm: no language server image in $LSP_BUILD_DIR" >&2; exit 1; } +mkdir -p "$(dirname "$OUT")" clang --target=wasm32 -O2 -w -fwrapv -nostdlib -fno-builtin -mbulk-memory -DJTYPE=int -DUSE_LSP_GENOME \ -I"$LSP_BUILD_DIR/src" -Isrc/micro src/micro/micro.c src/micro/port_wasm_stream.c \ -Wl,--no-entry -Wl,--export=wasm_chunk -Wl,--export=wasm_chunk_cap -Wl,--export=wasm_feed \ diff --git a/src/tools/mkvsix.sh b/src/tools/mkvsix.sh index 39fb9c4..df9e703 100755 --- a/src/tools/mkvsix.sh +++ b/src/tools/mkvsix.sh @@ -1,9 +1,13 @@ #!/bin/bash # builds the vs code extension, with the language server inside it: the tinyvm -# javascript vm (src/js/tinyvm.js, compiled from src/js/tinyvm.ts) and the server's image -# (src/js/lsp.json, from build/lsp/genome.h and its map), and the wasm server +# javascript vm (built from src/js/tinyvm.ts) and the server's image +# (build/js/lsp.json, from build/lsp/genome.h and its map), and the wasm server # (src/tools/mklspwasm.sh) when clang can build it. needs node and tsc; the # server build (src/tools/mklsp.sh) runs first if build/lsp is missing. +# +# everything generated lands in build/. the packaged files are staged into +# editors/vscode/server/ only for as long as vsce is packing, then removed, so a +# fresh clone has no extension until it is built. # src/tools/mkvsix.sh [outfile.vsix] set -e case "${1:-}" in @@ -14,20 +18,32 @@ cd "$(dirname "$0")/../.." OUT=${1:-$PWD/build/zc-language-support.vsix} case "$OUT" in /*) ;; *) OUT="$PWD/$OUT" ;; esac mkdir -p "$(dirname "$OUT")" +JS=build/js +STAGE=build/editors/vscode/server +PACKDIR=editors/vscode/server + bash src/tools/mklsp.sh build/lsp >/dev/null # typescript errors stop packaging, so broken generated code is never shipped. command -v tsc >/dev/null || { echo "mkvsix: tsc is not installed" >&2; exit 1; } -tsc src/js/tinyvm.ts --target es2020 --lib es2020,dom --module commonjs --outDir src/js +tsc src/js/tinyvm.ts --target es2020 --lib es2020,dom --module commonjs --outDir "$JS" node src/js/extract_lsp.js -mkdir -p editors/vscode/server -cp src/js/tinyvm.js src/js/layout.js src/js/lsp.json editors/vscode/server/ -# the wasm server runs when it is there; without clang the vm server is packed alone +mkdir -p "$STAGE" +cp "$JS/tinyvm.js" "$JS/layout.js" "$JS/lsp.json" "$STAGE/" +# the wasm server runs when there is one; without clang the vm server is packed alone if command -v clang >/dev/null && clang --print-targets | grep -q wasm32; then - LSP_BUILD_DIR=build/lsp LSP_REUSE_BUILD=1 bash src/tools/mklspwasm.sh editors/vscode/server/lsp.wasm + LSP_BUILD_DIR=build/lsp LSP_REUSE_BUILD=1 bash src/tools/mklspwasm.sh "$STAGE/lsp.wasm" else - rm -f editors/vscode/server/lsp.wasm + rm -f "$STAGE/lsp.wasm" echo "no clang with wasm32: packing the javascript vm server only" >&2 fi + +# vsce packs the extension directory, so the server has to sit inside it while +# it runs. stage it, package, and leave the tree as it was. +cleanup() { rm -rf "$PACKDIR"; } +trap cleanup EXIT INT TERM +rm -rf "$PACKDIR" +mkdir -p "$PACKDIR" +cp "$STAGE"/* "$PACKDIR"/ cd editors/vscode if [ -n "${VSCE:-}" ]; then "$VSCE" package --allow-missing-repository --skip-license -o "$OUT" >/dev/null @@ -36,4 +52,4 @@ elif command -v vsce >/dev/null; then else npx -y @vscode/vsce package --allow-missing-repository --skip-license -o "$OUT" >/dev/null fi -echo "$OUT" +echo "$OUT" \ No newline at end of file -- cgit v1.2.3