From a66f19190edc499494a903bdc4a6b58760ca110c Mon Sep 17 00:00:00 2001 From: Tomas Date: Thu, 27 Nov 2025 00:44:48 +0100 Subject: [PATCH] Increased build speed Instead of recompiling all of lunch source for each game, we generate source files containing the `main` function and default configuration for every game instead. --- config/template.build | 4 ++-- meson.build | 3 ++- prebuild.py | 14 ++++++++++++++ source/lunch/{main.d => app.d} | 11 +++++++---- source/lunch/conf.d | 11 +---------- source/lunch/launch.d | 3 ++- 6 files changed, 28 insertions(+), 18 deletions(-) rename source/lunch/{main.d => app.d} (91%) diff --git a/config/template.build b/config/template.build index 0541e9e..8f5f801 100644 --- a/config/template.build +++ b/config/template.build @@ -1,7 +1,7 @@ exec = executable( '$name', - lunch_src + windows.compile_resources(files('resource.rc')), + files('main.d') + windows.compile_resources(files('resource.rc')), include_directories: includes, d_import_dirs: ['.'], - link_with: [lua, luad, toml] + link_with: [lunch, lua, luad, toml] ) \ No newline at end of file diff --git a/meson.build b/meson.build index 30b16c0..c59925a 100644 --- a/meson.build +++ b/meson.build @@ -6,12 +6,12 @@ python3 = find_program('python3') lunch_src = files( + 'source/lunch/app.d', 'source/lunch/color.d', 'source/lunch/conf.d', 'source/lunch/http.d', 'source/lunch/launch.d', 'source/lunch/logger.d', - 'source/lunch/main.d', 'source/lunch/ui.d', 'source/lunch/update.d', ) @@ -89,6 +89,7 @@ source = d_source + c_source includes = include_directories('source') +lunch = static_library('lunch', lunch_src, include_directories: includes) toml = static_library('toml', toml_src, include_directories: includes) luad = static_library('luad', luad_src, include_directories: includes) lua = static_library('lua', lua_src, include_directories: includes) diff --git a/prebuild.py b/prebuild.py index 857d6da..4e1d9d0 100644 --- a/prebuild.py +++ b/prebuild.py @@ -108,6 +108,20 @@ for dirent in os.listdir("config"): "ICON\tICON\t\"icon.ico\"" ]) + # Generate source file + with open(pjoin(opath, "main.d"), "w") as file: + file.writelines([ + "module main;\n", + "\n", + "import lunch.app;\n", + "\n", + "\n", + "void main()\n", + "{\n", + " app(import(\"config.toml\"));\n", + "}\n", + ]) + # Generate meson file with open(pjoin(opath, "meson.build"), "w") as file: file.write(meson_template.substitute(dict(flat_config))) diff --git a/source/lunch/main.d b/source/lunch/app.d similarity index 91% rename from source/lunch/main.d rename to source/lunch/app.d index 89c1a2b..1798009 100644 --- a/source/lunch/main.d +++ b/source/lunch/app.d @@ -14,8 +14,11 @@ import lunch.update; import lunch.launch;; -void app() +void _app(string config_toml) { + // Load default config + wrapTOML(cast()config, config_toml.parseTOML()); + // Focus on exe chdir( thisExePath.dirName() ); @@ -64,7 +67,7 @@ void app() if (config.ui.config_dump) { - options ~= () { writeFile(config.app.config_name, default_config_toml); }; + options ~= () { writeFile(config.app.config_name, config_toml); }; writefln("[%d] %s", options.length, config.ui.config_dump_label); } @@ -93,11 +96,11 @@ void app() } -void main() +void app(string config_toml) { try { - app(); + _app(config_toml); } catch (Exception ex) { diff --git a/source/lunch/conf.d b/source/lunch/conf.d index 9f3146f..4b959e7 100644 --- a/source/lunch/conf.d +++ b/source/lunch/conf.d @@ -71,9 +71,7 @@ struct Config } -immutable string default_config_toml = import("config.toml"); -immutable Config default_config; -immutable Config config; +shared Config config; private string dash2minus(string str) @@ -149,10 +147,3 @@ Config parseConfig(string toml) @safe wrapTOML(config, doc); return config; } - - -shared static this() -{ - default_config = cast(immutable)parseConfig(default_config_toml); - config = default_config; -} diff --git a/source/lunch/launch.d b/source/lunch/launch.d index 8c7c424..57d63d9 100644 --- a/source/lunch/launch.d +++ b/source/lunch/launch.d @@ -10,6 +10,7 @@ import lunch.logger; version (Windows) { + pragma(lib, "User32"); import core.sys.windows.windows; } @@ -75,7 +76,7 @@ void launch() try { chdir(config.launcher.workdir); - Pid pid = spawnProcess(config.launcher.command); + Pid pid = spawnProcess(config.launcher.command.dup); wait(pid); } catch (Exception ex)