diff --git a/modules/gmake/_preload.lua b/modules/gmake/_preload.lua index 976561dfe3..d788384890 100644 --- a/modules/gmake/_preload.lua +++ b/modules/gmake/_preload.lua @@ -7,6 +7,17 @@ local p = premake local project = p.project + local function defaultToolset() + local target = os.target() + if target == p.MACOSX then + return "clang" + elseif target == p.EMSCRIPTEN then + return "emmcc" + else + return "gcc" + end + end + --- -- The GNU make action, with support for the new platforms API --- @@ -15,12 +26,12 @@ trigger = "gmake", shortname = "GNU Make", description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin", - toolset = iif(os.target() == p.MACOSX, "clang", "gcc"), + toolset = defaultToolset(), valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile", "None" }, valid_languages = { "C", "C++", "C#" }, valid_tools = { - cc = { "clang", "gcc", "cosmocc" }, + cc = { "clang", "gcc", "cosmocc", "emcc" }, dotnet = { "mono", "msnet", "pnet" } }, diff --git a/modules/gmake2/_preload.lua b/modules/gmake2/_preload.lua index 3323dc5cc4..2d021e942a 100644 --- a/modules/gmake2/_preload.lua +++ b/modules/gmake2/_preload.lua @@ -11,18 +11,29 @@ local p = premake local project = p.project + local function defaultToolset() + local target = os.target() + if target == p.MACOSX then + return "clang" + elseif target == p.EMSCRIPTEN then + return "emmcc" + else + return "gcc" + end + end + newaction { trigger = "gmake2", shortname = "Alternative GNU Make", description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin", - toolset = iif(os.target() == p.MACOSX, "clang", "gcc"), + toolset = defaultToolset(), valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile", "None" }, valid_languages = { "C", "C++", "C#" }, valid_tools = { - cc = { "clang", "gcc", "cosmocc" }, + cc = { "clang", "gcc", "cosmocc", "emcc" }, dotnet = { "mono", "msnet", "pnet" } }, diff --git a/src/_manifest.lua b/src/_manifest.lua index e7cba4e97c..e2e0b44762 100644 --- a/src/_manifest.lua +++ b/src/_manifest.lua @@ -65,6 +65,7 @@ "tools/clang.lua", "tools/mingw.lua", "tools/cosmocc.lua", + "tools/emcc.lua", -- Clean action "actions/clean/_clean.lua", diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 4d23f28db3..96f6a22de8 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -29,7 +29,9 @@ p.ARM, p.ARM64, p.RISCV64, - p.LOONGARCH64 + p.LOONGARCH64, + p.WASM32, + p.WASM64 }, aliases = { i386 = p.X86, @@ -840,6 +842,7 @@ allowed = { "aix", "bsd", + "emscripten", "haiku", "ios", "linux", @@ -1284,16 +1287,17 @@ value = "VALUE", description = "Generate files for a different operating system", allowed = { - { "aix", "IBM AIX" }, - { "bsd", "OpenBSD, NetBSD, or FreeBSD" }, - { "haiku", "Haiku" }, - { "hurd", "GNU/Hurd" }, - { "ios", "iOS" }, - { "linux", "Linux" }, - { "macosx", "Apple Mac OS X" }, - { "solaris", "Solaris" }, - { "uwp", "Microsoft Universal Windows Platform"}, - { "windows", "Microsoft Windows" }, + { "aix", "IBM AIX" }, + { "bsd", "OpenBSD, NetBSD, or FreeBSD" }, + { "emscripten", "Emscripten" }, + { "haiku", "Haiku" }, + { "hurd", "GNU/Hurd" }, + { "ios", "iOS" }, + { "linux", "Linux" }, + { "macosx", "Apple Mac OS X" }, + { "solaris", "Solaris" }, + { "uwp", "Microsoft Universal Windows Platform"}, + { "windows", "Microsoft Windows" }, } } @@ -1428,6 +1432,13 @@ filter { "system:darwin" } toolset "clang" + filter { "system:emscripten" } + toolset "emcc" + architecture "wasm32" + + filter { "system:emscripten", "kind:ConsoleApp or WindowedApp" } + targetextension ".wasm" + filter { "platforms:Win32" } architecture "x86" diff --git a/src/base/_foundation.lua b/src/base/_foundation.lua index 4581d2c0c5..6854b75ff8 100644 --- a/src/base/_foundation.lua +++ b/src/base/_foundation.lua @@ -34,6 +34,7 @@ premake.GCC = "gcc" premake.HAIKU = "haiku" premake.ANDROID = "android" + premake.EMSCRIPTEN = "emscripten" premake.IOS = "ios" premake.LINUX = "linux" premake.MACOSX = "macosx" @@ -63,7 +64,8 @@ premake.ARM64 = "ARM64" premake.RISCV64 = "RISCV64" premake.LOONGARCH64 = "loongarch64" - + premake.WASM32 = "wasm32" + premake.WASM64 = "wasm64" --- diff --git a/src/base/os.lua b/src/base/os.lua index 10667e875a..d0f3699dff 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -827,16 +827,17 @@ os.systemTags = { - ["aix"] = { "aix", "posix", "desktop" }, - ["android"] = { "android", "mobile" }, - ["bsd"] = { "bsd", "posix", "desktop" }, - ["haiku"] = { "haiku", "posix", "desktop" }, - ["ios"] = { "ios", "darwin", "posix", "mobile" }, - ["linux"] = { "linux", "posix", "desktop" }, - ["macosx"] = { "macosx", "darwin", "posix", "desktop" }, - ["solaris"] = { "solaris", "posix", "desktop" }, - ["uwp"] = { "uwp", "windows", "desktop" }, - ["windows"] = { "windows", "win32", "desktop" }, + ["aix"] = { "aix", "posix", "desktop" }, + ["android"] = { "android", "mobile" }, + ["bsd"] = { "bsd", "posix", "desktop" }, + ["emscripten"] = { "emscripten", "web" }, + ["haiku"] = { "haiku", "posix", "desktop" }, + ["ios"] = { "ios", "darwin", "posix", "mobile" }, + ["linux"] = { "linux", "posix", "desktop" }, + ["macosx"] = { "macosx", "darwin", "posix", "desktop" }, + ["solaris"] = { "solaris", "posix", "desktop" }, + ["uwp"] = { "uwp", "windows", "desktop" }, + ["windows"] = { "windows", "win32", "desktop" }, } function os.getSystemTags(name) diff --git a/src/tools/clang.lua b/src/tools/clang.lua index aefcffddd7..da5d0024dc 100644 --- a/src/tools/clang.lua +++ b/src/tools/clang.lua @@ -229,6 +229,8 @@ architecture = { x86 = "-m32", x86_64 = "-m64", + WASM32 = "-m32", + WASM64 = "-m64", }, fatalwarnings = { Link = "-Wl,--fatal-warnings", diff --git a/src/tools/emcc.lua b/src/tools/emcc.lua new file mode 100644 index 0000000000..9d75faae02 --- /dev/null +++ b/src/tools/emcc.lua @@ -0,0 +1,21 @@ +-- +-- emcc.lua +-- Emscripten emcc toolset. +-- Copyright (c) 2024 Premake project +-- + +local p = premake +local clang = p.tools.clang + +p.tools.emcc = table.deepcopy(clang, {}) +local emcc = p.tools.emcc + +emcc.tools = { + cc = "emcc", + cxx = "em++", + ar = "emar" +} + +function emcc.gettoolname(cfg, tool) + return emcc.tools[tool] +end diff --git a/tests/_tests.lua b/tests/_tests.lua index b9aafbb993..0ceb983728 100644 --- a/tests/_tests.lua +++ b/tests/_tests.lua @@ -63,6 +63,7 @@ return { -- -- Toolset tests "tools/test_dotnet.lua", + "tools/test_emcc.lua", "tools/test_gcc.lua", "tools/test_clang.lua", "tools/test_msc.lua", diff --git a/tests/tools/test_emcc.lua b/tests/tools/test_emcc.lua new file mode 100644 index 0000000000..b994cb7db1 --- /dev/null +++ b/tests/tools/test_emcc.lua @@ -0,0 +1,48 @@ +-- +-- tests/test_emcc.lua +-- Automated test suite for the emcc toolset interface. +-- Copyright (c) 2024 Premake project +-- + +local p = premake +local suite = test.declare("tools_emcc") + +local emcc = p.tools.emcc + + +-- +-- Setup/teardown +-- + +local wks, prj, cfg + +function suite.setup() + wks, prj = test.createWorkspace() + system "emscripten" +end + +local function prepare() + cfg = test.getconfig(prj, "Debug") +end + + +-- +-- Check the selection of tools based on the target system. +-- + +function suite.tools_onDefault() + system "emscripten" + prepare() + test.isequal("wasm32", cfg.architecture) + test.isequal("emcc", emcc.gettoolname(cfg, "cc")) + test.isequal("em++", emcc.gettoolname(cfg, "cxx")) + test.isequal("emar", emcc.gettoolname(cfg, "ar")) +end + +function suite.tools_onWASM64() + system "emscripten" + architecture "WASM64" + prepare() + test.isequal("wasm64", cfg.architecture) +end + diff --git a/website/docs/architecture.md b/website/docs/architecture.md index e7f4283f7b..6a1c7d8ea5 100644 --- a/website/docs/architecture.md +++ b/website/docs/architecture.md @@ -15,6 +15,8 @@ architecture ("value") * `ARM64` * `RISCV64` * `loongarch64` +* `wasm32`, +* `wasm64`, * `armv5`: Only supported in VSAndroid projects * `armv7`: Only supported in VSAndroid projects * `aarch64`: Only supported in VSAndroid projects diff --git a/website/docs/system.md b/website/docs/system.md index 58ca74b39a..13d9cfc764 100644 --- a/website/docs/system.md +++ b/website/docs/system.md @@ -13,6 +13,7 @@ If no system is specified, Premake will identify and target the current operatin * aix * android * bsd +* [emscripten](https://emscripten.org/) * [haiku](http://www.haiku-os.org) * ios * linux @@ -23,6 +24,8 @@ If no system is specified, Premake will identify and target the current operatin * windows * xbox360 +To note: `emscripten` at the moment is only supported for the `gmake` and `gmake2` actions. + ### Applies To ### Project configurations.