Skip to content

Commit 1896c8b

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

File tree

14 files changed

+142
-26
lines changed

14 files changed

+142
-26
lines changed

contrib/libzip/premake5.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ project "zip-lib"
1111
"**.c"
1212
}
1313

14+
filter "system:linux"
15+
defines { "HAVE_SSIZE_T_LIBZIP", "HAVE_CONFIG_H" }
16+
forceincludes { "unistd.h" }
17+
1418
filter "toolset:gcc or clang or cosmocc"
1519
defines { "HAVE_SSIZE_T_LIBZIP", "HAVE_CONFIG_H" }
1620
forceincludes { "unistd.h" }

modules/gmake/_preload.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515
trigger = "gmake",
1616
shortname = "GNU Make",
1717
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
18-
toolset = iif(os.target() == p.MACOSX, "clang", "gcc"),
18+
toolset = function()
19+
local target = os.target()
20+
if target == p.MACOSX then
21+
return "clang"
22+
elseif target == p.EMSCRIPTEN then
23+
return "emmcc"
24+
else
25+
return "gcc"
26+
end
27+
end,
1928

2029
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile", "None" },
2130
valid_languages = { "C", "C++", "C#" },
2231
valid_tools = {
23-
cc = { "clang", "gcc", "cosmocc" },
32+
cc = { "clang", "gcc", "cosmocc", "emcc" },
2433
dotnet = { "mono", "msnet", "pnet" }
2534
},
2635

modules/gmake2/_preload.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@
1515
trigger = "gmake2",
1616
shortname = "Alternative GNU Make",
1717
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
18-
toolset = iif(os.target() == p.MACOSX, "clang", "gcc"),
18+
toolset = function()
19+
local target = os.target()
20+
if target == p.MACOSX then
21+
return "clang"
22+
elseif target == p.EMSCRIPTEN then
23+
return "emmcc"
24+
else
25+
return "gcc"
26+
end
27+
end,
28+
1929

2030
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile", "None" },
2131

2232
valid_languages = { "C", "C++", "C#" },
2333

2434
valid_tools = {
25-
cc = { "clang", "gcc", "cosmocc" },
35+
cc = { "clang", "gcc", "cosmocc", "emcc" },
2636
dotnet = { "mono", "msnet", "pnet" }
2737
},
2838

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/base/oven.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@
538538
local system = os.target()
539539
local architecture = os.targetarch()
540540
local toolset = p.action.current().toolset
541+
if type(toolset) == "function" then
542+
toolset = toolset()
543+
end
541544

542545
if platform then
543546
system = p.api.checkValue(p.fields.system, platform) or system

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

0 commit comments

Comments
 (0)