From fb1ac8a218a8f064826e937d074f008b08a47c09 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 01:31:31 +0100 Subject: [PATCH 1/9] fix windows wasm compilation with packages --- xmake/core/platform/platform.lua | 2 +- xmake/modules/package/tools/cmake.lua | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1b2ba19e392..a7ab68fca1c 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -151,7 +151,7 @@ end -- get the toolchains function _instance:toolchains(opt) local toolchains = self:_memcache():get("toolchains") - if not toolchains then + if not toolchains or #toolchains == 0 then -- get current valid toolchains from configuration cache local names = nil diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 99dfe0436a3..38b25db5105 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -601,10 +601,16 @@ function _get_configs_for_wasm(package, configs, opt) local emscripten_cmakefile = find_file("Emscripten.cmake", path.join(emsdk.emscripten, "cmake/Modules/Platform")) assert(emscripten_cmakefile, "Emscripten.cmake not found!") table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile) - if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then - local mingw_make = _get_mingw32_make(package) - if mingw_make then - table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make) + if is_subhost("windows") then + if opt.cmake_generator ~= "Ninja" then + local mingw_make = _get_mingw32_make(package) + if mingw_make then + table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make) + end + else + local ninja = find_tool("ninja") + assert(ninja, "ninja not found!") + table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja.program) end end _get_configs_for_generic(package, configs, opt) @@ -1214,8 +1220,9 @@ end -- install package function install(package, configs, opt) opt = opt or {} - local cmake_generator = _get_cmake_generator(package, opt) + _get_configs(package, configs, opt) + local cmake_generator = _get_cmake_generator(package, opt) -- enter build directory local buildir = opt.buildir or package:buildir() os.mkdir(path.join(buildir, "install")) From 09f4c713fa673df9d175b58f8209c39d2dea8cea Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 03:09:18 +0100 Subject: [PATCH 2/9] use `_get_configs_for_generator` instead of `_get_configs` --- xmake/modules/package/tools/cmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 38b25db5105..52f89f51948 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -1220,7 +1220,7 @@ end -- install package function install(package, configs, opt) opt = opt or {} - _get_configs(package, configs, opt) + _get_configs_for_generator(package, configs, opt) local cmake_generator = _get_cmake_generator(package, opt) -- enter build directory From 63c0cd00d74a40f91262a6ca587b9ef0d22e37b8 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:53:25 +0100 Subject: [PATCH 3/9] add `_get_ninja(package)`, remove ` _get_configs_for_generator` in install --- xmake/modules/package/tools/cmake.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 52f89f51948..dbb76196651 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -366,6 +366,13 @@ function _get_mingw32_make(package) end end +-- get ninja +function _get_ninja(package) + local ninja = find_tool("ninja") + assert(ninja, "ninja not found!") + return ninja.program +end + -- https://github.com/xmake-io/xmake-repo/pull/1096 function _fix_cxx_compiler_cmake(package, envs) local cxx = envs.CMAKE_CXX_COMPILER @@ -608,9 +615,10 @@ function _get_configs_for_wasm(package, configs, opt) table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make) end else - local ninja = find_tool("ninja") - assert(ninja, "ninja not found!") - table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja.program) + local ninja = _get_ninja(package) + if ninja then + table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja) + end end end _get_configs_for_generic(package, configs, opt) @@ -768,7 +776,6 @@ function _get_configs_for_generator(package, configs, opt) table.insert(configs, "-G") if find_tool("ninja") then table.insert(configs, "Ninja") - opt.cmake_generator = "Ninja" else table.insert(configs, "MinGW Makefiles") end @@ -1148,7 +1155,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") then + elseif is_subhost("windows") and (package:is_plat("mingw", "wasm")) then local mingw_make = _get_mingw32_make(package) if not mingw_make and find_tool("ninja") then cmake_generator = "Ninja" @@ -1220,7 +1227,6 @@ end -- install package function install(package, configs, opt) opt = opt or {} - _get_configs_for_generator(package, configs, opt) local cmake_generator = _get_cmake_generator(package, opt) -- enter build directory From b88ecaeb0c721c1d8d3d6ba3de366f8a65581c86 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:55:09 +0100 Subject: [PATCH 4/9] Update cmake.lua --- xmake/modules/package/tools/cmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index dbb76196651..5e1eceb1aa6 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -1227,8 +1227,8 @@ end -- install package function install(package, configs, opt) opt = opt or {} - local cmake_generator = _get_cmake_generator(package, opt) + -- enter build directory local buildir = opt.buildir or package:buildir() os.mkdir(path.join(buildir, "install")) From 760ccdd1beb3673ed282f75bb630f3ecdbcfabd3 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 12:09:40 +0100 Subject: [PATCH 5/9] Update cmake.lua --- xmake/modules/package/tools/cmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 5e1eceb1aa6..9b4a014364e 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -1155,7 +1155,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")) then + elseif is_subhost("windows") and package:is_plat("mingw", "wasm") then local mingw_make = _get_mingw32_make(package) if not mingw_make and find_tool("ninja") then cmake_generator = "Ninja" From d7057eb144be99f09f18427e92eee52ccafc318f Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:35:36 +0100 Subject: [PATCH 6/9] add requested changes --- xmake/modules/package/tools/cmake.lua | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 9b4a014364e..8b1575d2e2e 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -609,16 +609,16 @@ function _get_configs_for_wasm(package, configs, opt) assert(emscripten_cmakefile, "Emscripten.cmake not found!") table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile) if is_subhost("windows") then - if opt.cmake_generator ~= "Ninja" then - local mingw_make = _get_mingw32_make(package) - if mingw_make then - table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make) - end - else + if opt.cmake_generator == "Ninja" then local ninja = _get_ninja(package) if ninja then table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja) end + else + local mingw_make = _get_mingw32_make(package) + if mingw_make then + table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make) + end end end _get_configs_for_generic(package, configs, opt) @@ -771,14 +771,8 @@ function _get_configs_for_generator(package, configs, opt) table.insert(configs, "-G") table.insert(configs, _get_cmake_generator_for_msvc(package)) elseif package:is_plat("wasm") and is_subhost("windows") then - -- we attempt to use ninja if it exist - -- @see https://github.com/xmake-io/xmake/issues/3771 table.insert(configs, "-G") - if find_tool("ninja") then - table.insert(configs, "Ninja") - else - table.insert(configs, "MinGW Makefiles") - end + table.insert(configs, "MinGW Makefiles") else table.insert(configs, "-G") table.insert(configs, "Unix Makefiles") From e2722a2ad5ce00a9a3edd3d75de9faa417222f17 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:39:50 +0100 Subject: [PATCH 7/9] Update cmake.lua --- xmake/modules/package/tools/cmake.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 8b1575d2e2e..61f49dacbf8 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -771,8 +771,10 @@ function _get_configs_for_generator(package, configs, opt) table.insert(configs, "-G") table.insert(configs, _get_cmake_generator_for_msvc(package)) elseif package:is_plat("wasm") and is_subhost("windows") then - table.insert(configs, "-G") - table.insert(configs, "MinGW Makefiles") + if not find_tool("ninja") then + table.insert(configs, "-G") + table.insert(configs, "MinGW Makefiles") + end else table.insert(configs, "-G") table.insert(configs, "Unix Makefiles") From 5d28f368645e6f5ecc4fd0e2b0b6e542f809bfc1 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:45:57 +0100 Subject: [PATCH 8/9] add requested changes --- xmake/modules/package/tools/cmake.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 61f49dacbf8..7d5550390e0 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -369,8 +369,9 @@ end -- get ninja function _get_ninja(package) local ninja = find_tool("ninja") - assert(ninja, "ninja not found!") - return ninja.program + if ninja then + return ninja.program + end end -- https://github.com/xmake-io/xmake-repo/pull/1096 @@ -771,10 +772,8 @@ function _get_configs_for_generator(package, configs, opt) table.insert(configs, "-G") table.insert(configs, _get_cmake_generator_for_msvc(package)) elseif package:is_plat("wasm") and is_subhost("windows") then - if not find_tool("ninja") then - table.insert(configs, "-G") - table.insert(configs, "MinGW Makefiles") - end + table.insert(configs, "-G") + table.insert(configs, "MinGW Makefiles") else table.insert(configs, "-G") table.insert(configs, "Unix Makefiles") @@ -1152,8 +1151,8 @@ function _get_cmake_generator(package, opt) 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") then - local mingw_make = _get_mingw32_make(package) - if not mingw_make and find_tool("ninja") then + local ninja = _get_ninja(package) + if ninja then cmake_generator = "Ninja" end end From e432b35f84dcfa2daad137a0fbb96d22ad48af04 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:06:45 +0100 Subject: [PATCH 9/9] Update platform.lua --- xmake/core/platform/platform.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index a7ab68fca1c..1b2ba19e392 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -151,7 +151,7 @@ end -- get the toolchains function _instance:toolchains(opt) local toolchains = self:_memcache():get("toolchains") - if not toolchains or #toolchains == 0 then + if not toolchains then -- get current valid toolchains from configuration cache local names = nil