From 7455e6b5114641b8d18dc67e0db88d4fec2264b5 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sat, 23 Dec 2023 17:44:45 -0800 Subject: [PATCH] Windows builds with ninja. --- tools/configure.py | 134 +++++++++++++++++++++++++++++++++++---------- windows/BUILD | 33 ++++++++++- 2 files changed, 136 insertions(+), 31 deletions(-) diff --git a/tools/configure.py b/tools/configure.py index 116af69..b71082e 100755 --- a/tools/configure.py +++ b/tools/configure.py @@ -107,45 +107,47 @@ WIN_LFLAGS64 = [ '/LIBPATH:"c:/Program Files (x86)/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64"', ] + WIN_LIBS +def Escape(path): + return path.replace(' ', '\\ ').replace('(', '\\(').replace(')', '\\)') + def LSQ(path): - return subprocess.check_output( - ['ls', path], stderr=subprocess.DEVNULL, shell=True).splitlines()[0] + return '"' + str(subprocess.check_output('ls ' + Escape(path), shell=True), 'ascii').splitlines()[0] + '"' PROGFILES = '/mnt/c/Program Files (x86)' MSVS = PROGFILES + '/Microsoft Visual Studio' MSKITS = PROGFILES + '/Windows Kits' -CL32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/cl.exe') -CL64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/cl.exe') -LINK32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/link.exe') -LINK64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/link.exe') -RC32 = LSQ(MSKITS + '/*/bin/*/x86/rc.exe') -RC64 = LSQ(MSKITS + '/*/bin/*/x64/rc.exe') +WIN_CL32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/cl.exe') +WIN_CL64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/cl.exe') +WIN_LINK32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/link.exe') +WIN_LINK64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/link.exe') +WIN_RC32 = LSQ(MSKITS + '/*/bin/*/x86/rc.exe') +WIN_RC64 = LSQ(MSKITS + '/*/bin/*/x64/rc.exe') D8 = LSQ('${HOME}/src/v8/v8/out/x64.release/d8') NODEJS = LSQ('/usr/bin/nodejs') output = f""" -version = {VERSION} -revision = {REVISION} src = ../ -cflags = {' '.join(CFLAGS)} -strip_args = {' '.join(STRIP_ARGS)} -libs = {' '.join(LIBS)} -cxx = g++ +VERSION = {VERSION} +REVISION = {REVISION} +CFLAGS = {' '.join(CFLAGS)} +STRIP_ARGS = {' '.join(STRIP_ARGS)} +LIBS = {' '.join(LIBS)} +CXX = g++ -CL32 = {CL32} -CL64 = {CL64} -LINK32 = {LINK32} -LINK64 = {LINK64} -RC32 = {RC32} -RC64 = {RC64} +WIN_CL32 = {WIN_CL32} +WIN_CL64 = {WIN_CL64} +WIN_LINK32 = {WIN_LINK32} +WIN_LINK64 = {WIN_LINK64} +WIN_RC32 = {WIN_RC32} +WIN_RC64 = {WIN_RC64} D8 = {D8} NODEJS = {NODEJS} -win_cflags = {' '.join(WIN_CFLAGS)} -win_lflags32 = {' '.join(WIN_LFLAGS32)} -win_lflags64 = {' '.join(WIN_LFLAGS64)} +WIN_CFLAGS = {' '.join(WIN_CFLAGS)} +WIN_LFLAGS32 = {' '.join(WIN_LFLAGS32)} +WIN_LFLAGS64 = {' '.join(WIN_LFLAGS64)} rule mkdir description = mkdir @@ -154,17 +156,51 @@ rule mkdir rule importation description = importation depfile = $out.dd - command = ../tools/importation.py -i $in -o $out -I . -I $src $options --depsout $depfile -DVERSION=$version -DREVISION=$revision + command = $src/tools/importation.py -i $in -o $out -I . -I $src $options --depsout $depfile -DVERSION=$VERSION -DREVISION=$REVERSION rule compile description = CXX depfile = $out.dd - command = $cxx $cflags $in -o $out $libs -MD -MF $depfile && strip $strip_args $out + command = $CXX $CFLAGS $in -o $out $LIBS -MD -MF $depfile && strip $STRIP_ARGS $out + +rule compile_win32 + description = WIN_CL32 + depfile = $out.dd + command = $src/tools/importation.py -i $in -o $out --no-out -I . -I $src --depsout $out.dd && $WIN_CL32 /nologo /c /Fo$out $WIN_CFLAGS $in >/dev/null + +rule compile_win64 + description = WIN_CL64 + depfile = $out.dd + command = $src/tools/importation.py -i $in -o $out --no-out -I . -I $src --depsout $out.dd && $WIN_CL64 /nologo /c /Fo$out $WIN_CFLAGS $in >/dev/null + +rule link_win32 + description = WIN_LINK32 + command = $WIN_LINK32 /nologo /OUT:$out $WIN_LFLAGS32 $in && chmod a+x $out + +rule link_win64 + description = WIN_LINK64 + command = $WIN_LINK64 /nologo /OUT:$out $WIN_LFLAGS64 $in && chmod a+x $out + +rule rc_win32 + description = WIN_RC32 + command = $WIN_RC32 /nologo /i $src /fo $out $in + +rule rc_win64 + description = WIN_RC64 + command = $WIN_RC64 /nologo /i $src /fo $out $in rule run description = RUN command = $in >$out +rule resize + description = RESIZE + command = convert -resize $size $in $out + +rule convert_image + description = IMAGE_CONVERT + command = convert $in $out + build gen: mkdir """ @@ -189,6 +225,7 @@ def Importation(target, source, header_mode='cpp', name=None, keep=False, deps=N output += f' options = {options}\n' if deps: output += f' depfile = {deps}\n' + return target def Esp32Optional(main_name, main_source, parts): @@ -204,16 +241,55 @@ def Esp32Optional(main_name, main_source, parts): implicit=['gen/esp32_' + i + '.h' for i, _ in parts]) -def Compile(target, source, implicit=[]): +def Simple(op, target, source, implicit=[]): global output outdir = os.path.dirname(target) implicit = ' '.join(implicit) - output += f'build {target}: compile {source} | {outdir} {implicit}\n' + output += f'build {target}: {op} {source} | {outdir} {implicit}\n' + return target -def Run(target, source): +def Compile(target, source, implicit=[]): + return Simple('compile', target, source, implicit) + + +def CompileW32(target, source, implicit=[]): + return Simple('compile_win32', target, source, implicit) + + +def CompileW64(target, source, implicit=[]): + return Simple('compile_win64', target, source, implicit) + + +def LinkW32(target, source, implicit=[]): + return Simple('link_win32', target, source, implicit) + + +def LinkW64(target, source, implicit=[]): + return Simple('link_win64', target, source, implicit) + + +def ResizeImage(target, source, size, implicit=[]): global output - output += f'build {target}: run {source}\n' + Simple('resize', target, source, implicit) + output += f' size={size}\n' + return target + + +def ConvertImage(target, source, implicit=[]): + return Simple('convert_image', target, source, implicit) + + +def CompileResource32(target, source, implicit=[]): + return Simple('rc_win32', target, source, implicit) + + +def CompileResource64(target, source, implicit=[]): + return Simple('rc_win64', target, source, implicit) + + +def Run(target, source, implicit=[]): + return Simple('run', target, source, implicit) def Include(path): diff --git a/windows/BUILD b/windows/BUILD index f38de89..e1f976b 100644 --- a/windows/BUILD +++ b/windows/BUILD @@ -12,5 +12,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -Importation('gen/windows_boot.h', '$src/windows/windows_boot.fs', header_mode='win', name='boot') -Importation('gen/windows_boot_extra.h', '$src/windows/windows_boot_extra.fs', header_mode='win', name='boot') +# Create boot. +Importation('gen/windows_boot.h', '$src/windows/windows_boot.fs', + header_mode='win', name='boot') +Importation('gen/windows_boot_extra.h', '$src/windows/windows_boot_extra.fs', + header_mode='win', name='boot_extra') + +# Compile Win32. +CompileW32('windows/uEf32.obj', '$src/windows/main.c', + implicit=['gen/windows_boot.h', 'gen/windows_boot_extra.h']) +LinkW32('windows/uEf32.exe', + ' '.join(['windows/uEf32.obj', 'resources/ueforth_res32.res'])) + +# Compile Win64. +CompileW64('windows/uEf64.obj', '$src/windows/main.c', + implicit=['gen/windows_boot.h', 'gen/windows_boot_extra.h']) +LinkW64('windows/uEf64.exe', + ' '.join(['windows/uEf64.obj', 'resources/ueforth_res64.res'])) + +# Create icon. +Mkdir('resources') +ICON_SIZES = [ + ResizeImage('resources/eforth16x16.png', '$src/images/eforth.png', '16x16'), + ResizeImage('resources/eforth32x32.png', '$src/images/eforth.png', '32x32'), + ResizeImage('resources/eforth48x48.png', '$src/images/eforth.png', '48x48'), + ResizeImage('resources/eforth256x256.png', '$src/images/eforth.png', '256x256'), +] +ConvertImage('resources/eforth.ico', ' '.join(ICON_SIZES)) +CompileResource32('resources/ueforth_res32.res', '$src/windows/ueforth.rc', + implicit=['resources/eforth.ico']) +CompileResource64('resources/ueforth_res64.res', '$src/windows/ueforth.rc', + implicit=['resources/eforth.ico'])