summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-02-21 19:30:11 +0300
committerSaikari <[email protected]>2026-02-21 19:30:11 +0300
commit30bcf8321661f8bd384eb941ea92e6ad3c7776f3 (patch)
tree76e6333edc92b411efcc95654834328ff37de47e
parentabe908e748c85ed30adf95df7e070f065e8f5363 (diff)
Add support for WASI platform in various modules and scripts
-rwxr-xr-xconfigure2
-rw-r--r--xmake/modules/detect/sdks/find_qt.lua4
-rw-r--r--xmake/modules/package/manager/conan/configurations.lua3
-rw-r--r--xmake/modules/package/manager/conan/v2/install_package.lua2
-rw-r--r--xmake/modules/package/tools/cmake.lua10
-rw-r--r--xmake/modules/package/tools/meson.lua4
-rw-r--r--xmake/modules/private/action/require/impl/package.lua2
-rw-r--r--xmake/modules/private/action/trybuild/cmake.lua8
-rw-r--r--xmake/modules/private/action/trybuild/meson.lua2
-rw-r--r--xmake/modules/private/detect/find_platform.lua2
-rw-r--r--xmake/modules/private/tools/go/goenv.lua6
-rw-r--r--xmake/platforms/wasi/xmake.lua32
-rw-r--r--xmake/rules/platform/wasm/installfiles/xmake.lua2
-rw-r--r--xmake/rules/platform/wasm/preloadfiles/xmake.lua2
-rw-r--r--xmake/rules/qt/config_static.lua2
-rw-r--r--xmake/rules/qt/load.lua2
16 files changed, 62 insertions, 23 deletions
diff --git a/configure b/configure
index d5bcbf5a0..466c8101e 100755
--- a/configure
+++ b/configure
@@ -3591,7 +3591,7 @@ _toolchain_detect() {
else
toolchains="x86_64_w64_mingw32"
fi
- elif is_plat "wasm"; then
+ elif is_plat "wasm" "wasi"; then
toolchains="emcc"
elif is_plat "linux" && ! is_arch "${os_arch}"; then
toolchains="envs"
diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua
index a7aa8e57c..6c1db309b 100644
--- a/xmake/modules/detect/sdks/find_qt.lua
+++ b/xmake/modules/detect/sdks/find_qt.lua
@@ -65,7 +65,7 @@ function _find_sdkdir(sdkdir, sdkver)
table.insert(subdirs, path.join(sdkver or "*", subdir, "bin"))
end
table.insert(subdirs, path.join(sdkver or "*", "android", "bin"))
- elseif is_plat("wasm") then
+ elseif is_plat("wasm", "wasi") then
table.insert(subdirs, path.join(sdkver or "*", "wasm_*", "bin"))
else
table.insert(subdirs, path.join(sdkver or "*", "*", "bin"))
@@ -126,7 +126,7 @@ function _find_sdkdir(sdkdir, sdkver)
-- special case for android on windows, where qmake is a .bat from version 6.3
-- this case also applys to wasm
- if is_host("windows") and is_plat("android", "wasm") then
+ if is_host("windows") and is_plat("android", "wasm", "wasi") then
local qmake = find_file("qmake.bat", paths, {suffixes = subdirs})
if qmake then
return path.directory(path.directory(qmake)), qmake
diff --git a/xmake/modules/package/manager/conan/configurations.lua b/xmake/modules/package/manager/conan/configurations.lua
index 178b3dfaa..f4dfcfbee 100644
--- a/xmake/modules/package/manager/conan/configurations.lua
+++ b/xmake/modules/package/manager/conan/configurations.lua
@@ -33,7 +33,8 @@ function arch(arch)
["arm64-v8a"] = "armv8", -- for android
mips = "mips",
mips64 = "mips64",
- wasm32 = "wasm"}
+ wasm32 = "wasm",
+ wasi = "wasm"}
return assert(map[arch], "unknown arch(%s)!", arch)
end
diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua
index ff834e1b6..e6f4f6632 100644
--- a/xmake/modules/package/manager/conan/v2/install_package.lua
+++ b/xmake/modules/package/manager/conan/v2/install_package.lua
@@ -193,7 +193,7 @@ function _conan_generate_compiler_profile(profile, configs, opt)
end
conf = {}
conf["tools.android:ndk_path"] = ndk:config("ndk")
- elseif plat == "wasm" then
+ elseif plat == "wasm" or plat == "wasi" then
local emsdk = find_emsdk()
assert(emsdk and emsdk.emscripten, "emscripten not found!")
local emscripten_cmakefile = find_file("Emscripten.cmake", path.join(emsdk.emscripten, "cmake/Modules/Platform"))
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 1557aebeb..fe9c13ffd 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -754,7 +754,7 @@ function _get_configs_for_generator(package, configs, opt)
elseif package:is_plat("windows") then
table.insert(configs, "-G")
table.insert(configs, _get_cmake_generator_for_msvc(package))
- elseif package:is_plat("wasm") and is_subhost("windows") then
+ elseif package:is_plat("wasm", "wasi") and is_subhost("windows") then
table.insert(configs, "-G")
table.insert(configs, "MinGW Makefiles")
else
@@ -894,7 +894,7 @@ function _get_envs_for_flags(package, configs, opt)
if package:has_tool("cxx", "clang", "clang_cl") then
platform_envs.CMAKE_CXX_FLAGS = _get_cxxflags(package, table.join({cross = true}, opt))
end
- elseif package:is_plat("wasm") then
+ elseif package:is_plat("wasm", "wasi") then
-- pass toolchain flags cross-compilation
-- @see https://github.com/xmake-io/xmake/issues/6690
opt.cross = true
@@ -929,7 +929,7 @@ function _get_configs(package, configs, opt)
_get_configs_for_appleos(package, configs, opt)
elseif package:is_plat("mingw") then
_get_configs_for_mingw(package, configs, opt)
- elseif package:is_plat("wasm") then
+ elseif package:is_plat("wasm", "wasi") then
_get_configs_for_wasm(package, configs, opt)
elseif package:is_cross() then
_get_configs_for_cross(package, configs, opt)
@@ -1146,7 +1146,7 @@ function _install_for_make(package, configs, opt)
if is_host("bsd") then
os.vrunv("gmake", argv)
os.vrunv("gmake", {"install"})
- elseif is_subhost("windows") and package:is_plat("mingw", "wasm") then
+ elseif is_subhost("windows") and package:is_plat("mingw", "wasm", "wasi") then
local mingw_make = assert(_get_mingw32_make(package), "mingw32-make.exe not found!")
os.vrunv(mingw_make, argv)
os.vrunv(mingw_make, {"install"})
@@ -1207,7 +1207,7 @@ function _get_cmake_generator(package, opt)
if not cmake_generator then
if package:has_tool("cc", "clang_cl") or package:has_tool("cxx", "clang_cl") then
cmake_generator = "Ninja"
- elseif (is_subhost("windows") and package:is_plat("mingw", "wasm"))
+ elseif (is_subhost("windows") and package:is_plat("mingw", "wasm", "wasi"))
or (package:is_plat("windows") and is_host("linux")) then
local ninja = _get_ninja(package)
if ninja then
diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua
index fbc6bbe77..4ba4d9bfb 100644
--- a/xmake/modules/package/tools/meson.lua
+++ b/xmake/modules/package/tools/meson.lua
@@ -174,7 +174,7 @@ function _insert_cross_configs(package, file, opt)
file:print("cpu_family = '%s'", cpu_family)
file:print("cpu = '%s'", cpu)
file:print("endian = 'little'")
- elseif package:is_plat("wasm") then
+ elseif package:is_plat("wasm", "wasi") then
file:print("system = 'emscripten'")
file:print("cpu_family = '%s'", package:arch())
file:print("cpu = '%s'", package:arch())
@@ -375,7 +375,7 @@ function _get_configs(package, configs, opt)
end
-- add cross file
- if package:is_cross() or package:is_plat("mingw") then
+ if package:is_cross() or package:is_plat("mingw", "wasm", "wasi") then
table.insert(configs, "--cross-file=" .. _get_configs_file(package, opt))
elseif package:config("toolchains") then
if _is_toolchain_compatible_with_host(package) then
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 4e2d70e5f..f0b55975c 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -293,7 +293,7 @@ function _add_package_configurations(package)
if package:extraconf("configs", "shared", "default") == nil then
-- we always use static library if it's for wasm platform
local readonly
- if package:is_plat("wasm") then
+ if package:is_plat("wasm", "wasi") then
readonly = true
end
local default = _get_default_config_value_of("shared")
diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua
index c5b807fb9..6be056a81 100644
--- a/xmake/modules/private/action/trybuild/cmake.lua
+++ b/xmake/modules/private/action/trybuild/cmake.lua
@@ -281,6 +281,10 @@ end
-- get configs for wasm
function _get_configs_for_wasm(configs)
+ if is_plat("wasi") then
+ _get_configs_for_cross(configs)
+ return
+ end
local emsdk = find_emsdk()
assert(emsdk and emsdk.emscripten, "emscripten not found!")
local emscripten_cmakefile = find_file("Emscripten.cmake", path.join(emsdk.emscripten, "cmake/Modules/Platform"))
@@ -419,7 +423,7 @@ function _get_configs_for_generator(configs, opt)
elseif is_plat("windows") then
table.insert(configs, "-G")
table.insert(configs, _get_cmake_generator_for_msvc())
- elseif is_plat("wasm") and is_subhost("windows") then
+ elseif is_plat("wasm", "wasi") and is_subhost("windows") then
table.insert(configs, "-G")
table.insert(configs, "MinGW Makefiles")
else
@@ -452,7 +456,7 @@ function _get_configs(opt)
_get_configs_for_appleos(configs)
elseif is_plat("mingw") then
_get_configs_for_mingw(configs)
- elseif is_plat("wasm") then
+ elseif is_plat("wasm", "wasi") then
_get_configs_for_wasm(configs)
elseif _is_cross_compilation() then
_get_configs_for_cross(configs)
diff --git a/xmake/modules/private/action/trybuild/meson.lua b/xmake/modules/private/action/trybuild/meson.lua
index e1976c703..9362f0b63 100644
--- a/xmake/modules/private/action/trybuild/meson.lua
+++ b/xmake/modules/private/action/trybuild/meson.lua
@@ -184,7 +184,7 @@ function _get_cross_file(builddir)
file:print("cpu_family = '%s'", cpu_family)
file:print("cpu = '%s'", cpu)
file:print("endian = 'little'")
- elseif is_plat("wasm") then
+ elseif is_plat("wasm", "wasi") then
file:print("system = 'emscripten'")
file:print("cpu_family = 'wasm32'")
file:print("cpu = 'wasm32'")
diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua
index a94b5ade3..0c38fca85 100644
--- a/xmake/modules/private/detect/find_platform.lua
+++ b/xmake/modules/private/detect/find_platform.lua
@@ -100,7 +100,7 @@ function _find_arch(plat, arch)
arch = appledev == "simulator" and os.arch() or "arm64"
elseif plat == "watchos" then
arch = appledev == "simulator" and os.arch() or "armv7k"
- elseif plat == "wasm" then
+ elseif plat == "wasm" or plat == "wasi" then
arch = "wasm32"
elseif plat == "mingw" then
local mingw_chost = nil
diff --git a/xmake/modules/private/tools/go/goenv.lua b/xmake/modules/private/tools/go/goenv.lua
index 1a448e6f3..c22401198 100644
--- a/xmake/modules/private/tools/go/goenv.lua
+++ b/xmake/modules/private/tools/go/goenv.lua
@@ -38,7 +38,8 @@ function GOOS(plat)
dragonfly = "dragonfly",
solaris = "solaris",
aix = "aix",
- plan9 = "plan9"
+ plan9 = "plan9",
+ wasi = "wasip1"
}
return goos_map[plat]
end
@@ -65,7 +66,8 @@ function GOARCH(arch)
ppc64le = "ppc64le",
riscv64 = "riscv64",
s390x = "s390x",
- wasm = "wasm"
+ wasm = "wasm",
+ wasm32 = "wasm"
}
-- try direct match first
diff --git a/xmake/platforms/wasi/xmake.lua b/xmake/platforms/wasi/xmake.lua
new file mode 100644
index 000000000..12c1f4b15
--- /dev/null
+++ b/xmake/platforms/wasi/xmake.lua
@@ -0,0 +1,32 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+platform("wasi")
+ set_os("wasi")
+ set_hosts("macosx", "linux", "windows", "bsd")
+ set_archs("wasm32", "wasm64")
+
+ set_formats("static", "lib$(name).a")
+ set_formats("object", "$(name).o")
+ set_formats("shared", "lib$(name).so")
+ set_formats("binary", "$(name).wasm")
+ set_formats("symbol", "$(name).sym")
+
+ set_toolchains("wasi")
diff --git a/xmake/rules/platform/wasm/installfiles/xmake.lua b/xmake/rules/platform/wasm/installfiles/xmake.lua
index f6833ecab..479f93d59 100644
--- a/xmake/rules/platform/wasm/installfiles/xmake.lua
+++ b/xmake/rules/platform/wasm/installfiles/xmake.lua
@@ -20,7 +20,7 @@
-- copy other files generated by emcc (see https://emscripten.org/docs/tools_reference/emcc.html#emcc-o-target)
rule("platform.wasm.installfiles")
- on_load("wasm", function (target)
+ on_load("wasm", "wasi", function (target)
if not target:is_binary() then
return
end
diff --git a/xmake/rules/platform/wasm/preloadfiles/xmake.lua b/xmake/rules/platform/wasm/preloadfiles/xmake.lua
index 144797f82..1fbb1d7d1 100644
--- a/xmake/rules/platform/wasm/preloadfiles/xmake.lua
+++ b/xmake/rules/platform/wasm/preloadfiles/xmake.lua
@@ -20,7 +20,7 @@
-- @see https://github.com/xmake-io/xmake/issues/3613
rule("platform.wasm.preloadfiles")
- on_load("wasm", function (target)
+ on_load("wasm", "wasi", function (target)
if not target:is_binary() then
return
end
diff --git a/xmake/rules/qt/config_static.lua b/xmake/rules/qt/config_static.lua
index 4cf943d13..d72cc2abb 100644
--- a/xmake/rules/qt/config_static.lua
+++ b/xmake/rules/qt/config_static.lua
@@ -58,7 +58,7 @@ function main(target)
if QtPlatformSupport then
table.insert(frameworks, QtPlatformSupport)
end
- elseif target:is_plat("wasm") then
+ elseif target:is_plat("wasm", "wasi") then
plugins.QWasmIntegrationPlugin = {linkdirs = "plugins/platforms", links = {"qwasm"}}
if qt_sdkver:ge("6.0") then
table.join2(frameworks, "QtOpenGL")
diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua
index 1ce0f4fb1..c0fc4c7f4 100644
--- a/xmake/rules/qt/load.lua
+++ b/xmake/rules/qt/load.lua
@@ -479,7 +479,7 @@ function main(target, opt)
fallbackmkspec = "android-clang"
target:add("rpathdirs", qt.libdir)
target:add("linkdirs", qt.libdir)
- elseif target:is_plat("wasm") then
+ elseif target:is_plat("wasm", "wasi") then
target:set("frameworks", nil)
_add_includedirs(target, qt.includedir)
fallbackmkspec = "wasm-emscripten"