The CLI's shell commands go through shell(), which is run() on POSIX and a scratch script handed to Git for Windows' bash on Windows (exit codes read directly there). compile_app links through `ludicc -o` on Windows, ludic run starts the .exe, and ludic-dev build and ensure_ludicc assemble selfhost/ludicc.win.seed.ll, which ludic-dev reseed now writes beside the macOS seed. ludic bundle makes build/<name>/ with a GUI-subsystem exe carrying the .ico beside `app icon` as an llvm-rc resource, game.lpak and packs.index; ludicc gains --gui and --link, and quotes its whole link line for cmd.exe. Verified: ludic-dev test 135/135, selfhost-test 32/32; on the PC a checkout bootstraps from the Windows seed, ludic-dev build makes the toolchain, and `ludic bundle` makes build/Maroon Lake/, which runs from its own folder. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
94 lines
4.2 KiB
Text
94 lines
4.2 KiB
Text
# build.ludic — turning a .ludic file into an executable.
|
|
#
|
|
# compile_app is the one place that happens, shared by `ludic build` / `ludic
|
|
# run` and by the contributor tool, so a user's build and the repo's own example
|
|
# builds cannot drift apart. Everything the toolchain owns — the compiler, the
|
|
# engine runtime it splices — is addressed through ludic_home(), so the same code
|
|
# path works from a checkout and from an installed ~/.ludic.
|
|
|
|
# ensure bin/ludicc exists and is current with the seed. Built from the checked-in
|
|
# IR seed with clang alone — no C compiler is ever involved.
|
|
function ensure_ludicc() -> void {
|
|
if not in_toolchain_repo() { return }
|
|
shell("mkdir -p bin build")
|
|
let seed = seed_file()
|
|
let bin = `bin/{exe_name("ludicc")}`
|
|
if (not is_exec(bin)) or newer(seed, bin) {
|
|
print(`cc: {seed} -> {bin} (from the IR seed, no C compiler)`)
|
|
if not shq(`{cc()} {seed} -o {bin}`) {
|
|
err("ludic: could not assemble the seed\n"); exit(1)
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---- compiling one program to a native binary -------------------------------
|
|
#
|
|
# mode 1 = windowed (a game opens a real window), 2 = headless (the last frame is
|
|
# rendered to build/out.ppm from piped input — deterministic output for tests).
|
|
# Returns true on success. `ludic build`, `ludic run` and the contributor tool all
|
|
# go through here.
|
|
function compile_app(src: pointer, out: pointer, mode: int, save: bool) -> bool {
|
|
ensure_ludicc() # in a checkout: assemble the seed if bin/ludicc is missing or stale
|
|
let home = ludic_home()
|
|
let pbf = prebuilt_link_flags() # #64: link resolved prebuilt module dylibs, if any
|
|
let odir = dir_of_path(out)
|
|
if len(odir) > 0 { shell(`mkdir -p {odir}`) }
|
|
shell("mkdir -p build")
|
|
let ll = `{out}.ll`
|
|
|
|
# On Windows the compiler links too: ludicc knows the Windows runtime's files and
|
|
# libraries (win32.ll, xaudio2, opengl32 ...), so saying them again here would be a
|
|
# second copy to keep in step. It writes {out}.exe.
|
|
if host_windows() {
|
|
var flags = "--windowed"
|
|
if mode == 2 { flags = "--headless" }
|
|
if save { flags = flags + " --save-temps" }
|
|
return shq(`{ludicc()} {flags} {src} -o {out}`)
|
|
}
|
|
|
|
if mode == 2 {
|
|
if not shq(`{ludicc()} --headless {src} --emit-llvm -o {ll}`) { return false }
|
|
if not shq(`{cc()} -O2 {ll}{gl_link_flags(ll)}{pbf} -o {out}`) { return false }
|
|
if not save { shell(`rm -f {ll}`) }
|
|
return true
|
|
}
|
|
|
|
if not shq(`{ludicc()} --windowed {src} --emit-llvm -o {ll}`) { return false }
|
|
# audio.ll (#22) is always linked here — unused snd_* are dead-stripped; the
|
|
# canonical `ludicc -o` path links it only when Audio.* is used.
|
|
let cocoa = `{home}runtime/native/cocoa.ll`
|
|
let audio = `{home}runtime/native/audio.ll`
|
|
if not shq(`{cc()} -O2 {ll} {cocoa} {audio} -framework Cocoa -Wl,-needed_framework,GameController -Wl,-needed_framework,AVFoundation -Wl,-rpath,@loader_path{gl_link_flags(ll)}{pbf} -o {out}`) { return false }
|
|
if not save { shell(`rm -f {ll}`) }
|
|
return true
|
|
}
|
|
|
|
# A program that uses Gl.* references the @lgl_* thunks; link the OpenGL backend
|
|
# (gl.ll + gl_thunks.ll + OpenGL.framework) only then, so other builds are untouched.
|
|
function gl_link_flags(ll: pointer) -> pointer {
|
|
if not shq(`grep -q "@lgl_" {ll}`) { return "" }
|
|
let home = ludic_home()
|
|
return ` {home}runtime/native/gl.ll {home}runtime/native/gl_thunks.ll -framework OpenGL`
|
|
}
|
|
|
|
# the directory part of a path, without the trailing '/' ("" when there is none)
|
|
function dir_of_path(p: pointer) -> pointer {
|
|
var last = -1
|
|
var i = 0
|
|
while p[i] != 0 { if p[i] == '/' { last = i }; i += 1 }
|
|
if last < 0 { return "" }
|
|
return p[0..last]
|
|
}
|
|
|
|
# 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. Binaries in
|
|
# bin/ are kept so the running CLI survives; in the toolchain repo, rebuild them
|
|
# any time with `ludic-dev build`.
|
|
function cmd_clean() -> int {
|
|
shell("rm -rf build")
|
|
shell("rm -f out.ppm bin/*.tmp")
|
|
print("cleaned: build/ (incl. build/out.ppm) and stray artifacts (bin/ is left alone)")
|
|
return 0
|
|
}
|