fix: CSPRNG on Windows, and a window's first title is the package's app name

Crypto.random_* and Uuid.* read /dev/urandom, which Windows lacks, so every
byte was zero; the Windows target now calls RtlGenRandom (advapi32).
ludicc takes --title, which ludic build/run/bundle pass from package.ludic's
app name, so rt_init opens the window under that name instead of the
program name.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-17 16:22:05 +03:00
parent 28f661c36f
commit 7f9f8de08a
9 changed files with 33592 additions and 33300 deletions

View file

@ -43,17 +43,17 @@ function compile_app(src: pointer, out: pointer, mode: int, save: bool) -> bool
var flags = "--windowed"
if mode == 2 { flags = "--headless" }
if save { flags = flags + " --save-temps" }
return shq(`{ludicc()} {flags} {src} -o {out}`)
return shq(`{ludicc()} {flags}{title_flag()} {src} -o {out}`)
}
if mode == 2 {
if not shq(`{ludicc()} --headless {src} --emit-llvm -o {ll}`) { return false }
if not shq(`{ludicc()} --headless{title_flag()} {src} --emit-llvm -o {ll}`) { return false }
if not shq(`{cc()} -O2 {ll}{gl_link_flags(ll)}{vk_link_flags(ll)}{http_link_flags(ll)}{udp_link_flags(ll)}{process_link_flags(ll)}{threads_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 }
if not shq(`{ludicc()} --windowed{title_flag()} {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`
@ -63,6 +63,21 @@ function compile_app(src: pointer, out: pointer, mode: int, save: bool) -> bool
return true
}
# ` --title "<app name>"` when the project's package.ludic names the app, so the window
# opens under that name rather than the `program` name; "" otherwise, and for a name the
# shell line could not carry safely.
function title_flag() -> pointer {
let name = manifest_app(read_root_manifest(), "name")
if name == "" { return "" }
var i = 0
while name[i] != 0 {
let c = name[i]
if c == '"' or c == '`' or c == '$' or c == 92 or c == '%' or c < ' ' { return "" }
i += 1
}
return ` --title "{name}"`
}
# 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 {

View file

@ -288,7 +288,7 @@ function cmd_bundle_windows() -> int {
let staged = tmp_path("bundle_exe")
var flags = "--windowed --gui"
if res != "" { flags = flags + ` --link "{res}"` }
if not shq(`{ludicc()} {flags} {entry} -o {staged}`) { return 1 }
if not shq(`{ludicc()} {flags}{title_flag()} {entry} -o {staged}`) { return 1 }
if not shq(`cp "{staged}.exe" "{root}/{name}.exe"`) {
err("ludic bundle: could not place the executable\n")
return 1