mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 15:49:57 -04:00
Compile the resources with windres when the install folder's path holds a space.
GNU windres runs its preprocessor through cmd.exe and, left to find it, puts the full path of the gcc beside it on that command line. When that path and the .rc's both hold a space (a Windows user name such as "Joe Budson"), cmd.exe drops the outer quotes and splits the command at the first space, so 0.5.0's Compile step failed with "'C:\Users\Joe' is not recognized". make_game.py, build_game.py and make_launcher.py now name gcc by bare name (the toolchain's bin is first on PATH) with windres's own preprocessor arguments, and make_game.py and make_launcher.py run windres in the .rc's folder with relative names. The objects are byte-identical to before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -191,6 +191,11 @@ INSTALL_SIDE = {'romfs.c', 'patches.c', 'ov_zstd.c', 'mouse_direct.c'}
|
||||
LIB_NAME = 'libnx2navirt.a'
|
||||
AR = UCRT / 'llvm-ar.exe' if WIN else on_path('llvm-ar')
|
||||
WINDRES = UCRT / 'windres.exe' # runtime/nx2navi.rc: the manifest of nx2navi.exe
|
||||
# GNU windres runs its preprocessor through cmd.exe, and left to find it names the gcc beside it by full path: once that
|
||||
# path and the .rc's both hold a space, cmd.exe drops the outer quotes and splits the command at the first space. gcc by
|
||||
# bare name (Ninja's PATH starts with UCRT) and the .rc by its path below MAIN_ROOT keep the command line free of
|
||||
# spaces. llvm-windres (--toolchain) starts its preprocessor without a shell and keeps its own.
|
||||
WINDRES_PP = '--preprocessor=gcc --preprocessor-arg=-E --preprocessor-arg=-xc --preprocessor-arg=-DRC_INVOKED'
|
||||
TOOLCHAIN_BIN = None # llvm-mingw bin directory, set by main() for --toolchain
|
||||
DEPS = None # the deps directory of an llvm-mingw build
|
||||
# tools/data/expected-<display version>.json for each build version name.
|
||||
@@ -405,7 +410,8 @@ def ninja_file(gen, out, mods, pool_depth, skip=(), prebuilt=False, runtime_lib=
|
||||
' description = CC $in',
|
||||
'',
|
||||
'rule rc',
|
||||
f' command = {cmd_arg(WINDRES.as_posix())} -I {cmd_path(RUNTIME)} -O coff $in -o $out',
|
||||
f' command = {cmd_arg(WINDRES.as_posix())}{"" if "llvm" in WINDRES.name else " " + WINDRES_PP} '
|
||||
f'-I {cmd_path(RUNTIME)} -O coff $in -o $out',
|
||||
' description = RC $in',
|
||||
'',
|
||||
'rule link',
|
||||
|
||||
@@ -76,6 +76,10 @@ LIFT_FIXES = [
|
||||
LINK_LIBS = ['-lvulkan-1', '-lSDL3', '-lopus', '-lvpx', '-l:libdav1d.a', '-lzstd', '-l:libatomic.a', '-lbcrypt',
|
||||
'-limm32', '-luuid', '-lole32', '-luser32', '-lshell32', '-lgdi32', '-ladvapi32', '-lwinmm']
|
||||
SYSTEM_DLLS_SKIP = {'vulkan-1.dll'} # the graphics driver's loader, never a copy
|
||||
# GNU windres's preprocessor, named explicitly: left to find it, windres puts the full path of the gcc beside it on a
|
||||
# cmd.exe command line, and once that path and the .rc's both hold a space, cmd.exe drops the outer quotes and splits
|
||||
# the command at the first space. gcc is then found on PATH (the toolchain's bin first); the arguments are windres's own.
|
||||
WINDRES_PP = ['--preprocessor=gcc', '--preprocessor-arg=-E', '--preprocessor-arg=-xc', '--preprocessor-arg=-DRC_INVOKED']
|
||||
EXE_NAME = 'ocarina.exe'
|
||||
|
||||
# Runs a script the way `python script.py` does, with the script's folder first on sys.path. The launcher's
|
||||
@@ -622,10 +626,12 @@ def step_compile(out, cache_dir, msys, jobs):
|
||||
fail(f'{len(bad)} files did not compile')
|
||||
|
||||
# the manifest (per-monitor DPI awareness: the picture at the monitor's real size, not one Windows stretches) and the
|
||||
# icon, runtime/nx2navi.rc through MSYS2's windres
|
||||
rco = obj / 'nx2navi_rc.o'
|
||||
r = subprocess.run([str(msys / 'bin' / 'windres.exe'), '-I', str(rt), '-O', 'coff', '-i', str(rt / 'nx2navi.rc'),
|
||||
'-o', str(rco)], capture_output=True, text=True, env=env, errors='replace')
|
||||
# icon, runtime/nx2navi.rc through MSYS2's windres. windres runs its preprocessor through cmd.exe: run from the
|
||||
# runtime folder with relative names and gcc by bare name (WINDRES_PP), that command line holds no path, so a space
|
||||
# in the install folder (a user name) cannot split it.
|
||||
rco = (obj / 'nx2navi_rc.o').resolve()
|
||||
r = subprocess.run([str(msys / 'bin' / 'windres.exe'), *WINDRES_PP, '-I', '.', '-O', 'coff', '-i', 'nx2navi.rc',
|
||||
'-o', str(rco)], capture_output=True, text=True, env=env, errors='replace', cwd=rt)
|
||||
if r.returncode:
|
||||
fail(f'windres failed on runtime/nx2navi.rc: {r.stderr.strip()[:400]}')
|
||||
objs = [o for _, o in srcs] + [rco]
|
||||
|
||||
@@ -201,10 +201,16 @@ def build_native(work, cc, windres):
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
(work / 'nx2navi.ico').write_bytes(art.triforce_ico())
|
||||
shutil.copy2(ROOT / 'launcher' / 'native' / 'app.manifest', work / 'app.manifest')
|
||||
res = work / 'res.o'
|
||||
# windres preprocesses with the gcc it finds on PATH: the toolchain's own bin first (no MSYS2 shell sets it)
|
||||
shutil.copy2(ROOT / 'launcher' / 'native' / 'res.rc', work / 'res.rc')
|
||||
res = (work / 'res.o').resolve()
|
||||
# MSYS2's GNU windres runs its preprocessor through cmd.exe and, left to find it, names the gcc beside it by full
|
||||
# path, which cmd.exe splits at a space once the .rc's path holds one too. So gcc by bare name, found on PATH (the
|
||||
# toolchain's own bin first; no MSYS2 shell sets it), and the .rc by its name in the work folder, where windres runs.
|
||||
# llvm-windres (Linux) starts its preprocessor without a shell.
|
||||
pp = [] if 'llvm' in Path(windres[0]).name else [
|
||||
'--preprocessor=gcc', '--preprocessor-arg=-E', '--preprocessor-arg=-xc', '--preprocessor-arg=-DRC_INVOKED']
|
||||
env = dict(os.environ, PATH=str(Path(windres[0]).parent) + os.pathsep + os.environ.get('PATH', ''))
|
||||
run([*windres, '-I', work, ROOT / 'launcher' / 'native' / 'res.rc', '-O', 'coff', '-o', res], env=env)
|
||||
run([*windres, *pp, '-I', '.', 'res.rc', '-O', 'coff', '-o', res], env=env, cwd=work)
|
||||
flags = ['-municode', '-mwindows', '-O2', '-Wall', '-static', '-s']
|
||||
stub = work / 'NX2navi.exe'
|
||||
setup = work / 'setup-stub.exe'
|
||||
|
||||
Reference in New Issue
Block a user