From 30bcf8321661f8bd384eb941ea92e6ad3c7776f3 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sat, 21 Feb 2026 19:30:11 +0300 Subject: Add support for WASI platform in various modules and scripts --- configure | 2 +- xmake/modules/detect/sdks/find_qt.lua | 4 +-- .../package/manager/conan/configurations.lua | 3 +- .../package/manager/conan/v2/install_package.lua | 2 +- xmake/modules/package/tools/cmake.lua | 10 +++---- xmake/modules/package/tools/meson.lua | 4 +-- .../private/action/require/impl/package.lua | 2 +- xmake/modules/private/action/trybuild/cmake.lua | 8 ++++-- xmake/modules/private/action/trybuild/meson.lua | 2 +- xmake/modules/private/detect/find_platform.lua | 2 +- xmake/modules/private/tools/go/goenv.lua | 6 ++-- xmake/platforms/wasi/xmake.lua | 32 ++++++++++++++++++++++ xmake/rules/platform/wasm/installfiles/xmake.lua | 2 +- xmake/rules/platform/wasm/preloadfiles/xmake.lua | 2 +- xmake/rules/qt/config_static.lua | 2 +- xmake/rules/qt/load.lua | 2 +- 16 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 xmake/platforms/wasi/xmake.lua 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" -- cgit v1.3.1 From 54fe033757a7f157f181adb0470572f1963a74cc Mon Sep 17 00:00:00 2001 From: Saikari Date: Sat, 21 Feb 2026 20:59:43 +0300 Subject: try implement runner? --- xmake/actions/run/main.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 6ed59f3f1..d11456cb7 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -33,6 +33,24 @@ import("private.detect.check_targetname") import("lib.detect.find_tool") import("private.action.utils", {alias = "action_utils"}) +function _run_wasi_target(targetfile, args, opt) + opt = opt or {} + local rundir = opt.rundir + local addenvs = opt.addenvs + local setenvs = opt.setenvs + local wasmtime = find_tool("wasmtime") + if wasmtime then + local runargs = {targetfile} + if args and #args > 0 then + table.join2(runargs, args) + end + os.execv(wasmtime.program, runargs, { + curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs}) + else + raise("wasmtime not found, which is required for running wasi target!") + end +end + function _run_wasm_target_in_browser(targetfile, opt) opt = opt or {} local rundir = opt.rundir @@ -81,6 +99,12 @@ function _do_run_target(target) return end + -- run wasi target via wasmtime + if target:is_plat("wasi") then + _run_wasi_target(targetfile, args, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) + return + end + -- run windows target on non-windows host via wine if not is_host("windows") and target:is_plat("windows") then local wine = assert(find_tool("wine"), "wine not found!") -- cgit v1.3.1 From 25f6f0ce529a29611812558fc6e3d1c9f0fdc9b8 Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 23 Feb 2026 16:24:27 +0300 Subject: Remove WASI platform references from various modules and scripts --- configure | 2 +- xmake/actions/run/main.lua | 15 +++++----- xmake/modules/detect/sdks/find_qt.lua | 4 +-- .../package/manager/conan/configurations.lua | 3 +- .../package/manager/conan/v2/install_package.lua | 2 +- xmake/modules/package/tools/cmake.lua | 10 +++---- xmake/modules/package/tools/meson.lua | 4 +-- .../private/action/require/impl/package.lua | 2 +- xmake/modules/private/action/trybuild/cmake.lua | 6 ++-- xmake/modules/private/action/trybuild/meson.lua | 2 +- xmake/modules/private/detect/find_platform.lua | 2 +- xmake/modules/private/tools/go/goenv.lua | 3 +- xmake/platforms/wasi/xmake.lua | 32 ---------------------- xmake/rules/platform/wasm/installfiles/xmake.lua | 2 +- xmake/rules/platform/wasm/preloadfiles/xmake.lua | 2 +- xmake/rules/qt/config_static.lua | 2 +- xmake/rules/qt/load.lua | 2 +- 17 files changed, 30 insertions(+), 65 deletions(-) delete mode 100644 xmake/platforms/wasi/xmake.lua diff --git a/configure b/configure index 466c8101e..d5bcbf5a0 100755 --- a/configure +++ b/configure @@ -3591,7 +3591,7 @@ _toolchain_detect() { else toolchains="x86_64_w64_mingw32" fi - elif is_plat "wasm" "wasi"; then + elif is_plat "wasm"; then toolchains="emcc" elif is_plat "linux" && ! is_arch "${os_arch}"; then toolchains="envs" diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index d11456cb7..59d7cbe76 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -93,15 +93,14 @@ function _do_run_target(target) -- get run arguments local args = table.wrap(option.get("arguments") or target:get("runargs")) - -- run wasm target in browser + -- run wasm target if target:is_plat("wasm") then - _run_wasm_target_in_browser(targetfile, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) - return - end - - -- run wasi target via wasmtime - if target:is_plat("wasi") then - _run_wasi_target(targetfile, args, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) + -- run via wasmtime if using the wasi toolchain, otherwise open in browser + if target:toolchain("wasi") then + _run_wasi_target(targetfile, args, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) + else + _run_wasm_target_in_browser(targetfile, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) + end return end diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua index 6c1db309b..a7aa8e57c 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", "wasi") then + elseif is_plat("wasm") 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", "wasi") then + if is_host("windows") and is_plat("android", "wasm") 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 f4dfcfbee..178b3dfaa 100644 --- a/xmake/modules/package/manager/conan/configurations.lua +++ b/xmake/modules/package/manager/conan/configurations.lua @@ -33,8 +33,7 @@ function arch(arch) ["arm64-v8a"] = "armv8", -- for android mips = "mips", mips64 = "mips64", - wasm32 = "wasm", - wasi = "wasm"} + wasm32 = "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 e6f4f6632..ff834e1b6 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" or plat == "wasi" then + elseif plat == "wasm" 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 fe9c13ffd..1557aebeb 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", "wasi") and is_subhost("windows") then + elseif package:is_plat("wasm") 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", "wasi") then + elseif package:is_plat("wasm") 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", "wasi") then + elseif package:is_plat("wasm") 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", "wasi") then + elseif is_subhost("windows") and package:is_plat("mingw", "wasm") 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", "wasi")) + elseif (is_subhost("windows") and package:is_plat("mingw", "wasm")) 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 4ba4d9bfb..01c12bbe7 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", "wasi") then + elseif package:is_plat("wasm") 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", "wasm", "wasi") then + if package:is_cross() or package:is_plat("mingw", "wasm") 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 f0b55975c..4e2d70e5f 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", "wasi") then + if package:is_plat("wasm") 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 6be056a81..4243a7ce8 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -281,7 +281,7 @@ end -- get configs for wasm function _get_configs_for_wasm(configs) - if is_plat("wasi") then + if config.get("toolchain") == "wasi" then _get_configs_for_cross(configs) return end @@ -423,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", "wasi") and is_subhost("windows") then + elseif is_plat("wasm") and is_subhost("windows") then table.insert(configs, "-G") table.insert(configs, "MinGW Makefiles") else @@ -456,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", "wasi") then + elseif is_plat("wasm") 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 9362f0b63..e1976c703 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", "wasi") then + elseif is_plat("wasm") 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 0c38fca85..a94b5ade3 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" or plat == "wasi" then + elseif plat == "wasm" 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 c22401198..37a2c27c3 100644 --- a/xmake/modules/private/tools/go/goenv.lua +++ b/xmake/modules/private/tools/go/goenv.lua @@ -38,8 +38,7 @@ function GOOS(plat) dragonfly = "dragonfly", solaris = "solaris", aix = "aix", - plan9 = "plan9", - wasi = "wasip1" + plan9 = "plan9" } return goos_map[plat] end diff --git a/xmake/platforms/wasi/xmake.lua b/xmake/platforms/wasi/xmake.lua deleted file mode 100644 index 12c1f4b15..000000000 --- a/xmake/platforms/wasi/xmake.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!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 479f93d59..f6833ecab 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", "wasi", function (target) + on_load("wasm", 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 1fbb1d7d1..144797f82 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", "wasi", function (target) + on_load("wasm", 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 d72cc2abb..4cf943d13 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", "wasi") then + elseif target:is_plat("wasm") 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 c0fc4c7f4..1ce0f4fb1 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", "wasi") then + elseif target:is_plat("wasm") then target:set("frameworks", nil) _add_includedirs(target, qt.includedir) fallbackmkspec = "wasm-emscripten" -- cgit v1.3.1 From f3ab2ca1744900c105e7e789dc099ee4838015d1 Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 23 Feb 2026 16:35:05 +0300 Subject: Refactor WASI platform handling and clean up wasm references in various modules --- xmake/actions/run/main.lua | 3 ++- xmake/modules/package/tools/meson.lua | 2 +- xmake/modules/private/tools/go/goenv.lua | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 59d7cbe76..8eaa5672f 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -96,7 +96,8 @@ function _do_run_target(target) -- run wasm target if target:is_plat("wasm") then -- run via wasmtime if using the wasi toolchain, otherwise open in browser - if target:toolchain("wasi") then + local is_wasi = target:toolchain("wasi") or (target:has_tool("cc", "clang") and target:has_tool("ar", "llvm-ar")) + if is_wasi then _run_wasi_target(targetfile, args, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) else _run_wasm_target_in_browser(targetfile, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 01c12bbe7..fbc6bbe77 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -375,7 +375,7 @@ function _get_configs(package, configs, opt) end -- add cross file - if package:is_cross() or package:is_plat("mingw", "wasm") then + if package:is_cross() or package:is_plat("mingw") 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/tools/go/goenv.lua b/xmake/modules/private/tools/go/goenv.lua index 37a2c27c3..1a448e6f3 100644 --- a/xmake/modules/private/tools/go/goenv.lua +++ b/xmake/modules/private/tools/go/goenv.lua @@ -65,8 +65,7 @@ function GOARCH(arch) ppc64le = "ppc64le", riscv64 = "riscv64", s390x = "s390x", - wasm = "wasm", - wasm32 = "wasm" + wasm = "wasm" } -- try direct match first -- cgit v1.3.1 From 3634d880f8e48d095fe5184ac9a594923e742f10 Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 23 Feb 2026 16:55:17 +0300 Subject: optimize --- xmake/actions/run/main.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 8eaa5672f..effa362e5 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -95,12 +95,10 @@ function _do_run_target(target) -- run wasm target if target:is_plat("wasm") then - -- run via wasmtime if using the wasi toolchain, otherwise open in browser - local is_wasi = target:toolchain("wasi") or (target:has_tool("cc", "clang") and target:has_tool("ar", "llvm-ar")) - if is_wasi then - _run_wasi_target(targetfile, args, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) - else + if target:has_tool("cc", "emcc") then _run_wasm_target_in_browser(targetfile, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) + else + _run_wasi_target(targetfile, args, {rundir = rundir, addenvs = addenvs, setenvs = setenvs}) end return end -- cgit v1.3.1