Skip to content

Commit 08a40b4

Browse files
committed
Add Emscripten system and emcc toolset support.
1 parent 7fdcacb commit 08a40b4

File tree

12 files changed

+138
-26
lines changed

12 files changed

+138
-26
lines changed

modules/gmake/_preload.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
local p = premake
88
local project = p.project
99

10+
local function defaultToolset()
11+
local target = os.target()
12+
if target == p.MACOSX then
13+
return "clang"
14+
elseif target == p.EMSCRIPTEN then
15+
return "emmcc"
16+
else
17+
return "gcc"
18+
end
19+
end
20+
1021
---
1122
-- The GNU make action, with support for the new platforms API
1223
---
@@ -15,12 +26,12 @@
1526
trigger = "gmake",
1627
shortname = "GNU Make",
1728
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
18-
toolset = iif(os.target() == p.MACOSX, "clang", "gcc"),
29+
toolset = defaultToolset(),
1930

2031
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile", "None" },
2132
valid_languages = { "C", "C++", "C#" },
2233
valid_tools = {
23-
cc = { "clang", "gcc", "cosmocc" },
34+
cc = { "clang", "gcc", "cosmocc", "emcc" },
2435
dotnet = { "mono", "msnet", "pnet" }
2536
},
2637

modules/gmake2/_preload.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@
1111
local p = premake
1212
local project = p.project
1313

