diff --git a/justfile b/justfile index 16a5b19..7426054 100644 --- a/justfile +++ b/justfile @@ -12,7 +12,7 @@ tcc := justfile_directory() + "/scripts/tcc/tcc" default: @just --list -# Build the vendored tinycc (third_party/tinycc) into _build/tcc, once. +# Build the vendored tinycc (third_party/tinycc) into _build/tcc, once. Optional: `just build` uses any tcc it can find. tcc-build: #!/usr/bin/env bash set -euo pipefail @@ -30,8 +30,9 @@ tcc-build: modules: scripts/build-modules.sh -# Debug build of the native compositor, compiled and linked with the vendored tcc. -build: tcc-build +# Debug build of the native compositor, compiled and linked with tcc ($TCC, the vendored build if present, or tcc on PATH). Never builds tcc itself. +build: + @{{tcc}} --which >/dev/null MOON_CC={{tcc}} MOON_STUB_CC={{tcc}} moon build --target native --warn-list -a compositor/bin # Optimised build with the system C compiler (slower to build, faster to run). @@ -101,7 +102,7 @@ view: build modules xdg-open _build/desktop.png # Time the native build (cold / warm / one-file edit), tcc vs system cc, on a temp copy: `just bench 5` or `just bench 3 "tcc cc cc-release"`. -bench runs="3" configs="tcc cc": tcc-build +bench runs="3" configs="tcc cc": scripts/bench-build.sh {{runs}} "{{configs}}" # Delete build output (compiled compositor, wasm modules, rendered frames) but keep the built tinycc in _build/tcc. diff --git a/scripts/bench-build.sh b/scripts/bench-build.sh index 567dd78..eb404a5 100755 --- a/scripts/bench-build.sh +++ b/scripts/bench-build.sh @@ -5,7 +5,7 @@ # incr rebuild after touching one source file (compositor/shell/shell.mbt, then lib/ui/ui.mbt) # Runs on a throwaway copy of the sources with its own target dir, so it never touches your # _build/ or the files other people are editing. The tcc configs use the repo's vendored tinycc -# (run `just tcc-build` first; its own one-time build is not part of these numbers). +# (any tcc scripts/tcc/tcc can find; see that script). # # scripts/bench-build.sh [runs=3] ["tcc cc cc-release"] # tcc debug build, compiled and linked with the vendored tinycc (what `just build` does) @@ -17,7 +17,7 @@ export PATH="$HOME/.moon/bin:$PATH" runs="${1:-3}" configs="${2:-tcc cc}" command -v moon >/dev/null || { echo "error: moon not found" >&2; exit 1; } -[ -x "$ROOT/_build/tcc/bin/tcc" ] || [ "$configs" = "cc" ] || { echo "error: run 'just tcc-build' first" >&2; exit 1; } +case " $configs " in *" tcc "*) "$ROOT/scripts/tcc/tcc" --which >/dev/null || exit 1 ;; esac work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT diff --git a/scripts/tcc/tcc b/scripts/tcc/tcc index 604fa50..bcee2c2 100755 --- a/scripts/tcc/tcc +++ b/scripts/tcc/tcc @@ -1,12 +1,26 @@ #!/usr/bin/env bash -# moon's C compiler/linker driver for debug builds: the vendored tinycc -# (third_party/tinycc, built by `just tcc` into _build/tcc). +# moon's C compiler/linker driver for debug builds. It never builds tcc; it uses one that exists: +# 1. $TCC, if set +# 2. the vendored tinycc, if already built (`just tcc-build` puts it in _build/tcc) +# 3. `tcc` on PATH (e.g. from `pixi install`, see pixi.toml) +# scripts/tcc/tcc --which prints the tcc it would use (exit 1 if none) # moon adds -DMOONBIT_NATIVE_NO_SYS_HEADER whenever the compiler is tcc; that # mode compiles the system parts of the runtime out (it expects to be JIT-ed # inside moon), so a standalone executable would not link. Drop it. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" -tcc="$root/_build/tcc/bin/tcc" +if [ -n "${TCC:-}" ]; then + tcc="$TCC" +elif [ -x "$root/_build/tcc/bin/tcc" ]; then + tcc="$root/_build/tcc/bin/tcc" +elif tcc="$(command -v tcc)"; then + : +else + echo "error: no tcc found. Install one (pixi install, or your package manager), set TCC=/path/to/tcc," >&2 + echo " or build the vendored one with: just tcc-build" >&2 + exit 127 +fi +if [ "${1:-}" = "--which" ]; then echo "$tcc"; exit 0; fi args=() for a in "$@"; do [ "$a" = "-DMOONBIT_NATIVE_NO_SYS_HEADER" ] || args+=("$a")