- every scratch file lives in `$TMPDIR/x_<pid>/` (tmp_dir/tmp_path in prelude.ludic), removed by main's new dispatch() → tmp_cleanup(); X_KEEP_TMP=1 keeps it. `x test` and `x check-*` may now run together. - `x test-lsp` (tools/x/lsp_test.ludic) replaces tools/test-lsp.py: the whole request stream is framed into one stdin file, the server runs to `exit`, and the response stream is parsed back by request id; adds a check that ludicc's own error is published on save - tools/x/forgejo.ludic replaces tools/ci/forgejo_release.py (curl with a 0600 header file; the token is no longer on the command line; LUDIC_FORGEJO_API for forks) - `x docs-palette --check` regenerates into scratch and compares, so the drift guard judges the working tree rather than git HEAD; the generator no longer emits a trailing blank line the formatter rejects - `x test-tools`: exit 2 from test-lsp / test-grammar.js is a visible skip, never a pass; the widget-prop test uses the `id: Root` syntax - tools/test-grammar.js: current vocabulary (property/model/handler/ prefab/scene/event/become/@Queries), LUDIC_NODE_MODULES, exit 2 on skip - tools/atlas.ludic rewritten in the current language (it did not compile) - operators.ludic / os.ludic registered in the suite - json.ludic: j_quote() writer helper Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
101 lines
4.8 KiB
Text
101 lines
4.8 KiB
Text
# build.ludic — building the toolchain binaries and user programs.
|
|
#
|
|
# Replaces build-cli.sh (the ludicc/ludic front-end) and build.sh (compiling a
|
|
# Ludic program to a native app). All toolchain binaries land in bin/.
|
|
|
|
# compile a Ludic source to a native binary in bin/ via ludicc + clang (-O2).
|
|
# Returns true on success. Used for x itself and the editor tools.
|
|
function build_tool(name: pointer, src: pointer) -> bool {
|
|
let ll = `build/{name}.ll`
|
|
if not shq(`bin/ludicc {src} --emit-llvm -o {ll} 2>/dev/null`) { print(`build failed: {name} (compile)`); return false }
|
|
# write to a temp then move, so a running bin/x can rebuild itself in place
|
|
if not shq(`{cc()} -O2 {ll} -o bin/{name}.tmp`) { print(`build failed: {name} (link)`); return false }
|
|
run(`mv -f bin/{name}.tmp bin/{name} && rm -f {ll}`)
|
|
return true
|
|
}
|
|
|
|
# ---- build-cli: the self-hosted front-end binaries ---------------------------
|
|
# Both ludicc and ludic are the SAME multi-call binary assembled from the IR seed
|
|
# with clang alone; invoked as `ludic` it compiles-and-runs, as `ludicc` it just
|
|
# compiles.
|
|
function cmd_build_cli() -> int {
|
|
run("mkdir -p bin build")
|
|
print("cc: selfhost/ludicc.seed.ll -> bin/ludicc, bin/ludic (from the IR seed, no C compiler)")
|
|
if not shq(`{cc()} selfhost/ludicc.seed.ll -o bin/ludicc`) { err("x: seed did not assemble\n"); return 1 }
|
|
run("cp bin/ludicc bin/ludic && chmod +x bin/ludicc bin/ludic")
|
|
print("done. built bin/ludicc and bin/ludic")
|
|
return 0
|
|
}
|
|
|
|
# ---- build: the whole toolchain (ludicc, ludic, x, ludic-fmt, ludic-lsp) -----
|
|
function cmd_build() -> int {
|
|
if cmd_build_cli() != 0 { return 1 }
|
|
print("ludicc: tools/x/main.ludic -> bin/x (the task runner rebuilds itself)")
|
|
if not build_tool("x", "tools/x/main.ludic") { return 1 }
|
|
print("ludicc: tools/ludic-tools/fmt.ludic -> bin/ludic-fmt")
|
|
if not build_tool("ludic-fmt", "tools/ludic-tools/fmt.ludic") { return 1 }
|
|
print("ludicc: tools/ludic-tools/lsp.ludic -> bin/ludic-lsp")
|
|
if not build_tool("ludic-lsp", "tools/ludic-tools/lsp.ludic") { return 1 }
|
|
sync_vscode_grammar()
|
|
print("done. toolchain in bin/ (ludicc, ludic, x, ludic-fmt, ludic-lsp)")
|
|
return 0
|
|
}
|
|
|
|
# ---- app: compile a Ludic program to a native app ----------------------------
|
|
# usage: x app <file.ludic> [--headless|--windowed] [--save-temps]
|
|
# windowed is the default for a game; headless renders the last frame to
|
|
# build/out.ppm (never the repo root).
|
|
function cmd_app() -> int {
|
|
ensure_ludicc()
|
|
var src = null
|
|
var mode = 1 # 1 = windowed, 2 = headless
|
|
var save = false
|
|
var ai = 2
|
|
while ai < arg_count() {
|
|
let a = arg(ai)
|
|
if (a == "--headless") { mode = 2 }
|
|
else if (a == "--windowed") { mode = 1 }
|
|
else if (a == "--save-temps") { save = true }
|
|
else if (a[0] != '-') { src = a } # 45 = '-', so skip other flags
|
|
ai += 1
|
|
}
|
|
if (src == null) { err("usage: x app <file.ludic> [--headless] [--save-temps]\n"); return 1 }
|
|
let name = capture_line(`basename {src} .ludic`)
|
|
|
|
let pbf = prebuilt_link_flags() # #64: link resolved prebuilt module dylibs, if any
|
|
|
|
if (mode == 2) {
|
|
let outbin = `build/{name}_headless`
|
|
let ll = `{outbin}.ll`
|
|
print(`ludicc: {src} -> {outbin} (renders the last frame to build/out.ppm)`)
|
|
if not shq(`bin/ludicc --headless {src} > {ll}`) { return 1 }
|
|
if not shq(`{cc()} -O2 {ll}{pbf} -o {outbin}`) { return 1 }
|
|
if not save { run(`rm -f {ll}`) }
|
|
print(`done. run: mkdir -p build && printf 'ddss' | ./{outbin} && open build/out.ppm`)
|
|
return 0
|
|
}
|
|
|
|
let outbin = `build/{name}`
|
|
let ll = `{outbin}.ll`
|
|
print(`ludicc: {src} -> {outbin} (Ludic-written compiler -> LLVM IR -> windowed binary)`)
|
|
if not shq(`bin/ludicc --windowed {src} > {ll}`) { return 1 }
|
|
# audio.ll (#22) is always linked here for the dev runner — unused snd_* are
|
|
# dead-stripped; the canonical `ludicc -o` path links it only when Audio.* is used.
|
|
if not shq(`{cc()} -O2 {ll} runtime/native/cocoa.ll runtime/native/audio.ll -framework Cocoa -Wl,-needed_framework,GameController -Wl,-needed_framework,AVFoundation -Wl,-rpath,@loader_path{pbf} -o {outbin}`) { return 1 }
|
|
if not save { run(`rm -f {ll}`) }
|
|
print(`done. run: ./{outbin} (from the repo root, so assets/ resolves)`)
|
|
return 0
|
|
}
|
|
|
|
# Remove every generated artifact and leave the tracked source untouched: the
|
|
# whole build/ tree (IR, objects, compiled apps, the headless render at
|
|
# build/out.ppm), and any stray *.tmp/*.ll left behind by a failed build. A
|
|
# legacy out.ppm in the root (from an older toolchain) is swept too. The
|
|
# toolchain binaries in bin/ are kept so the running `x` survives; rebuild them
|
|
# any time with `x build`.
|
|
function cmd_clean() -> int {
|
|
run("rm -rf build")
|
|
run("rm -f out.ppm bin/*.tmp")
|
|
print("cleaned: build/ (incl. build/out.ppm), bin/*.tmp (bin/ toolchain kept — `x build` to rebuild)")
|
|
return 0
|
|
}
|