14+
local function defaultToolset()
15+
local target = os.target()
16+
if target == p.MACOSX then
17+
return "clang"
18+
elseif target == p.EMSCRIPTEN then
19+
return "emmcc"
20+
else
21+
return "gcc"
22+
end
23+
end
24+
1425
newaction {
1526
trigger = "gmake2",
1627
shortname = "Alternative GNU Make",
1728
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
18-
toolset = iif(os.target() == p.MACOSX, "clang", "gcc"),
29+
toolset = defaultToolset(),
1930

2031
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile", "None" },
2132

2233
valid_languages = { "C", "C++", "C#" },
2334

2435
valid_tools = {
25-
cc = { "clang", "gcc", "cosmocc" },
36+
cc = { "clang", "gcc", "cosmocc", "emcc" },
2637
dotnet = { "mono", "msnet", "pnet" }
2738
},
2839

src/_manifest.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"tools/clang.lua",
6666
"tools/mingw.lua",
6767
"tools/cosmocc.lua",
68+
"tools/emcc.lua",
6869

6970
-- Clean action
7071
"actions/clean/_clean.lua",

src/_premake_init.lua

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
p.ARM,
3030
p.ARM64,
3131
p.RISCV64,
32-
p.LOONGARCH64
32+
p.LOONGARCH64,
33+
p.WASM32,
34+
p.WASM64
3335
},
3436
aliases = {
3537
i386 = p.X86,
@@ -840,6 +842,7 @@
840842
allowed = {
841843
"aix",
842844
"bsd",
845+
"emscripten",
843846
"haiku",
844847
"ios",
845848
"linux",
@@ -1284,16 +1287,17 @@
12841287
value = "VALUE",
12851288
description = "Generate files for a different operating system",
12861289
allowed = {
1287-
{ "aix", "IBM AIX" },
1288-
{ "bsd", "OpenBSD, NetBSD, or FreeBSD" },
1289-
{ "haiku", "Haiku" },
1290-
{ "hurd", "GNU/Hurd" },
1291-
{ "ios", "iOS" },
1292-
{ "linux", "Linux" },
1293-
{ "macosx", "Apple Mac OS X" },
1294-
{ "solaris", "Solaris" },
1295-
{ "uwp", "Microsoft Universal Windows Platform"},
1296-
{ "windows", "Microsoft Windows" },
1290+
{ "aix", "IBM AIX" },
1291+
{ "bsd", "OpenBSD, NetBSD, or FreeBSD" },
1292+
{ "emscripten", "Emscripten" },
1293+
{ "haiku", "Haiku" },
1294+
{ "hurd", "GNU/Hurd" },
1295+
{ "ios", "iOS" },
1296+
{ "linux", "Linux" },
1297+
{ "macosx", "Apple Mac OS X" },
1298+
{ "solaris", "Solaris" },
1299+
{ "uwp", "Microsoft Universal Windows Platform"},
1300+
{ "windows", "Microsoft Windows" },
12971301
}
12981302
}
12991303

@@ -1428,6 +1432,13 @@
14281432
filter { "system:darwin" }
14291433
toolset "clang"
14301434

1435+
filter { "system:emscripten" }
1436+
toolset "emcc"
1437+
architecture "wasm32"
1438+
1439+
filter { "system:emscripten", "kind:ConsoleApp or WindowedApp" }
1440+
targetextension ".wasm"
1441+
14311442
filter { "platforms:Win32" }
14321443
architecture "x86"
14331444

src/base/_foundation.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
premake.GCC = "gcc"
3535
premake.HAIKU = "haiku"
3636
premake.ANDROID = "android"
37+
premake.EMSCRIPTEN = "emscripten"
3738
premake.IOS = "ios"
3839
premake.LINUX = "linux"
3940
premake.MACOSX = "macosx"
@@ -63,7 +64,8 @@
6364
premake.ARM64 = "ARM64"
6465
premake.RISCV64 = "RISCV64"
6566
premake.LOONGARCH64 = "loongarch64"
66-
67+
premake.WASM32 = "wasm32"
68+
premake.WASM64 = "wasm64"
6769

6870

6971
---

src/base/os.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,17 @@
827827

828828
os.systemTags =
829829
{
830-
["aix"] = { "aix", "posix", "desktop" },
831-
["android"] = { "android", "mobile" },
832-
["bsd"] = { "bsd", "posix", "desktop" },
833-
["haiku"] = { "haiku", "posix", "desktop" },
834-
["ios"] = { "ios", "darwin", "posix", "mobile" },
835-
["linux"] = { "linux", "posix", "desktop" },
836-
["macosx"] = { "macosx", "darwin", "posix", "desktop" },
837-
["solaris"] = { "solaris", "posix", "desktop" },
838-
["uwp"] = { "uwp", "windows", "desktop" },
839-
["windows"] = { "windows", "win32", "desktop" },
830+
["aix"] = { "aix", "posix", "desktop" },
831+
["android"] = { "android", "mobile" },
832+
["bsd"] = { "bsd", "posix", "desktop" },
833+
["emscripten"] = { "emscripten", "web" },
834+
["haiku"] = { "haiku", "posix", "desktop" },
835+
["ios"] = { "ios", "darwin", "posix", "mobile" },
836+
["linux"] = { "linux", "posix", "desktop" },
837+
["macosx"] = { "macosx", "darwin", "posix", "desktop" },
838+
["solaris"] = { "solaris", "posix", "desktop" },
839+
["uwp"] = { "uwp", "windows", "desktop" },
840+
["windows"] = { "windows", "win32", "desktop" },
840841
}
841842

842843
function os.getSystemTags(name)

src/tools/clang.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@
229229
architecture = {
230230
x86 = "-m32",
231231
x86_64 = "-m64",
232+
WASM32 = "-m32",
233+
WASM64 = "-m64",
232234
},
233235
fatalwarnings = {
234236
Link = "-Wl,--fatal-warnings",

src/tools/emcc.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--
2+
-- emcc.lua
3+
-- Emscripten emcc toolset.
4+
-- Copyright (c) 2024 Premake project
5+
--
6+
7+
local p = premake
8+
local clang = p.tools.clang
9+
10+
p.tools.emcc = table.deepcopy(clang, {})
11+
local emcc = p.tools.emcc
12+
13+
emcc.tools = {
14+
cc = "emcc",
15+
cxx = "em++",
16+
ar = "emar"
17+
}
18+
19+
function emcc.gettoolname(cfg, tool)
20+
return emcc.tools[tool]
21+
end

tests/_tests.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ return {
6363

6464
-- -- Toolset tests
6565
"tools/test_dotnet.lua",
66+
"tools/test_emcc.lua",
6667
"tools/test_gcc.lua",
6768
"tools/test_clang.lua",
6869
"tools/test_msc.lua",

tests/tools/test_emcc.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--
2+
-- tests/test_emcc.lua
3+
-- Automated test suite for the emcc toolset interface.
4+
-- Copyright (c) 2024 Premake project
5+
--
6+
7+
local p = premake
8+
local suite = test.declare("tools_emcc")
9+
10+
local emcc = p.tools.emcc
11+
12+
13+
--
14+
-- Setup/teardown
15+
--
16+
17+
local wks, prj, cfg
18+
19+
function suite.setup()
20+
wks, prj = test.createWorkspace()
21+
system "emscripten"
22+
end
23+
24+
local function prepare()
25+
cfg = test.getconfig(prj, "Debug")
26+
end
27+
28+
29+
--
30+
-- Check the selection of tools based on the target system.
31+
--
32+
33+
function suite.tools_onDefault()
34+
system "emscripten"
35+
prepare()
36+
test.isequal("wasm32", cfg.architecture)
37+
test.isequal("emcc", emcc.gettoolname(cfg, "cc"))
38+
test.isequal("em++", emcc.gettoolname(cfg, "cxx"))
39+
test.isequal("emar", emcc.gettoolname(cfg, "ar"))
40+
end
41+
42+
function suite.tools_onWASM64()
43+
system "emscripten"
44+
architecture "WASM64"
45+
prepare()
46+
test.isequal("wasm64", cfg.architecture)
47+
end
48+

0 commit comments

Comments
 (0)