Repository navigation
Expand file tree
/
Copy pathpremake5.lua
More file actions
1061 lines (929 loc) · 42.2 KB
/
Copy pathpremake5.lua
File metadata and controls
1061 lines (929 loc) · 42.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
newoption { trigger = "module-validation", description = "Include backend-independent module smoke tests in this workspace." }
newoption
{
trigger = "core-validation",
description = "Generate an isolated core-only Engine workspace for CI validation."
}
ROOT_DIR = os.realpath(_MAIN_SCRIPT_DIR)
FunkeCoreValidationRoot = _OPTIONS["core-validation"]
and path.join(ROOT_DIR, "premake/generated/core")
or nil
-- Optional engine feature modules (Funke.2D, Funke.3D). Their source lists live in
-- Funke-Engine/EngineModules.json, shared with cmake/FunkeEngine.cmake.
FunkeFeatureModules = json.decode(io.readfile(path.join(ROOT_DIR, "Funke-Engine/EngineModules.json"))).modules
for _, featureModule in ipairs(FunkeFeatureModules) do
newoption
{
trigger = "without-" .. featureModule.option,
description = "Build a runtime variant without the " .. featureModule.id .. " engine module (isolated workspace under premake/generated/variant-*)."
}
end
local function ResolveFunkeEngineVariant()
local byId = {}
for _, featureModule in ipairs(FunkeFeatureModules) do
featureModule.Enabled = not _OPTIONS["without-" .. featureModule.option]
byId[featureModule.id] = featureModule
end
for _, featureModule in ipairs(FunkeFeatureModules) do
for _, dependency in ipairs(featureModule.dependencies or {}) do
if not byId[dependency].Enabled then featureModule.Enabled = false end
end
end
local included, excludedAny = {}, false
for _, featureModule in ipairs(FunkeFeatureModules) do
if featureModule.Enabled then table.insert(included, featureModule.option)
else excludedAny = true end
end
if not excludedAny then return nil end
return "v2-" .. (#included > 0 and table.concat(included, "-") or "nomodules")
end
-- A variant only builds the engine + runtime a game ships, into its own workspace and output
-- folders, so it never overwrites the full-engine projects the editor uses.
FunkeEngineVariant = ResolveFunkeEngineVariant()
FunkeVariantRoot = FunkeEngineVariant
and path.join(ROOT_DIR, "premake/generated/variant-" .. FunkeEngineVariant)
or nil
if FunkeVariantRoot and FunkeCoreValidationRoot then
error("--without-* module options cannot be combined with --core-validation")
end
FunkeIsolatedRoot = FunkeCoreValidationRoot or FunkeVariantRoot
-- Project files go to the isolated workspace root when one is active.
function FunkeProjectLocation(projectName, defaultLocation)
if FunkeIsolatedRoot then
return path.join(FunkeIsolatedRoot, projectName)
end
return defaultLocation
end
function IsFunkeFeatureModuleEnabled(moduleId)
for _, featureModule in ipairs(FunkeFeatureModules) do
if featureModule.id == moduleId then
return featureModule.Enabled
end
end
error("Unknown engine feature module '" .. tostring(moduleId) .. "'")
end
include "premake/compat.lua"
include "premake/architecture.lua"
workspace "Funke"
FunkeApplyArchitecture()
startproject ((FunkeCoreValidationRoot and "Funke-Engine") or (FunkeVariantRoot and "Funke-Runtime") or "Funke-Launcher")
if FunkeIsolatedRoot then
location(FunkeIsolatedRoot)
end
configurations
{
"Debug",
"Release",
"Dist"
}
filter { "system:windows", "language:C++" }
toolset "v143"
defines { "SPDLOG_WCHAR_FILENAMES" }
filter { "system:windows", "language:C++", "configurations:not Dist" }
-- /Z7 (DebugInformationFormat=OldStyle) instead of premake's defaults:
-- /ZI (Edit & Continue) for Debug and /Zi for Release.
--
-- /ZI is the most memory-hungry debug-info format and nothing in this
-- repo uses Edit & Continue. More importantly, both /ZI and /Zi funnel
-- every cl.exe through mspdbsrv.exe to serialise writes into a single
-- vc143.pdb per project. That is a parallelism bottleneck and the
-- source of `error C2471: cannot update program database` whenever
-- several projects compiled at once -- the reason whole-solution
-- builds had to run serially.
--
-- /Z7 embeds debug info directly in each .obj, so compilers never
-- contend for a PDB. The linker still emits a complete PDB for the
-- final binary, so breakpoints and stack traces are unchanged.
-- Trade-off: .obj files grow, so bin-int/ gets bigger. Dist is
-- excluded because it builds with symbols "Off" anyway.
debugformat "c7"
filter { "system:linux", "language:C++" }
-- GCC rejects a member named identically to its type (e.g. the
-- WindowSpecification / Log::Entry::Level fields in core headers) as a
-- [-Wchanges-meaning] error, where MSVC accepts it. It is functionally
-- harmless scope pedantry, so silence it for the whole GCC/Linux build
-- rather than renaming widely-used API members.
buildoptions { "-Wno-changes-meaning" }
filter { "system:macosx", "language:C++" }
-- App packaging expands library paths when moving binaries into MacOS and Frameworks.
linkoptions { "-Wl,-headerpad_max_install_names" }
filter "system:linux"
-- Every Linux artifact ultimately links into libFunke-Engine.so, so all
-- static deps (ImGui, Box2D, ...) must be position-
-- independent. Set it workspace-wide so no dependency is missed (Tracy
-- already sets it locally; this is harmless there).
pic "On"
filter {}
newoption
{
trigger = "sanitize",
description = "Instrument Linux Debug native targets with AddressSanitizer and UndefinedBehaviorSanitizer."
}
newoption
{
trigger = "coverage",
description = "Instrument an isolated Linux Debug native build for gcov/lcov coverage."
}
if _OPTIONS["core-validation"] and _OPTIONS["module-profile"] ~= "core" then
error("--core-validation requires --module-profile=core")
end
if _OPTIONS["core-validation"] and (_OPTIONS["sanitize"] or _OPTIONS["coverage"]) then
error("--core-validation cannot be combined with instrumentation variants")
end
if _OPTIONS["sanitize"] and _OPTIONS["coverage"] then
error("--sanitize and --coverage use separate isolated build variants")
end
local outputVariant = _OPTIONS["sanitize"] and "-sanitized"
or (_OPTIONS["coverage"] and "-coverage")
or (_OPTIONS["core-validation"] and "-core")
or (FunkeEngineVariant and ("-" .. FunkeEngineVariant) or "")
outputdir = "%{cfg.buildcfg}-%{cfg.system}-" .. FunkeArchitecture .. outputVariant
-- Module-independent outputs (ScriptCore) that a runtime variant reuses from the full build.
outputdirFull = "%{cfg.buildcfg}-%{cfg.system}-" .. FunkeArchitecture
if (_OPTIONS["sanitize"] or _OPTIONS["coverage"]) and os.target() ~= "linux" then
error("--sanitize and --coverage are supported only for Linux targets")
end
if _OPTIONS["sanitize"] then
filter { "system:linux", "language:C++", "configurations:Debug" }
buildoptions {
"-fsanitize=address,undefined",
"-fno-omit-frame-pointer",
"-fno-sanitize-recover=all"
}
linkoptions { "-fsanitize=address,undefined", "-fno-sanitize-recover=all" }
filter {}
end
if _OPTIONS["coverage"] then
filter { "system:linux", "language:C++", "configurations:Debug" }
buildoptions { "--coverage", "-fprofile-update=atomic", "-fno-omit-frame-pointer" }
linkoptions { "--coverage" }
filter {}
end
newoption
{
trigger = "with-imgui-demo",
description = "Include imgui_demo.cpp in the ImGui static library project."
}
newoption
{
trigger = "module-profile",
value = "PROFILE",
description = "Funke module profile: full (default compatibility), core, or custom. Supplying any --with-* option without this flag selects custom.",
allowed =
{
{ "full", "Compatibility profile: render, audio, physics, scripting, editor, and FUNKE_ALL_MODULES." },
{ "core", "Core-only profile: no optional module defines or third-party module dependencies." },
{ "custom", "Core-equivalent with no module flags, or the complete application surface with --with-editor." }
}
}
newoption { trigger = "with-render", description = "Select render in a custom profile; currently requires --with-editor." }
newoption { trigger = "with-audio", description = "Select audio in a custom profile; currently requires --with-editor." }
newoption { trigger = "with-physics", description = "Select physics in a custom profile; currently requires --with-editor." }
newoption { trigger = "with-scripting", description = "Enable scripting; custom profiles also require --with-editor." }
newoption { trigger = "with-editor", description = "Enable the editor and implicitly enable render, audio, physics, and scripting." }
newoption
{
trigger = "funke-project",
value = "PATH",
description = "Absolute path to a Funke project whose entityBits setting should configure the engine build. Project-local packages use premake/project-packages.lua."
}
newoption
{
trigger = "no-profiler",
description = "Strip the Funke profiler from every configuration. By default, Tracy and the profiler panel are available in Debug/Release; Dist is always profiler-free."
}
-- The engine has exactly one graphics backend (WebGPU via Dawn); the
-- runtime D3D12/Vulkan/Metal choice underneath Dawn is selected by Dawn
-- itself based on the adapter request in WebGPUApi.cpp::RequestAdapterSync.
-- Controls whether development configurations offer profiler support; Dist is always stripped.
FunkeProfiler = {}
FunkeProfiler.Enabled = not _OPTIONS["no-profiler"] and not FunkeCoreValidationRoot
require("premake/fix_csharp_platforms")
-- Surface DawnLayout (include / lib / define paths to the pre-built
-- webgpu_dawn.lib) BEFORE Dependencies.lua is loaded so EngineCoreRender
-- can splice the layout's lists into its own. dawn.lua is always loaded
-- — WebGPU is the only RHI, so a missing External/dawn/ checkout is a
-- real configuration error (scripts/dawn/SetupDawn.bat fixes it).
include "premake/dependencies/dawn.lua"
include "premake/dependencies/sdl3.lua"
include "Dependencies.lua"
local function HasExplicitModuleOption()
return _OPTIONS["with-render"]
or _OPTIONS["with-audio"]
or _OPTIONS["with-physics"]
or _OPTIONS["with-scripting"]
or _OPTIONS["with-editor"]
end
local function ResolveFunkeModules()
local profile = _OPTIONS["module-profile"]
if not profile then
profile = HasExplicitModuleOption() and "custom" or "full"
end
local modules =
{
Profile = profile,
FullCompatibility = profile == "full",
Render = false,
Audio = false,
Physics = false,
Scripting = false,
Editor = false
}
if profile == "full" then
modules.Render = true
modules.Audio = true
modules.Physics = true
modules.Scripting = true
modules.Editor = true
elseif profile == "custom" then
modules.Render = _OPTIONS["with-render"] or false
modules.Audio = _OPTIONS["with-audio"] or false
modules.Physics = _OPTIONS["with-physics"] or false
modules.Scripting = _OPTIONS["with-scripting"] or false
modules.Editor = _OPTIONS["with-editor"] or false
end
if modules.Editor then
modules.Render = true
modules.Audio = true
modules.Physics = true
modules.Scripting = true
end
if profile == "custom" and modules.Scripting and not modules.Editor then
error("--with-scripting requires --with-editor in a custom module profile.")
end
if profile == "custom"
and (modules.Render or modules.Audio or modules.Physics or modules.Scripting)
and not modules.Editor then
error("Partial custom module profiles are not supported; use --module-profile=core or add --with-editor (which enables the complete application surface).")
end
if FunkeVariantRoot and profile ~= "full" then
error("--without-* module options build a full-profile runtime variant; drop --module-profile/--with-*")
end
-- Feature modules sit on top of the application surface; a core build has neither.
local hasApplicationSurface = modules.Render
modules.TwoD = hasApplicationSurface and IsFunkeFeatureModuleEnabled("Funke.2D")
modules.ThreeD = hasApplicationSurface and IsFunkeFeatureModuleEnabled("Funke.3D")
modules.Physics2D = modules.Physics and modules.TwoD and IsFunkeFeatureModuleEnabled("Funke.Physics2D")
modules.Physics3D = modules.Physics and modules.ThreeD and IsFunkeFeatureModuleEnabled("Funke.Physics3D")
return modules
end
FunkeModules = ResolveFunkeModules()
-- The engine itself no longer depends on ImGui (the editor application owns its own
-- ImGui context as a Layer). EngineCoreEditor is therefore consumed only by the
-- editor and launcher executables, not by the engine static library.
--
-- Exception: engine.dll hosts the WebGPU-side ImGui backend
-- (Gui/ImGuiImplWebGPU.cpp, a thin wrapper around the official
-- imgui_impl_wgpu). It touches the wgpu::Device that lives in
-- WebGPUApi.cpp's TU, so it has to compile in the same module. The
-- consumer's ImGuiContext is synced into engine.dll's ImGui copy through
-- PackageImGuiBridge at every backend entry point (same pattern packages
-- already use).
Dependency.EngineSelectedModules = MergeDependencySets(
Dependency.EngineCore,
FunkeModules.Render and Dependency.EngineCoreEditor or nil,
FunkeModules.Render and Dependency.EngineCoreRender or nil,
FunkeModules.Audio and Dependency.EngineCoreAudio or nil,
FunkeModules.Physics2D and Dependency.EngineCorePhysics2D or nil,
FunkeModules.Physics3D and Dependency.EngineCorePhysics3D or nil,
FunkeModules.Scripting and Dependency.EngineCoreScripting or nil,
Dependency.EngineCoreLinuxSystem
)
Dependency.EditorRuntimeCommon = MergeDependencySets(
{
-- Funke-EditorRuntime is the StaticLib that holds shared editor /
-- launcher scaffolding (custom titlebar, ImGui context bring-up).
-- Both consumers compile and link the same source via this dep
-- set instead of duplicating the files into each binary.
IncludeDirs = { "%{IncludeDir.FunkeEditorRuntime}" },
DependsOn = { "Funke-Engine", "Funke-EditorRuntime" },
Links = { "Funke-Engine", "Funke-EditorRuntime" }
},
Dependency.EngineSelectedModules,
FunkeModules.Editor and Dependency.EngineCoreEditor or nil
)
-- Picks the EnTT entity/version bit-split from the active project's
-- project.json. Default is 20 — matches EnTT's stock split, so
-- existing projects pay no extra memory and behave identically to the
-- unpatched engine. Cached so repeated calls from each consumer's
-- premake5.lua don't re-parse the file. The vendored EnTT header at
-- External/entt/src/entt/entity/entity.hpp branches on the resulting
-- -DFUNKE_ENTITY_BITS=N to adjust entt_traits<uint32_t>::entity_mask /
-- version_mask.
--
-- Mirrors the FunkeProject::Load validator in
-- Funke-Engine/src/Project/FunkeProject.cpp so the premake-time and
-- runtime views of the setting stay in sync.
FunkeEntityBits = nil
function GetFunkeEntityBits()
if FunkeEntityBits ~= nil then
return FunkeEntityBits
end
local default = 20
local projectRootDir = _OPTIONS["funke-project"]
if not projectRootDir or projectRootDir == "" then
FunkeEntityBits = default
return FunkeEntityBits
end
local manifestPath = path.join(projectRootDir, "project.json")
if not os.isfile(manifestPath) then
FunkeEntityBits = default
return FunkeEntityBits
end
local file = io.open(manifestPath, "rb")
if not file then
FunkeEntityBits = default
return FunkeEntityBits
end
local jsonText = file:read("*all")
file:close()
if not jsonText then
FunkeEntityBits = default
return FunkeEntityBits
end
jsonText = jsonText:gsub("//[^\n]*", ""):gsub("/%*.-%*/", "")
local valueText = jsonText:match('"entityBits"%s*:%s*(%-?%d+)')
if not valueText then
FunkeEntityBits = default
return FunkeEntityBits
end
local bits = tonumber(valueText)
if bits == 16 or bits == 20 or bits == 22 or bits == 24 or bits == 28 then
FunkeEntityBits = bits
else
print("[Funke] project.json: entityBits=" .. tostring(valueText)
.. " is not one of {16, 20, 22, 24, 28}; falling back to 20.")
FunkeEntityBits = default
end
return FunkeEntityBits
end
-- Writes the generated header that the EnTT patch reads to override
-- FUNKE_ENTITY_BITS at compile time. The build-time -D in
-- GetFunkeModuleDefines() (and in package-loader.lua's RegisterNative-
-- Project) is the fallback; the header tracks the source build's
-- configured entity-bit width. Prebuilt packages keep their compiled value.
--
-- Layout:
-- Funke-Engine/src/Generated/FunkeEntityBitsConfig.h
--
-- Every C++ project that compiles entt-using code has this folder on its
-- include path (the four main projects + RegisterNativeProject). On
-- premake regen we always rewrite the header so its value tracks
-- project.json. If the file ever drifts from the -D, the header
-- wins (it #undef/#defines FUNKE_ENTITY_BITS).
FunkeEntityBitsConfigHeader = path.join(ROOT_DIR,
"Funke-Engine/src/Generated/FunkeEntityBitsConfig.h")
FunkeEntityBitsConfigIncludeDir = path.join(ROOT_DIR,
"Funke-Engine/src/Generated")
function WriteFunkeEntityBitsConfigHeader()
local bits = GetFunkeEntityBits()
os.mkdir(FunkeEntityBitsConfigIncludeDir)
local newContent =
"// Auto-generated by premake. Do not edit by hand.\n" ..
"// Overrides build-time -DFUNKE_ENTITY_BITS with the source build's\n" ..
"// configured EnTT entity/version bit split.\n" ..
"// See premake5.lua's WriteFunkeEntityBitsConfigHeader().\n" ..
"#pragma once\n" ..
"#undef FUNKE_ENTITY_BITS\n" ..
"#define FUNKE_ENTITY_BITS " .. tostring(bits) .. "\n"
-- Skip the write when the on-disk content already matches. Touching the
-- mtime here invalidates every TU that transitively includes entt (the
-- header sits on every entt-using project's include path), which is what
-- forces Visual Studio to recompile the world on every launcher-driven
-- premake regen.
local existing = io.open(FunkeEntityBitsConfigHeader, "rb")
if existing then
local current = existing:read("*all")
existing:close()
if current == newContent then return end
end
local file, err = io.open(FunkeEntityBitsConfigHeader, "wb")
if not file then
error("[Funke] cannot write " .. FunkeEntityBitsConfigHeader
.. " (" .. tostring(err) .. ")")
end
file:write(newContent)
file:close()
end
-- Run once at premake-time so the header exists before any project block
-- is processed.
WriteFunkeEntityBitsConfigHeader()
-- Reproduce the engine-owned changes in pinned upstream submodules.
-- Hash and path verification prevents dependency bumps from accepting stale patches.
require("premake/vendor-patches")
ApplyFunkeVendorPatches()
function GetFunkeModuleDefines()
local hasApplication = FunkeModules.Render
and FunkeModules.Audio
and FunkeModules.Scripting
and FunkeModules.Editor
local defines =
{
"FUNKE_WITH_RENDER=" .. (FunkeModules.Render and "1" or "0"),
"FUNKE_WITH_AUDIO=" .. (FunkeModules.Audio and "1" or "0"),
"FUNKE_WITH_PHYSICS=" .. (FunkeModules.Physics and "1" or "0"),
"FUNKE_WITH_SCRIPTING=" .. (FunkeModules.Scripting and "1" or "0"),
-- FUNKE_WITH_EDITOR is intentionally NOT emitted here: it varies per
-- build configuration (1 in Debug/Release so the workspace can host the
-- editor, 0 in Dist so shipped runtimes carry no editor systems). It is
-- applied by ApplyFunkeEditorModuleDefine() below, which every engine
-- consumer calls right after defines(GetFunkeModuleDefines()).
"FUNKE_WITH_APPLICATION=" .. (hasApplication and "1" or "0"),
"FUNKE_WITH_2D=" .. (FunkeModules.TwoD and "1" or "0"),
"FUNKE_WITH_3D=" .. (FunkeModules.ThreeD and "1" or "0"),
"FUNKE_WITH_PHYSICS2D=" .. (FunkeModules.Physics2D and "1" or "0"),
"FUNKE_WITH_PHYSICS3D=" .. (FunkeModules.Physics3D and "1" or "0"),
"FUNKE_ENTITY_BITS=" .. tostring(GetFunkeEntityBits()),
-- Shrink magic_enum's default reflection window [-128, 127] -> [-1, 64].
-- All engine-side reflected enums are small `enum class : uint8_t`
-- with sequential values in [0, ~16] (see Funke-Engine/src/Components/
-- and Funke-Engine/src/Graphics/Wrap.hpp for the only customized
-- range). The default window instantiates 256 template specializations
-- per reflected enum; ComponentInspectors.cpp reflects so many enums
-- via Properties::MakeWith<T>() that even 64-bit cl.exe runs out of
-- heap (C1060 in magic_enum.hpp). Shrinking the window cuts template
-- bloat ~4x. If a new enum exceeds [-1, 64], specialize
-- magic_enum::customize::enum_range<T> in its header (see
-- Funke-Engine/src/Graphics/Wrap.hpp for the existing pattern).
"MAGIC_ENUM_RANGE_MIN=-1",
"MAGIC_ENUM_RANGE_MAX=32"
}
if FunkeModules.FullCompatibility then
table.insert(defines, "FUNKE_ALL_MODULES=1")
end
return defines
end
-- Emits FUNKE_WITH_EDITOR per build configuration. MUST be called inside a
-- project block, right after defines(GetFunkeModuleDefines()).
--
-- Editor-support code in the engine (the PrefabTemplateCache .prefab watcher,
-- ProjectManager's cache hook, ...) is gated on `#if FUNKE_WITH_EDITOR`. It
-- compiles into Debug/Release so the dev workspace can host the editor, but is
-- stripped from Dist so a shipped runtime carries no editor-only systems.
-- When the workspace was generated without the editor module at all, it stays
-- off in every configuration.
--
-- Splitting it out per-config (rather than baking one value at premake time)
-- is safe for cross-DLL ODR: every binary in a single process is built in the
-- same configuration, so engine.dll and its consumers always agree on the
-- value (PrefabTemplateCache has an FUNKE_WITH_EDITOR-conditional member).
function ApplyFunkeEditorModuleDefine()
if FunkeModules.Editor then
filter "configurations:Dist"
defines { "FUNKE_WITH_EDITOR=0" }
filter "configurations:not Dist"
defines { "FUNKE_WITH_EDITOR=1" }
filter {}
else
defines { "FUNKE_WITH_EDITOR=0" }
end
end
function UseFunkeEngineModuleDependencies()
UseDependencySet(Dependency.EngineSelectedModules)
UseFunkeProfilerDependencies(true)
end
-- Shared postbuild command: copy FunkeAssets into each target output
-- directory. The single source tree is `Funke-Runtime/FunkeAssets/`,
-- staged via one {COPYDIR} next to the consumer exe.
CopyFunkeAssets = '{COPYDIR} "' .. path.join(ROOT_DIR, "Funke-Runtime/FunkeAssets") .. '" "%{cfg.targetdir}/FunkeAssets"'
local function SharedLibFileName(projectName)
if os.target() == "windows" then
return projectName .. ".dll"
elseif os.target() == "macosx" then
return "lib" .. projectName .. ".dylib"
end
return "lib" .. projectName .. ".so"
end
-- Copies a shared library next to a consumer. On Linux / macOS a changed library is replaced by a new file
-- (rm + cp) instead of being overwritten in place: a running editor may have the old one mapped, and
-- truncating a mapped library crashes it (the editor rebuilds the runtime with make while it runs).
function CopySharedLibFile(source, destination)
if os.target() == "windows" then
return '{COPYFILE} "' .. source .. '" "' .. destination .. '"'
end
return 'cmp -s "' .. source .. '" "' .. destination .. '" || { rm -f "' .. destination ..
'" && cp "' .. source .. '" "' .. destination .. '"; }'
end
local function CopySharedLib(projectName)
local fileName = SharedLibFileName(projectName)
return CopySharedLibFile(path.join(ROOT_DIR, "bin/" .. outputdir, projectName, fileName),
"%{cfg.targetdir}/" .. fileName)
end
local function RemoveSharedLib(projectName)
local target = "%{cfg.targetdir}/" .. SharedLibFileName(projectName)
if os.target() == "windows" then
return 'if exist "' .. target .. '" del /F /Q "' .. target .. '"'
end
return 'rm -f "' .. target .. '"'
end
-- Shared postbuild command: copy the engine SharedLib next to each consumer executable
-- so it resolves at runtime without depending on PATH.
local function DawnSharedLibFileName()
if os.target() == "macosx" then
return "libwebgpu_dawn.dylib"
end
return "libwebgpu_dawn.so"
end
CopyFunkeEngineDll = CopySharedLib("Funke-Engine")
CopyDawnSharedLib = ""
CopyNetHostSharedLib = ""
if os.target() == "macosx" then
CopyNetHostSharedLib = CopySharedLibFile(path.join(ROOT_DIR, "External/dotnet/lib/libnethost.dylib"),
"%{cfg.targetdir}/libnethost.dylib")
end
if FunkeModules.Render and os.target() ~= "windows" then
local dawnSharedLib = DawnSharedLibFileName()
CopyDawnSharedLib = CopySharedLibFile(path.join(ROOT_DIR, "External/dawn/build/src/dawn/native", dawnSharedLib),
"%{cfg.targetdir}/" .. dawnSharedLib)
end
-- The Funke-GameComponents sidecar DLL is removed — user components now
-- register at runtime via DynamicComponentRegistrar in Funke-ScriptCore.
-- No per-project codegen artifact gets shipped alongside consumer exes.
CopyFunkeGameComponentsDll = "" -- retained as a no-op so any leftover postbuild reference stays harmless
-- Consumers load private ScriptCore copies so its shared build output remains replaceable while they run.
local function CopyScriptCoreArtifact(filename)
return '{COPYFILE} "' ..
path.join(ROOT_DIR, "bin/" .. (FunkeVariantRoot and outputdirFull or outputdir), "Funke-ScriptCore", filename) ..
'" "%{cfg.targetdir}/' .. filename .. '"'
end
CopyScriptCoreArtifacts = {
CopyScriptCoreArtifact("Funke-ScriptCore.dll"),
CopyScriptCoreArtifact("Funke-ScriptCore.runtimeconfig.json"),
CopyScriptCoreArtifact("Funke-ScriptCore.deps.json"),
}
-- Editor-only in-process hot-reload compiler (Funke-ScriptCompiler, a dotnet-built project outside the
-- solution). Optional: without it the editor falls back to dotnet build.
if os.target() == "windows" then
local scriptCompilerDir = path.translate(path.join(ROOT_DIR, "bin/" .. outputdir, "Funke-ScriptCompiler"), "\\")
CopyScriptCompilerArtifacts = { 'if exist "' .. scriptCompilerDir .. '\\Funke-ScriptCompiler.dll" xcopy /Y /Q /I "' ..
scriptCompilerDir .. '\\Funke-ScriptCompiler.*" "%{cfg.targetdir}\\ScriptCompiler\\" >nul' }
else
-- Funke-Managed (below) always builds it on Linux / macOS.
local scriptCompilerDir = path.join(ROOT_DIR, "bin/" .. outputdir, "Funke-ScriptCompiler")
CopyScriptCompilerArtifacts = { '{MKDIR} "%{cfg.targetdir}/ScriptCompiler"' }
for _, file in ipairs({ "Funke-ScriptCompiler.dll", "Funke-ScriptCompiler.deps.json", "Funke-ScriptCompiler.runtimeconfig.json" }) do
table.insert(CopyScriptCompilerArtifacts,
'{COPYFILE} "' .. path.join(scriptCompilerDir, file) .. '" "%{cfg.targetdir}/ScriptCompiler/' .. file .. '"')
end
end
-- Materialize a self-contained EngineSDK/ folder next to the Launcher exe
-- so the zipped Launcher can build new projects' NativeScripts (which
-- generate a CMakeLists.txt that hard-references ${FUNKE_DIR}/Funke-Engine/
-- src and ${FUNKE_DIR}/External/... — see BuildNativeScriptCMakeLists in
-- Funke-Engine/src/Project/FunkeProject.cpp). ResolveEngineRoot() picks up
-- the bundled SDK ahead of the dev-layout fallbacks. The script is a thin
-- batch wrapper around robocopy so the lua stays free of per-folder copy
-- spam; see scripts/CopyEngineSdk.bat for the actual copy list.
if os.target() == "windows" then
CopyEngineSdk = 'call "' .. path.join(ROOT_DIR, "scripts/CopyEngineSdk.bat") ..
'" "%{cfg.targetdir}/EngineSDK" "' .. ROOT_DIR ..
'" "' .. path.join(ROOT_DIR, "bin/" .. outputdir) .. '"'
else
CopyEngineSdk = FunkePython() .. ' "' .. path.join(ROOT_DIR, "scripts/CopyEngineSdk.py") ..
'" "%{cfg.targetdir}/EngineSDK" "' .. ROOT_DIR ..
'" "' .. path.join(ROOT_DIR, "bin/" .. outputdir) .. '"'
end
-- Managed projects consumers depend on: the solution's C# projects on Windows, the Funke-Managed
-- utility (scripts/BuildManaged.py) on Linux / macOS where gmake2 cannot build SDK-style projects.
function FunkeManagedDependencies(windowsProjects)
if os.target() == "windows" then
return windowsProjects
end
return { "Funke-Managed" }
end
-- SDL3 is a shared library so engine.dll and the consumer executables share one copy
-- of its global state. Each consumer ships it alongside its binary.
CopySDL3SharedLib = CopySharedLibFile(path.join(ROOT_DIR, SDL3Layout.SharedLibPath),
"%{cfg.targetdir}/" .. SDL3Layout.SharedLibFileName)
-- Tracy is process-wide and ships only beside profiler-enabled development binaries.
if FunkeProfiler and FunkeProfiler.Enabled then
CopyTracyDll = CopySharedLib("Tracy")
else
CopyTracyDll = ""
end
RemoveTracyDll = RemoveSharedLib("Tracy")
function ApplyFunkeProfilerRuntime()
if FunkeProfiler and FunkeProfiler.Enabled then
filter "configurations:not Dist"
postbuildcommands { CopyTracyDll }
filter "configurations:Dist"
postbuildcommands { RemoveTracyDll }
else
postbuildcommands { RemoveTracyDll }
end
filter {}
end
local function NormalizeRootPath(pathValue)
if path.isabsolute(pathValue) then
return pathValue
end
return path.join(ROOT_DIR, pathValue)
end
local function NormalizeRootPaths(paths)
local normalized = {}
for _, pathValue in ipairs(paths) do
table.insert(normalized, NormalizeRootPath(pathValue))
end
return normalized
end
-- Apply per-config libdirs pointing at Dawn's Debug vs Release output
-- folders. Call once inside a project block; the filter context resets
-- afterwards so subsequent project config isn't accidentally scoped.
--
-- `rootRelPrefix` is the path prefix to prepend so the (repo-root-
-- relative) Dawn build directory resolves correctly from the consumer's
-- own premake working directory. Top-level project folders (Funke-Engine/,
-- Funke-Editor/, etc.) need "../"; deeper folders (Tests/Funke-Engine-
-- Tests/) need "../../" — caller picks.
--
-- Why per-config: webgpu_dawn.lib lives in both `Debug/` and `Release/`
-- subdirectories with /MDd vs /MD runtime selection respectively. Linking
-- the wrong-config lib into an /MDd Debug engine produces LNK2038
-- "RuntimeLibrary" + "_ITERATOR_DEBUG_LEVEL" mismatch errors.
function ApplyDawnLibDirs(rootRelPrefix)
local p = rootRelPrefix or "../"
filter "configurations:Debug"
libdirs { p .. "External/dawn/build/src/dawn/native/Debug" }
filter "configurations:Release"
libdirs { p .. "External/dawn/build/src/dawn/native/Release" }
filter "configurations:Dist"
libdirs { p .. "External/dawn/build/src/dawn/native/Release" }
filter {}
-- Single-config generators (Make / Ninja — i.e. the Linux + macOS builds,
-- and CI) emit the lib straight into .../native/ with no per-config
-- subfolder, so the per-config dirs above never match there. Add the bare
-- path for every config as a fallback. On Windows (multi-config VS) the
-- bare .../native/ holds no webgpu_dawn lib — the libs live in the Debug/
-- and Release/ subfolders above — so this is a harmless search-path miss
-- with no LNK2038 risk. On Linux a Debug engine linking the Release .a is
-- fine: libstdc++ has no _ITERATOR_DEBUG_LEVEL ABI split, unlike MSVC's
-- /MDd vs /MD. This is what lets CI build Release Dawn once and link it
-- into both the Release and Debug engine builds.
libdirs { p .. "External/dawn/build/src/dawn/native" }
end
-- True when an engine-shipped package with this name is installed on disk —
-- its manifest is present at <repo>/packages/<Name>/funke-package.lua. The
-- package loader (premake/package-loader.lua) registers exactly those, so this
-- is a faithful "will the Pkg.<Name> project exist in the workspace?" predicate.
-- It checks the filesystem rather than loader state, so a consumer's premake5.lua
-- can call it even though packages are loaded last. Lets a sample opt into a
-- package link only when the package is actually present, so a checkout without
-- it (CI, a fresh clone, a user who hasn't fetched it from the registry) builds
-- clean instead of emitting MSB3245 for an unresolvable assembly reference.
function FunkeEnginePackageInstalled(name)
return os.isfile(path.join(ROOT_DIR, "packages", name, "funke-package.lua"))
end
function UseDependencySet(dep)
if dep.IncludeDirs then
includedirs(NormalizeRootPaths(dep.IncludeDirs))
end
if dep.LibDirs then
libdirs(NormalizeRootPaths(dep.LibDirs))
end
if dep.DependsOn then
dependson(dep.DependsOn)
end
if dep.Links then
links(dep.Links)
end
if dep.Defines then
defines(dep.Defines)
end
end
-- Variant for intermediate StaticLib projects whose consumer .exe handles
-- the linking. Skips LibDirs and Links because MSVC's lib.exe MERGES input
-- .lib files into the output archive (it doesn't just record references).
-- Routing Links onto a StaticLib's <Lib><AdditionalDependencies> bloats the
-- resulting .lib by the combined size of every transitively-listed static
-- lib — e.g. webgpu_dawn.lib is ~185 MB Release / ~1.36 GB Debug, and ends
-- up archived wholesale inside the consuming StaticLib if links() is called.
-- Headers, dependson() (build-order), and defines() are still applied so the
-- TUs in this lib see the same include paths / preprocessor surface as the
-- consumer .exes that link the actual dependencies.
function UseDependencySetNoLink(dep)
if dep.IncludeDirs then
includedirs(NormalizeRootPaths(dep.IncludeDirs))
end
if dep.DependsOn then
dependson(dep.DependsOn)
end
if dep.Defines then
defines(dep.Defines)
end
end
function UseFunkeProfilerDependencies(linkTracy)
if not (FunkeProfiler and FunkeProfiler.Enabled) then
return
end
filter "configurations:not Dist"
if linkTracy then
UseDependencySet(Dependency.Profiler)
else
UseDependencySetNoLink(Dependency.Profiler)
end
filter {}
end
group "Dependencies"
if FunkeModules.Render then
project "ImGui"
location (FunkeProjectLocation("ImGui", path.join(ROOT_DIR, "premake/generated/ImGui")))
kind "StaticLib"
language "C++"
cppdialect "C++20"
staticruntime "off"
targetdir (path.join(ROOT_DIR, "bin/" .. outputdir .. "/%{prj.name}"))
objdir (path.join(ROOT_DIR, "bin-int/" .. outputdir .. "/%{prj.name}"))
files
{
-- Core
"External/imgui/imconfig.h",
"External/imgui/imgui.h",
"External/imgui/imgui_internal.h",
"External/imgui/imstb_rectpack.h",
"External/imgui/imstb_textedit.h",
"External/imgui/imstb_truetype.h",
"External/imgui/imgui.cpp",
"External/imgui/imgui_draw.cpp",
"External/imgui/imgui_tables.cpp",
"External/imgui/imgui_widgets.cpp",
-- Backends:
-- * imgui_impl_sdl3 — used by editor / launcher / runtime
-- executables for input + window-event plumbing.
-- * imgui_impl_wgpu — used by engine.dll via
-- Gui/ImGuiImplWebGPU.cpp for in-engine ImGui draws on the
-- shared wgpu::Device. Headers are reachable through
-- Dependency.ImGui below (DawnLayout spliced in).
"External/imgui/backends/imgui_impl_sdl3.h",
"External/imgui/backends/imgui_impl_sdl3.cpp",
"External/imgui/backends/imgui_impl_wgpu.h",
"External/imgui/backends/imgui_impl_wgpu.cpp"
}
if _OPTIONS["with-imgui-demo"] then
files { "External/imgui/imgui_demo.cpp" }
end
vpaths
{
["Core/*"] =
{
"External/imgui/imconfig.h",
"External/imgui/imgui.h",
"External/imgui/imgui_internal.h",
"External/imgui/imstb_rectpack.h",
"External/imgui/imstb_textedit.h",
"External/imgui/imstb_truetype.h",
"External/imgui/imgui.cpp",
"External/imgui/imgui_draw.cpp",
"External/imgui/imgui_tables.cpp",
"External/imgui/imgui_widgets.cpp"
},
["Backends/*"] =
{
"External/imgui/backends/imgui_impl_sdl3.h",
"External/imgui/backends/imgui_impl_sdl3.cpp",
"External/imgui/backends/imgui_impl_wgpu.h",
"External/imgui/backends/imgui_impl_wgpu.cpp"
},
["Optional/*"] = { "External/imgui/imgui_demo.cpp" }
}
UseDependencySet(Dependency.ImGui)
-- The WebGPU backend's surface helper uses Cocoa / CAMetalLayer on macOS.
filter { "system:macosx", "files:**/imgui_impl_wgpu.cpp" }
compileas "Objective-C++"
filter "system:windows"
-- See Funke-Engine/premake5.lua for the rationale on
-- MultiProcessorCompile + /Zc:preprocessor.
FunkeMultiProcessorCompile()
buildoptions { "/FS", "/Zc:preprocessor" }
systemversion "latest"
filter "configurations:Debug"
runtime "Debug"
symbols "On"
defines { "_DEBUG" }
filter "configurations:Release"
runtime "Release"
optimize "On"
symbols "On"
defines { "NDEBUG" }
filter "configurations:Dist"
runtime "Release"
optimize "Full"
symbols "Off"
defines { "NDEBUG" }
filter {}
end
-- ImGuizmo (translate/rotate/scale gizmos) — editor-only. Built as its own
-- StaticLib so it compiles WITHOUT the engine PCH/forceinclude the editor uses;
-- it only needs the imgui headers and resolves ImGui symbols at editor link time.
if FunkeModules.Editor and not FunkeVariantRoot then
project "ImGuizmo"
location (path.join(ROOT_DIR, "premake/generated/ImGuizmo"))
kind "StaticLib"
language "C++"
cppdialect "C++20"
staticruntime "off"
targetdir (path.join(ROOT_DIR, "bin/" .. outputdir .. "/%{prj.name}"))
objdir (path.join(ROOT_DIR, "bin-int/" .. outputdir .. "/%{prj.name}"))
files
{
"External/ImGuizmo/src/ImGuizmo.h",
"External/ImGuizmo/src/ImGuizmo.cpp"
}
includedirs
{
"External/imgui",
"External/ImGuizmo/src"
}
filter "system:windows"
FunkeMultiProcessorCompile()
buildoptions { "/FS", "/Zc:preprocessor" }
systemversion "latest"
filter "configurations:Debug"
runtime "Debug"
symbols "On"
defines { "_DEBUG" }
filter "configurations:Release"
runtime "Release"
optimize "On"
symbols "On"
defines { "NDEBUG" }
filter "configurations:Dist"
runtime "Release"
optimize "Full"
symbols "Off"
defines { "NDEBUG" }
filter {}
end
-- Dawn (WebGPU) and SDL3 are built out-of-band by scripts/dawn/SetupDawn.* and
-- scripts/sdl/SetupSDL.py; premake only links them (see dawn.lua / sdl3.lua).
if FunkeModules.Physics2D then
include "premake/dependencies/box2d.lua"
end
if FunkeModules.Physics3D then
include "premake/dependencies/jolt.lua"
end
if FunkeProfiler.Enabled then
include "premake/dependencies/tracy.lua"
end
include "Funke-Engine"
-- The solution builds the managed projects on Windows. gmake2 cannot build SDK-style .NET 10 projects,
-- so Linux / macOS run them through dotnet in one utility project the native consumers depend on.
-- A runtime variant reuses the full build's ScriptCore: the C# surface is module-independent.
if FunkeVariantRoot then
-- nothing managed
elseif os.target() == "windows" and not FunkeCoreValidationRoot then
include "Funke-PackageTool"
if FunkeModules.Scripting then