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.
This commit is contained in:
2025-11-27 00:44:48 +01:00
parent 46abfdeead
commit a66f19190e
6 changed files with 28 additions and 18 deletions

View File

@ -1,7 +1,7 @@
exec = executable( exec = executable(
'$name', '$name',
lunch_src + windows.compile_resources(files('resource.rc')), files('main.d') + windows.compile_resources(files('resource.rc')),
include_directories: includes, include_directories: includes,
d_import_dirs: ['.'], d_import_dirs: ['.'],
link_with: [lua, luad, toml] link_with: [lunch, lua, luad, toml]
) )

View File

@ -6,12 +6,12 @@ python3 = find_program('python3')
lunch_src = files( lunch_src = files(
'source/lunch/app.d',
'source/lunch/color.d', 'source/lunch/color.d',
'source/lunch/conf.d', 'source/lunch/conf.d',
'source/lunch/http.d', 'source/lunch/http.d',
'source/lunch/launch.d', 'source/lunch/launch.d',
'source/lunch/logger.d', 'source/lunch/logger.d',
'source/lunch/main.d',
'source/lunch/ui.d', 'source/lunch/ui.d',
'source/lunch/update.d', 'source/lunch/update.d',
) )
@ -89,6 +89,7 @@ source = d_source + c_source
includes = include_directories('source') includes = include_directories('source')
lunch = static_library('lunch', lunch_src, include_directories: includes)
toml = static_library('toml', toml_src, include_directories: includes) toml = static_library('toml', toml_src, include_directories: includes)
luad = static_library('luad', luad_src, include_directories: includes) luad = static_library('luad', luad_src, include_directories: includes)
lua = static_library('lua', lua_src, include_directories: includes) lua = static_library('lua', lua_src, include_directories: includes)

View File

@ -108,6 +108,20 @@ for dirent in os.listdir("config"):
"ICON\tICON\t\"icon.ico\"" "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 # Generate meson file
with open(pjoin(opath, "meson.build"), "w") as file: with open(pjoin(opath, "meson.build"), "w") as file:
file.write(meson_template.substitute(dict(flat_config))) file.write(meson_template.substitute(dict(flat_config)))

View File

@ -14,8 +14,11 @@ import lunch.update;
import lunch.launch;; import lunch.launch;;
void app() void _app(string config_toml)
{ {
// Load default config
wrapTOML(cast()config, config_toml.parseTOML());
// Focus on exe // Focus on exe
chdir( thisExePath.dirName() ); chdir( thisExePath.dirName() );
@ -64,7 +67,7 @@ void app()
if (config.ui.config_dump) 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); writefln("[%d] %s", options.length, config.ui.config_dump_label);
} }
@ -93,11 +96,11 @@ void app()
} }
void main() void app(string config_toml)
{ {
try try
{ {
app(); _app(config_toml);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -71,9 +71,7 @@ struct Config
} }
immutable string default_config_toml = import("config.toml"); shared Config config;
immutable Config default_config;
immutable Config config;
private string dash2minus(string str) private string dash2minus(string str)
@ -149,10 +147,3 @@ Config parseConfig(string toml) @safe
wrapTOML(config, doc); wrapTOML(config, doc);
return config; return config;
} }
shared static this()
{
default_config = cast(immutable)parseConfig(default_config_toml);
config = default_config;
}

View File

@ -10,6 +10,7 @@ import lunch.logger;
version (Windows) version (Windows)
{ {
pragma(lib, "User32");
import core.sys.windows.windows; import core.sys.windows.windows;
} }
@ -75,7 +76,7 @@ void launch()
try try
{ {
chdir(config.launcher.workdir); chdir(config.launcher.workdir);
Pid pid = spawnProcess(config.launcher.command); Pid pid = spawnProcess(config.launcher.command.dup);
wait(pid); wait(pid);
} }
catch (Exception ex) catch (Exception ex)