From de227a41eaa079f4ee3c725922495f8ce0f96833 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 00:57:59 +0800 Subject: add runtimes option --- xmake/actions/config/xmake.lua | 7 +++++++ xmake/platforms/android/xmake.lua | 2 +- xmake/platforms/windows/xmake.lua | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 464afa662..48bcb6eef 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -213,6 +213,13 @@ task("config") , " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx" , " - run `xmake show -l toolchains` to get all toolchains" , values = _toolchain_values}, + {nil, "runtimes", "kv", nil, "Set the compiler runtime library." + , "e.g. " + , " - xmake f --runtimes=MTd" + , " - xmake f --runtimes=MT,c++_static" + , values = {"MT", "MTd", "MD", "MDd", -- only for msvc + "c++_static", "c++_shared", -- gcc/clang + "stdc++_static", "stdc++_shared"}}, -- gcc/clang _language_menu_options, _platform_menu_options, {category = "Other Configuration"}, diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 48f1463e1..4199dbcc6 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -47,7 +47,7 @@ platform("android") , {nil, "android_sdk", "kv", nil, "The Android SDK Directory" } , {nil, "build_toolver", "kv", nil, "The Build Tool Version of Android SDK" } , {nil, "ndk_stdcxx", "kv", true, "Use stdc++ library for NDK" } - , {nil, "ndk_cxxstl", "kv", nil, "The stdc++ stl library for NDK", + , {nil, "ndk_cxxstl", "kv", nil, "The stdc++ stl library for NDK, (deprecated, please use --runtimes)", " - c++_static", " - c++_shared", " - gnustl_static", diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 84160b818..14ada8784 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -41,7 +41,7 @@ platform("windows") , " e.g. --vs_toolset=14.0" } , {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio" , " e.g. --vs_sdkver=10.0.15063.0" } - , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio" + , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio (deprecated, please use --runtimes)" , values = {"MT", "MTd", "MD", "MDd"} } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } -- cgit v1.3.1 From 64df1054c8c48a5f9008bd801759f8f4d696f616 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 00:19:30 +0800 Subject: get runtimes for target --- xmake/actions/config/xmake.lua | 9 ++++++--- xmake/core/project/target.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 48bcb6eef..57b9ff7ee 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -217,9 +217,12 @@ task("config") , "e.g. " , " - xmake f --runtimes=MTd" , " - xmake f --runtimes=MT,c++_static" - , values = {"MT", "MTd", "MD", "MDd", -- only for msvc - "c++_static", "c++_shared", -- gcc/clang - "stdc++_static", "stdc++_shared"}}, -- gcc/clang + , " - xmake f --runtimes=gcc::stdc++_static,clang::c++_static" + , values = {"MT", "MTd", "MD", "MDd", -- only for msvc + "c++_static", "c++_shared", -- gcc/clang/android ndk + "stdc++_static", "stdc++_shared", -- gcc/clang + "gnustl_static", "gnustl_shared", -- only for old android ndk + "stlport_static", "stlport_shared"}}, -- only for old android ndk _language_menu_options, _platform_menu_options, {category = "Other Configuration"}, diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index f4cdafb0e..ba87fa08d 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2380,6 +2380,35 @@ function _instance:pcoutputfile(langkind) end end +-- get runtimes +-- +-- set_runtimes("MTd") +-- set_runtimes("MT,c++_static") +-- set_runtimes("gcc::stdc++_static,clang::c++_static") +-- +function _instance:runtimes() + local runtimes = self:_memcache():get("runtimes") + if runtimes == nil then + runtimes = self:get("runtimes") or config.get("runtimes") + if self:is_plat("windows") then + runtimes = runtimes or config.get("vs_runtime") + elseif self:is_plat("android") then + runtimes = runtimes or config.get("ndk_cxxstl") + end + if runtimes then + runtimes = runtimes:split(",", {plain = true}) + end + runtimes = runtimes or {} + self:_memcache():set("runtimes", runtimes) + end + return runtimes +end + +-- has the given runtime for the current toolchain? +function _instance:has_runtime(name) + -- TODO +end + -- get the given toolchain function _instance:toolchain(name) local toolchains_map = self:_memcache():get("toolchains_map") @@ -2407,6 +2436,7 @@ function _instance:toolchains() local toolchain_opt = table.copy(self:extraconf("toolchains", name)) toolchain_opt.arch = self:arch() toolchain_opt.plat = self:plat() + toolchain_opt.runtimes = self:runtimes() local toolchain_inst, errors = toolchain.load(name, toolchain_opt) -- attempt to load toolchain from project if not toolchain_inst and target._project() then -- cgit v1.3.1 From c622a4e8a6542cc9234344ab323139f5e8f23612 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 23:22:46 +0800 Subject: pass runtimes to toolchain --- xmake/actions/config/xmake.lua | 1 - xmake/core/platform/platform.lua | 25 +++++++++++++++++++++++-- xmake/core/project/target.lua | 26 +++++++++++++++----------- xmake/core/tool/toolchain.lua | 20 ++++++++++++++++++++ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 57b9ff7ee..4bf43c787 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -217,7 +217,6 @@ task("config") , "e.g. " , " - xmake f --runtimes=MTd" , " - xmake f --runtimes=MT,c++_static" - , " - xmake f --runtimes=gcc::stdc++_static,clang::c++_static" , values = {"MT", "MTd", "MD", "MDd", -- only for msvc "c++_static", "c++_shared", -- gcc/clang/android ndk "stdc++_static", "stdc++_shared", -- gcc/clang diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 8a56a816e..322e976b8 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -147,6 +147,25 @@ function _instance:runenvs() return runenvs end +-- get runtimes +function _instance:runtimes() + local runtimes = self:_memcache():get("runtimes") + if runtimes == nil then + runtimes = config.get("runtimes") + if self:name() == "windows" then + runtimes = runtimes or config.get("vs_runtime") + elseif self:name() == "android" then + runtimes = runtimes or config.get("ndk_cxxstl") + end + if runtimes then + runtimes = table.unwrap(runtimes:split(",", {plain = true})) + end + runtimes = runtimes or false + self:_memcache():set("runtimes", runtimes) + end + return runtimes or nil +end + -- get the toolchains function _instance:toolchains(opt) local toolchains = self:_memcache():get("toolchains") @@ -162,7 +181,8 @@ function _instance:toolchains(opt) -- get the given toolchain local toolchain_given = config.get("toolchain") if toolchain_given then - local toolchain_inst, errors = toolchain.load(toolchain_given, {plat = self:name(), arch = self:arch()}) + local toolchain_inst, errors = toolchain.load(toolchain_given, { + plat = self:name(), arch = self:arch(), runtimes = self:runtimes()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(toolchain_given) @@ -181,7 +201,8 @@ function _instance:toolchains(opt) end if names then for _, name in ipairs(table.wrap(names)) do - local toolchain_inst, errors = toolchain.load(name, {plat = self:name(), arch = self:arch()}) + local toolchain_inst, errors = toolchain.load(name, { + plat = self:name(), arch = self:arch(), runtimes = self:runtimes()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ba87fa08d..74d8b77b5 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2381,11 +2381,6 @@ function _instance:pcoutputfile(langkind) end -- get runtimes --- --- set_runtimes("MTd") --- set_runtimes("MT,c++_static") --- set_runtimes("gcc::stdc++_static,clang::c++_static") --- function _instance:runtimes() local runtimes = self:_memcache():get("runtimes") if runtimes == nil then @@ -2396,17 +2391,26 @@ function _instance:runtimes() runtimes = runtimes or config.get("ndk_cxxstl") end if runtimes then - runtimes = runtimes:split(",", {plain = true}) + runtimes = table.unwrap(runtimes:split(",", {plain = true})) end - runtimes = runtimes or {} + runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) end - return runtimes + return runtimes or nil end --- has the given runtime for the current toolchain? -function _instance:has_runtime(name) - -- TODO +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self._RUNTIMES_SET + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self._RUNTIMES_SET = runtimes_set + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end end -- get the given toolchain diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 4831bce5c..020b790d8 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -29,6 +29,7 @@ local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local option = require("base/option") +local hashset = require("base/hashset") local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local config = require("project/config") @@ -107,6 +108,25 @@ function _instance:is_arch(...) end end +-- get toolchain runtimes +function _instance:runtimes() + return self:config("runtimes") +end + +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self._RUNTIMES_SET + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self._RUNTIMES_SET = runtimes_set + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end +end + -- get toolchain info function _instance:info() local arch = self:arch() -- cgit v1.3.1 From eddb673f8fffc281fa9a5c9ef56ef0c00495a627 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 23:42:09 +0800 Subject: limit toolchain runtimes --- xmake/core/platform/platform.lua | 7 +++++-- xmake/core/project/target.lua | 7 ++++++- xmake/core/tool/toolchain.lua | 19 ++++++++++++++++++- xmake/toolchains/clang/xmake.lua | 5 ++--- xmake/toolchains/gcc/xmake.lua | 8 ++------ xmake/toolchains/llvm/xmake.lua | 11 ++--------- xmake/toolchains/msvc/xmake.lua | 10 ++-------- xmake/toolchains/ndk/xmake.lua | 10 ++-------- 8 files changed, 39 insertions(+), 38 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 322e976b8..180e5401e 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -157,8 +157,11 @@ function _instance:runtimes() elseif self:name() == "android" then runtimes = runtimes or config.get("ndk_cxxstl") end - if runtimes then - runtimes = table.unwrap(runtimes:split(",", {plain = true})) + runtimes = runtimes:split(",", {plain = true}) + if #runtimes > 0 then + runtimes = table.unwrap(runtimes) + else + runtimes = nil end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 74d8b77b5..fd8421051 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2391,7 +2391,12 @@ function _instance:runtimes() runtimes = runtimes or config.get("ndk_cxxstl") end if runtimes then - runtimes = table.unwrap(runtimes:split(",", {plain = true})) + runtimes = runtimes:split(",", {plain = true}) + if #runtimes > 0 then + runtimes = table.unwrap(runtimes) + else + runtimes = nil + end end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 020b790d8..ab9673c91 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -110,7 +110,23 @@ end -- get toolchain runtimes function _instance:runtimes() - return self:config("runtimes") + local runtimes = self._RUNTIMES + if runtimes == nil then + runtimes = {} + local runtimes_supported = hashset.from(table.wrap(self:get("runtimes"))) + for _, runtime in ipairs(table.wrap(self:config("runtimes"))) do + if runtimes_supported:has(runtime) then + table.insert(runtimes, runtime) + end + end + if #runtimes > 0 then + runtimes = table.unwrap(runtimes) + else + runtimes = false + end + self._RUNTIMES = runtimes + end + return runtimes or nil end -- has the given runtime for the current toolchains? @@ -587,6 +603,7 @@ function toolchain.apis() , "toolchain.set_bindir" , "toolchain.set_sdkdir" , "toolchain.set_archs" + , "toolchain.set_runtimes" , "toolchain.set_homepage" , "toolchain.set_description" } diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 0f9662cee..981cac82e 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -25,11 +25,10 @@ if version then suffix = suffix .. "-" .. version end toolchain("clang" .. suffix) - + set_kind("standalone") set_homepage("https://clang.llvm.org/") set_description("A C language family frontend for LLVM" .. (version and (" (" .. version .. ")") or "")) - - set_kind("standalone") + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") set_toolset("cc", "clang" .. suffix) set_toolset("cxx", "clang" .. suffix, "clang++" .. suffix) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index 365341eda..b21f3592e 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -25,15 +25,11 @@ if version then suffix = suffix .. "-" .. version end toolchain("gcc" .. suffix) - - -- set homepage + set_kind("standalone") set_homepage("https://gcc.gnu.org/") set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or "")) + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- set toolset set_toolset("cc", "gcc" .. suffix) set_toolset("cxx", "gcc" .. suffix, "g++" .. suffix) set_toolset("ld", "g++" .. suffix, "gcc" .. suffix) diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index 3525a2d6d..ef27a2073 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -18,17 +18,12 @@ -- @file xmake.lua -- --- define toolchain toolchain("llvm") - - -- set homepage + set_kind("standalone") set_homepage("https://llvm.org/") set_description("A collection of modular and reusable compiler and toolchain technologies") + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- set toolset set_toolset("cc", "clang") set_toolset("cxx", "clang", "clang++") set_toolset("mxx", "clang", "clang++") @@ -42,10 +37,8 @@ toolchain("llvm") set_toolset("strip", "llvm-strip") set_toolset("mrc", "llvm-rc") - -- check toolchain on_check("check") - -- on load on_load(function (toolchain) -- add march flags diff --git a/xmake/toolchains/msvc/xmake.lua b/xmake/toolchains/msvc/xmake.lua index a79cb4268..9ef6babe1 100644 --- a/xmake/toolchains/msvc/xmake.lua +++ b/xmake/toolchains/msvc/xmake.lua @@ -30,16 +30,10 @@ -- @endcode -- toolchain("msvc") - - -- set homepage + set_kind("standalone") set_homepage("https://visualstudio.microsoft.com") set_description("Microsoft Visual C/C++ Compiler") + set_runtimes("MT", "MTd", "MD", "MDd") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load("load") diff --git a/xmake/toolchains/ndk/xmake.lua b/xmake/toolchains/ndk/xmake.lua index 609efb4a2..108d52275 100644 --- a/xmake/toolchains/ndk/xmake.lua +++ b/xmake/toolchains/ndk/xmake.lua @@ -30,16 +30,10 @@ -- @endcode -- toolchain("ndk") - - -- set homepage + set_kind("standalone") set_homepage("https://developer.android.com/ndk") set_description("Android NDK") + set_runtimes("c++_static", "c++_shared", "gnustl_static", "gnustl_shared", "stlport_static", "stlport_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load("load") -- cgit v1.3.1 From c5f7e1ffa4aefdccd4007cc3d291de6fc9413f38 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 23:45:45 +0800 Subject: add runtimes for clang-cl --- xmake/toolchains/clang-cl/xmake.lua | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/xmake/toolchains/clang-cl/xmake.lua b/xmake/toolchains/clang-cl/xmake.lua index 79ca6dc6e..443eba0a2 100644 --- a/xmake/toolchains/clang-cl/xmake.lua +++ b/xmake/toolchains/clang-cl/xmake.lua @@ -30,16 +30,10 @@ -- @endcode -- toolchain("clang-cl") - - -- set homepage + set_kind("standalone") set_homepage("https://visualstudio.microsoft.com") set_description("LLVM Clang C/C++ Compiler compatible with msvc") + set_runtimes("MT", "MTd", "MD", "MDd") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load("load") -- cgit v1.3.1 From ecaa9738b2f784f69009ca7902855f3528c08af9 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 23:49:52 +0800 Subject: fix platform error --- xmake/core/platform/platform.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 180e5401e..4a4b4bf96 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -157,11 +157,13 @@ function _instance:runtimes() elseif self:name() == "android" then runtimes = runtimes or config.get("ndk_cxxstl") end - runtimes = runtimes:split(",", {plain = true}) - if #runtimes > 0 then - runtimes = table.unwrap(runtimes) - else - runtimes = nil + if runtimes then + runtimes = runtimes:split(",", {plain = true}) + if #runtimes > 0 then + runtimes = table.unwrap(runtimes) + else + runtimes = nil + end end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) -- cgit v1.3.1 From 6059675c1ed54a7a77fb695b1ad3aef934640235 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jan 2024 23:54:27 +0800 Subject: use runtimes for ndk --- xmake/toolchains/ndk/load.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/toolchains/ndk/load.lua b/xmake/toolchains/ndk/load.lua index dac6388ca..b9e06c8dd 100644 --- a/xmake/toolchains/ndk/load.lua +++ b/xmake/toolchains/ndk/load.lua @@ -207,7 +207,7 @@ function main(toolchain) -- get c++ stl sdk directory local cxxstl_sdkdir = nil - local ndk_cxxstl = config.get("ndk_cxxstl") + local ndk_cxxstl = toolchain:runtimes() or config.get("ndk_cxxstl") if ndk_cxxstl then -- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then -- cgit v1.3.1 From bda43e3e865e2336db2bdf2b66af9beb235da1df Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Jan 2024 22:21:01 +0800 Subject: limit gcc runtimes --- xmake/toolchains/gcc/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index b21f3592e..9b01a80f5 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -28,7 +28,7 @@ toolchain("gcc" .. suffix) set_kind("standalone") set_homepage("https://gcc.gnu.org/") set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or "")) - set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") + set_runtimes("stdc++_static", "stdc++_shared") set_toolset("cc", "gcc" .. suffix) set_toolset("cxx", "gcc" .. suffix, "g++" .. suffix) -- cgit v1.3.1 From 5d2f15a1004be7baaaeb08b2e196ad77c52f9647 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Jan 2024 22:33:01 +0800 Subject: improve clang runtime --- xmake/core/project/target.lua | 2 +- xmake/modules/core/tools/cl.lua | 14 ++++++++++---- xmake/modules/core/tools/clang.lua | 32 +++++++++++++++++++++++++------- xmake/modules/core/tools/link.lua | 6 +++--- xmake/modules/core/tools/nvcc.lua | 8 +++++++- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index fd8421051..19f19e664 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2390,7 +2390,7 @@ function _instance:runtimes() elseif self:is_plat("android") then runtimes = runtimes or config.get("ndk_cxxstl") end - if runtimes then + if type(runtimes) == "string" then runtimes = runtimes:split(",", {plain = true}) if #runtimes > 0 then runtimes = table.unwrap(runtimes) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 2d267f508..799596ab7 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -184,10 +184,16 @@ function nf_optimize(self, level) return maps[level] end --- make vs runtime flag -function nf_runtime(self, vs_runtime) - if vs_runtime then - return "-" .. vs_runtime +-- make the runtime flag +function nf_runtime(self, runtime) + if runtime then + local maps = { + MT = "-MT", + MD = "-MD", + MTd = "-MTd", + MDd = "-MDd" + } + return maps[runtime] end end diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 28a00d84f..c9c6b854d 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -178,18 +178,18 @@ function _has_ms_runtime_lib(self) return has_ms_runtime_lib end --- make vs runtime flag +-- make the runtime flag -- @see https://github.com/xmake-io/xmake/issues/3546 -function nf_runtime(self, vs_runtime) - if self:is_plat("windows") and vs_runtime then +function nf_runtime(self, runtime) + local kind = self:kind() + if self:is_plat("windows") and runtime then if not _has_ms_runtime_lib(self) then - if vs_runtime:startswith("MD") then - wprint("%s runtime is not available for the current Clang compiler.", vs_runtime) + if runtime:startswith("MD") then + wprint("%s runtime is not available for the current Clang compiler.", runtime) end return end local maps - local kind = self:kind() if language.sourcekinds()[kind] then maps = { MT = "-fms-runtime-lib=static", @@ -205,7 +205,25 @@ function nf_runtime(self, vs_runtime) MDd = "-nostdlib" } end - return maps and maps[vs_runtime] + return maps and maps[runtime] + else + local maps + if kind == "cxx" then + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + else + maps = { + ["c++_static"] = {"-stdlib=libc++", "-static-libstdc++"}, + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = {"-stdlib=libstdc++", "-static-libstdc++"}, + ["stdc++_shared"] = "-stdlib=libstdc++", + } + end + return maps and maps[runtime] end end diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 9c53c2e28..a144d515e 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -113,9 +113,9 @@ function nf_syslink(self, lib) return nf_link(self, lib) end --- make vs runtime flag -function nf_runtime(self, vs_runtime) - if vs_runtime and vs_runtime:startswith("MT") then +-- make the runtime flag +function nf_runtime(self, runtime) + if runtime and runtime:startswith("MT") then return "-nodefaultlib:msvcrt.lib" end end diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index e67dc0749..3d23c0998 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -172,7 +172,13 @@ end -- make vs runtime flag function nf_runtime(self, vs_runtime) if self:is_plat("windows") and vs_runtime then - return '-Xcompiler "-' .. vs_runtime .. '"' + local maps = { + MT = '-Xcompiler "-MT"', + MD = '-Xcompiler "-MD"', + MTd = '-Xcompiler "-MTd"', + MDd = '-Xcompiler "-MDd"' + } + return maps[vs_runtime] end end -- cgit v1.3.1 From 4f7105af06f2b9f390b3441328911b48cb35b7e9 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Jan 2024 22:41:59 +0800 Subject: improve compile runtime rules --- xmake/core/project/target.lua | 16 +++------------- xmake/modules/core/tools/clang.lua | 3 ++- xmake/rules/utils/compiler_runtime/xmake.lua | 17 ++++++++++++----- xmake/toolchains/xcode/load_macosx.lua | 2 ++ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 19f19e664..e2262049a 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2384,19 +2384,9 @@ end function _instance:runtimes() local runtimes = self:_memcache():get("runtimes") if runtimes == nil then - runtimes = self:get("runtimes") or config.get("runtimes") - if self:is_plat("windows") then - runtimes = runtimes or config.get("vs_runtime") - elseif self:is_plat("android") then - runtimes = runtimes or config.get("ndk_cxxstl") - end - if type(runtimes) == "string" then - runtimes = runtimes:split(",", {plain = true}) - if #runtimes > 0 then - runtimes = table.unwrap(runtimes) - else - runtimes = nil - end + runtimes = self:get("runtimes") + if runtimes and #runtimes > 0 then + runtimes = table.unwrap(runtimes) end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index c9c6b854d..7e1f37b8d 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -207,6 +207,7 @@ function nf_runtime(self, runtime) end return maps and maps[runtime] else + --[[ local maps if kind == "cxx" then maps = { @@ -222,7 +223,7 @@ function nf_runtime(self, runtime) ["stdc++_static"] = {"-stdlib=libstdc++", "-static-libstdc++"}, ["stdc++_shared"] = "-stdlib=libstdc++", } - end + end]] return maps and maps[runtime] end end diff --git a/xmake/rules/utils/compiler_runtime/xmake.lua b/xmake/rules/utils/compiler_runtime/xmake.lua index f8e3d39d0..61681b235 100644 --- a/xmake/rules/utils/compiler_runtime/xmake.lua +++ b/xmake/rules/utils/compiler_runtime/xmake.lua @@ -21,11 +21,18 @@ -- define rule: utils.compiler.runtime rule("utils.compiler.runtime") on_config(function (target) - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) + local runtimes = get_config("runtimes") + if not runtimes and target:is_plat("windows") then + runtimes = get_config("vs_runtime") + end + if not runtimes and target:is_plat("android") then + runtimes = get_config("ndk_cxxstl") + end + if runtimes and not target:get("runtimes") then + if type(runtimes) == "string" then + runtimes = runtimes:split(",", {plain = true}) + end + target:set("runtimes", runtimes) end end) diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index 039152067..a52ad9389 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -83,4 +83,6 @@ function main(toolchain) -- init flags for objc/c++ (with ldflags and shflags) -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua toolchain:add("mxflags", "-fobjc-arc") + + print("11", toolchain:runtimes()) end -- cgit v1.3.1 From ecd32a1463825b40a6dc69695bbb0276b7236ae7 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Jan 2024 22:42:09 +0800 Subject: remove logs --- xmake/toolchains/xcode/load_macosx.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index a52ad9389..039152067 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -83,6 +83,4 @@ function main(toolchain) -- init flags for objc/c++ (with ldflags and shflags) -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua toolchain:add("mxflags", "-fobjc-arc") - - print("11", toolchain:runtimes()) end -- cgit v1.3.1 From a74bb4c14a8eda9c70062c1c6f592f2474672b71 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Jan 2024 22:43:29 +0800 Subject: improve android runtimes --- xmake/modules/core/tools/clang.lua | 5 ++--- xmake/rules/utils/compiler_runtime/xmake.lua | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 7e1f37b8d..673500599 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -206,8 +206,7 @@ function nf_runtime(self, runtime) } end return maps and maps[runtime] - else - --[[ + elseif not self:is_plat("android") then -- we will set runtimes in android ndk toolchain local maps if kind == "cxx" then maps = { @@ -223,7 +222,7 @@ function nf_runtime(self, runtime) ["stdc++_static"] = {"-stdlib=libstdc++", "-static-libstdc++"}, ["stdc++_shared"] = "-stdlib=libstdc++", } - end]] + end return maps and maps[runtime] end end diff --git a/xmake/rules/utils/compiler_runtime/xmake.lua b/xmake/rules/utils/compiler_runtime/xmake.lua index 61681b235..1a50fddef 100644 --- a/xmake/rules/utils/compiler_runtime/xmake.lua +++ b/xmake/rules/utils/compiler_runtime/xmake.lua @@ -24,9 +24,15 @@ rule("utils.compiler.runtime") local runtimes = get_config("runtimes") if not runtimes and target:is_plat("windows") then runtimes = get_config("vs_runtime") + if runtimes then + wprint("--vs_runtime=%s is deprecated, please use --runtimes=%s", runtimes, runtimes) + end end if not runtimes and target:is_plat("android") then runtimes = get_config("ndk_cxxstl") + if runtimes then + wprint("--ndk_cxxstl=%s is deprecated, please use --runtimes=%s", runtimes, runtimes) + end end if runtimes and not target:get("runtimes") then if type(runtimes) == "string" then -- cgit v1.3.1 From 9f76e77a010c835f17a8a4ed65254df84e38d7e7 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Jan 2024 22:44:25 +0800 Subject: remove stdc++ for apple os --- xmake/toolchains/xcode/load_appletvos.lua | 8 ++------ xmake/toolchains/xcode/load_applexros.lua | 4 ---- xmake/toolchains/xcode/load_iphoneos.lua | 8 ++------ xmake/toolchains/xcode/load_macosx.lua | 6 ------ xmake/toolchains/xcode/load_watchos.lua | 8 ++------ 5 files changed, 6 insertions(+), 28 deletions(-) diff --git a/xmake/toolchains/xcode/load_appletvos.lua b/xmake/toolchains/xcode/load_appletvos.lua index aad701ad5..8d723149f 100644 --- a/xmake/toolchains/xcode/load_appletvos.lua +++ b/xmake/toolchains/xcode/load_appletvos.lua @@ -18,10 +18,6 @@ -- @file load_appletvos.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) -- init architecture @@ -38,8 +34,8 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("shflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) -- init flags for objc/c++ toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) diff --git a/xmake/toolchains/xcode/load_applexros.lua b/xmake/toolchains/xcode/load_applexros.lua index 61b142374..09805cdc3 100644 --- a/xmake/toolchains/xcode/load_applexros.lua +++ b/xmake/toolchains/xcode/load_applexros.lua @@ -18,10 +18,6 @@ -- @file load_applexros.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) local arch = toolchain:arch() diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index 77a581b0c..a36fa50b9 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -18,10 +18,6 @@ -- @file load_iphoneos.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) -- init architecture @@ -41,8 +37,8 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("shflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) -- init flags for objc/c++ toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index 039152067..071f8ec6d 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -18,10 +18,6 @@ -- @file load_macosx.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) local arch = toolchain:arch() @@ -75,8 +71,6 @@ function main(toolchain) end -- init flags for c/c++ - toolchain:add("ldflags", "-stdlib=libc++") - toolchain:add("shflags", "-stdlib=libc++") toolchain:add("ldflags", "-lz") toolchain:add("shflags", "-lz") diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index a727776bd..cceabeb02 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -18,10 +18,6 @@ -- @file load_watchos.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) -- init architecture @@ -38,8 +34,8 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("shflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) -- init flags for objc/c++ toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) -- cgit v1.3.1 From ad109d0818b38889e703a038514a3acb0d90cdd7 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Jan 2024 23:40:57 +0800 Subject: rename vs_runtime to runtimes in package configs --- tests/projects/package/depconfigs/xmake.lua | 4 +-- xmake/modules/core/tools/nvcc.lua | 6 ++-- .../package/manager/conan/v1/install_package.lua | 4 +-- .../package/manager/conan/v2/install_package.lua | 8 ++--- .../package/manager/vcpkg/configurations.lua | 2 +- .../private/action/require/impl/package.lua | 39 +++++++++++++--------- xmake/modules/private/action/trybuild/xrepo.lua | 5 +-- xmake/modules/private/xrepo/action/env.lua | 2 +- xmake/modules/private/xrepo/action/export.lua | 2 +- xmake/modules/private/xrepo/action/fetch.lua | 2 +- xmake/modules/private/xrepo/action/import.lua | 2 +- xmake/modules/private/xrepo/action/info.lua | 2 +- xmake/modules/private/xrepo/action/install.lua | 2 +- xmake/modules/private/xrepo/action/remove.lua | 2 +- xmake/plugins/project/cmake/cmakelists.lua | 32 +++++++++--------- 15 files changed, 62 insertions(+), 52 deletions(-) diff --git a/tests/projects/package/depconfigs/xmake.lua b/tests/projects/package/depconfigs/xmake.lua index 377c8899b..11623755c 100644 --- a/tests/projects/package/depconfigs/xmake.lua +++ b/tests/projects/package/depconfigs/xmake.lua @@ -1,5 +1,5 @@ -add_requires("libpng", {system = false, configs = {vs_runtime = "MD"}}) -add_requires("libtiff", {system = false, configs = {vs_runtime = "MD", zlib = true}}) +add_requires("libpng", {system = false, configs = {runtimes = "MD"}}) +add_requires("libtiff", {system = false, configs = {runtimes = "MD", zlib = true}}) add_requireconfs("libpng.zlib", {system = false, override = true, configs = {cxflags = "-DTEST1"}, version = "1.2.10"}) add_requireconfs("libtiff.*|cmake", {system = false, configs = {cxflags = "-DTEST2"}}) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 3d23c0998..15ef721d0 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -170,15 +170,15 @@ function nf_optimize(self, level) end -- make vs runtime flag -function nf_runtime(self, vs_runtime) - if self:is_plat("windows") and vs_runtime then +function nf_runtime(self, runtime) + if self:is_plat("windows") and runtime then local maps = { MT = '-Xcompiler "-MT"', MD = '-Xcompiler "-MD"', MTd = '-Xcompiler "-MTd"', MDd = '-Xcompiler "-MDd"' } - return maps[vs_runtime] + return maps[runtime] end end diff --git a/xmake/modules/package/manager/conan/v1/install_package.lua b/xmake/modules/package/manager/conan/v1/install_package.lua index e443e585b..3475a21b3 100644 --- a/xmake/modules/package/manager/conan/v1/install_package.lua +++ b/xmake/modules/package/manager/conan/v1/install_package.lua @@ -211,9 +211,9 @@ function main(conan, name, opt) table.insert(argv, "compiler=Visual Studio") table.insert(argv, "-s") table.insert(argv, "compiler.version=" .. assert(vsvers[vs], "unknown msvc version!")) - if configs.vs_runtime then + if configs.runtimes then table.insert(argv, "-s") - table.insert(argv, "compiler.runtime=" .. configs.vs_runtime) + table.insert(argv, "compiler.runtime=" .. configs.runtimes) end elseif opt.plat == "iphoneos" then local target_minver = nil diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index eb4299d83..bf561124e 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -182,10 +182,10 @@ function _conan_generate_compiler_profile(profile, configs, opt) if tonumber(vs) >= 2015 then profile:print("compiler.cppstd=14") end - local vs_runtime = configs.vs_runtime - if vs_runtime then - profile:print("compiler.runtime=" .. (vs_runtime:startswith("MD") and "dynamic" or "static")) - profile:print("compiler.runtime_type=" .. (vs_runtime:endswith("d") and "Debug" or "Release")) + local runtimes = configs.runtimes + if runtimes then + profile:print("compiler.runtime=" .. (runtimes:startswith("MD") and "dynamic" or "static")) + profile:print("compiler.runtime_type=" .. (runtimes:endswith("d") and "Debug" or "Release")) end elseif plat == "iphoneos" then local target_minver = nil diff --git a/xmake/modules/package/manager/vcpkg/configurations.lua b/xmake/modules/package/manager/vcpkg/configurations.lua index 997f8fa35..cb81e560a 100644 --- a/xmake/modules/package/manager/vcpkg/configurations.lua +++ b/xmake/modules/package/manager/vcpkg/configurations.lua @@ -52,7 +52,7 @@ function triplet(configs, plat, arch) local triplet = arch .. "-" .. plat if plat == "windows" and configs.shared ~= true then triplet = triplet .. "-static" - if configs.vs_runtime and configs.vs_runtime:startswith("MD") then + if configs.runtimes and configs.runtimes:startswith("MD") then triplet = triplet .. "-md" end elseif plat == "mingw" then diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 8bbeeee45..7a9d89bf8 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -152,6 +152,13 @@ function _load_require(require_str, requires_extra, parentinfo) require_build_configs.debug = true end + -- vs_runtime is deprecated, we should use runtimes + if require_build_configs and require_build_configs.vs_runtime then + require_build_configs.runtimes = require_build_configs.vs_runtime + require_build_configs.vs_runtime = nil + wprint("add_requires(%s): vs_runtime is deprecated, please use runtimes!", require_str) + end + -- require packge in the current host platform if require_extra.host then if is_subhost(core_package.targetplat()) and os.subarch() == core_package.targetarch() then @@ -346,8 +353,10 @@ function _add_package_configurations(package) if package:extraconf("configs", "asan", "default") == nil then package:add("configs", "asan", {builtin = true, description = "Enable the address sanitizer.", type = "boolean"}) end - if package:extraconf("configs", "vs_runtime", "default") == nil then - package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", values = {"MT", "MTd", "MD", "MDd"}}) + if package:extraconf("configs", "runtimes", "default") == nil then + package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", values = { + "MT", "MTd", "MD", "MDd", + "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"}}) end if package:extraconf("configs", "toolchains", "default") == nil then package:add("configs", "toolchains", {builtin = true, description = "Set package toolchains only for cross-compilation."}) @@ -513,9 +522,9 @@ function _init_requireinfo(requireinfo, package, opt) requireinfo.configs.toolchains = requireinfo.configs.toolchains or get_config("toolchain") end end - requireinfo.configs.vs_runtime = requireinfo.configs.vs_runtime or project.get("target.runtimes") + requireinfo.configs.runtimes = requireinfo.configs.runtimes or project.get("target.runtimes") if project.policy("package.inherit_external_configs") then - requireinfo.configs.vs_runtime = requireinfo.configs.vs_runtime or get_config("vs_runtime") + requireinfo.configs.runtimes = requireinfo.configs.runtimes or get_config("runtimes") or get_config("vs_runtime") end if requireinfo.configs.lto == nil then requireinfo.configs.lto = project.policy("build.optimization.lto") @@ -527,7 +536,7 @@ function _init_requireinfo(requireinfo, package, opt) -- but we will ignore some configs for buildhash in the headeronly and host/binary package -- @note on_test still need these configs, @see https://github.com/xmake-io/xmake/issues/4124 if package:is_headeronly() or (package:is_binary() and not package:is_cross()) then - requireinfo.ignored_configs_for_buildhash = {"vs_runtime", "toolchains", "lto", "asan", "pic"} + requireinfo.ignored_configs_for_buildhash = {"runtimes", "toolchains", "lto", "asan", "pic"} end end @@ -542,8 +551,8 @@ function _finish_requireinfo(requireinfo, package) end requireinfo.configs = requireinfo.configs or {} if not package:is_headeronly() then - if requireinfo.configs.vs_runtime == nil and package:is_plat("windows") then - requireinfo.configs.vs_runtime = "MT" + if requireinfo.configs.runtimes == nil and package:is_plat("windows") then + requireinfo.configs.runtimes = "MT" end end -- we need to ensure readonly configs @@ -568,9 +577,9 @@ end -- merge requireinfo from `add_requireconfs()` -- --- add_requireconfs("*", {system = false, configs = {vs_runtime = "MD"}}) --- add_requireconfs("lib*", {system = false, configs = {vs_runtime = "MD"}}) --- add_requireconfs("libwebp", {system = false, configs = {vs_runtime = "MD"}}) +-- add_requireconfs("*", {system = false, configs = {runtimes = "MD"}}) +-- add_requireconfs("lib*", {system = false, configs = {runtimes = "MD"}}) +-- add_requireconfs("libwebp", {system = false, configs = {runtimes = "MD"}}) -- add_requireconfs("libpng.zlib", {system = false, override = true, configs = {cxflags = "-DTEST1"}, version = "1.2.10"}) -- add_requireconfs("libtiff.*", {system = false, configs = {cxflags = "-DTEST2"}}) -- add_requireconfs("libwebp.**|cmake|autoconf", {system = false, configs = {cxflags = "-DTEST3"}}) -- recursive deps @@ -660,15 +669,15 @@ function _get_packagelock_key(requireinfo) end -- inherit some builtin configs of parent package if these config values are not default value --- e.g. add_requires("libpng", {configs = {vs_runtime = "MD", pic = false}}) +-- e.g. add_requires("libpng", {configs = {runtimes = "MD", pic = false}}) -- function _inherit_parent_configs(requireinfo, package, parentinfo) if package:is_library() then local requireinfo_configs = requireinfo.configs or {} local parentinfo_configs = parentinfo.configs or {} if not requireinfo_configs.shared then - if requireinfo_configs.vs_runtime == nil then - requireinfo_configs.vs_runtime = parentinfo_configs.vs_runtime + if requireinfo_configs.runtimes == nil then + requireinfo_configs.runtimes = parentinfo_configs.runtimes end if requireinfo_configs.pic == nil then requireinfo_configs.pic = parentinfo_configs.pic @@ -681,7 +690,7 @@ function _inherit_parent_configs(requireinfo, package, parentinfo) requireinfo.arch = parentinfo.arch end requireinfo_configs.toolchains = requireinfo_configs.toolchains or parentinfo_configs.toolchains - requireinfo_configs.vs_runtime = requireinfo_configs.vs_runtime or parentinfo_configs.vs_runtime + requireinfo_configs.runtimes = requireinfo_configs.runtimes or parentinfo_configs.runtimes requireinfo_configs.lto = requireinfo_configs.lto or parentinfo_configs.lto requireinfo_configs.asan = requireinfo_configs.asan or parentinfo_configs.asan requireinfo.configs = requireinfo_configs @@ -838,7 +847,7 @@ function _load_package(packagename, requireinfo, opt) -- merge requireinfo from `add_requireconfs()` _merge_requireinfo(requireinfo, opt.requirepath) - -- inherit some builtin configs of parent package, e.g. vs_runtime, pic + -- inherit some builtin configs of parent package, e.g. runtimes, pic if opt.parentinfo then _inherit_parent_configs(requireinfo, package, opt.parentinfo) end diff --git a/xmake/modules/private/action/trybuild/xrepo.lua b/xmake/modules/private/action/trybuild/xrepo.lua index cfb63e553..31d866d58 100644 --- a/xmake/modules/private/action/trybuild/xrepo.lua +++ b/xmake/modules/private/action/trybuild/xrepo.lua @@ -111,9 +111,10 @@ function _get_common_configs(argv) if config.get("toolchain") then table.insert(argv, "--toolchain=" .. config.get("toolchain")) end - if config.get("vs_runtime") then + local runtimes = config.get("runtimes") or config.get("vs_runtime") + if runtimes then table.insert(argv, "-f") - table.insert(argv, "vs_runtime='" .. config.get("vs_runtime") .. "'") + table.insert(argv, "runtimes='" .. runtimes .. "'") end end diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 5a9347922..b2e421f24 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -49,7 +49,7 @@ function menu_options() {nil, "show", "k", nil, "Only show environment information." }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo env -f \"vs_runtime='MD'\" zlib cmake ..", + " - xrepo env -f \"runtimes='MD'\" zlib cmake ..", " - xrepo env -f \"regex=true,thread=true\" \"zlib,boost\" cmake .."}, {nil, "add", "k", nil, "Add global environment config.", "e.g.", diff --git a/xmake/modules/private/xrepo/action/export.lua b/xmake/modules/private/xrepo/action/export.lua index 551d978a3..4c718bcb0 100644 --- a/xmake/modules/private/xrepo/action/export.lua +++ b/xmake/modules/private/xrepo/action/export.lua @@ -39,7 +39,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo export -f \"vs_runtime='MD'\" zlib", + " - xrepo export -f \"runtimes='MD'\" zlib", " - xrepo export -f \"regex=true,thread=true\" boost"}, {}, {nil, "includes", "kv", nil, "Includes extra lua configuration files."}, diff --git a/xmake/modules/private/xrepo/action/fetch.lua b/xmake/modules/private/xrepo/action/fetch.lua index b54294a68..4455d21e7 100644 --- a/xmake/modules/private/xrepo/action/fetch.lua +++ b/xmake/modules/private/xrepo/action/fetch.lua @@ -38,7 +38,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo fetch --configs=\"vs_runtime='MD'\" zlib", + " - xrepo fetch --configs=\"runtimes='MD'\" zlib", " - xrepo fetch --configs=\"regex=true,thread=true\" boost"}, {nil, "system", "k", "false", "Only fetch package on current system."}, {}, diff --git a/xmake/modules/private/xrepo/action/import.lua b/xmake/modules/private/xrepo/action/import.lua index 8c32e2c0f..7ad0a1759 100644 --- a/xmake/modules/private/xrepo/action/import.lua +++ b/xmake/modules/private/xrepo/action/import.lua @@ -39,7 +39,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo import -f \"vs_runtime='MD'\" zlib", + " - xrepo import -f \"runtimes='MD'\" zlib", " - xrepo import -f \"regex=true,thread=true\" boost"}, {}, {'i', "packagedir", "kv", "packages","Set the imported packages directory."}, diff --git a/xmake/modules/private/xrepo/action/info.lua b/xmake/modules/private/xrepo/action/info.lua index 3bc547b94..e89ac80af 100644 --- a/xmake/modules/private/xrepo/action/info.lua +++ b/xmake/modules/private/xrepo/action/info.lua @@ -38,7 +38,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo fetch --configs=\"vs_runtime='MD'\" zlib", + " - xrepo fetch --configs=\"runtimes='MD'\" zlib", " - xrepo fetch --configs=\"regex=true,thread=true\" boost"}, {}, {nil, "packages", "vs", nil, "The packages list.", diff --git a/xmake/modules/private/xrepo/action/install.lua b/xmake/modules/private/xrepo/action/install.lua index dfcaadf80..81420f51f 100644 --- a/xmake/modules/private/xrepo/action/install.lua +++ b/xmake/modules/private/xrepo/action/install.lua @@ -38,7 +38,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo install -f \"vs_runtime='MD'\" zlib", + " - xrepo install -f \"runtimes='MD'\" zlib", " - xrepo install -f \"regex=true,thread=true\" boost"}, {'j', "jobs", "kv", tostring(os.default_njob()), "Set the number of parallel compilation jobs."}, diff --git a/xmake/modules/private/xrepo/action/remove.lua b/xmake/modules/private/xrepo/action/remove.lua index dd850deb6..38be707fb 100644 --- a/xmake/modules/private/xrepo/action/remove.lua +++ b/xmake/modules/private/xrepo/action/remove.lua @@ -39,7 +39,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo remove -f \"vs_runtime='MD'\" zlib", + " - xrepo remove -f \"runtimes='MD'\" zlib", " - xrepo remove -f \"regex=true,thread=true\" boost"}, {nil, "toolchain", "kv", nil, "Set the toolchain name." }, {}, diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index ddef34471..6fcf38313 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -753,31 +753,31 @@ function _add_target_symbols(cmakelists, target) end end --- add target vs runtime +-- add target runtimes -- -- https://github.com/xmake-io/xmake/issues/1661#issuecomment-927979489 -- https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html -- -function _add_target_vs_runtime(cmakelists, target) +function _add_target_runtimes(cmakelists, target) local cmake_minver = _get_cmake_minver() if cmake_minver:ge("3.15.0") then - local vs_runtime = target:get("runtimes") + local runtimes = target:get("runtimes") cmakelists:print("if(MSVC)") - if vs_runtime then - if vs_runtime == "MT" then - vs_runtime = "MultiThreaded" - elseif vs_runtime == "MTd" then - vs_runtime = "MultiThreadedDebug" - elseif vs_runtime == "MD" then - vs_runtime = "MultiThreadedDLL" - elseif vs_runtime == "MDd" then - vs_runtime = "MultiThreadedDebugDLL" + if runtimes then + if runtimes == "MT" then + runtimes = "MultiThreaded" + elseif runtimes == "MTd" then + runtimes = "MultiThreadedDebug" + elseif runtimes == "MD" then + runtimes = "MultiThreadedDLL" + elseif runtimes == "MDd" then + runtimes = "MultiThreadedDebugDLL" end else - vs_runtime = "MultiThreaded$<$:Debug>" + runtimes = "MultiThreaded$<$:Debug>" end cmakelists:print(' set_property(TARGET %s PROPERTY', target:name()) - cmakelists:print(' MSVC_RUNTIME_LIBRARY "%s")', vs_runtime) + cmakelists:print(' MSVC_RUNTIME_LIBRARY "%s")', runtimes) cmakelists:print("endif()") end end @@ -1047,8 +1047,8 @@ function _add_target(cmakelists, target, outputdir) -- add target symbols _add_target_symbols(cmakelists, target) - -- add vs runtime for msvc - _add_target_vs_runtime(cmakelists, target) + -- add target runtimes + _add_target_runtimes(cmakelists, target) -- add target link libraries _add_target_link_libraries(cmakelists, target, outputdir) -- cgit v1.3.1 From 0b4aa5644e51a62aa69e8d41f81b48629910a5c2 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 22:36:52 +0800 Subject: improve to check runtimes --- .../private/action/require/impl/package.lua | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 7a9d89bf8..c46a62025 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -354,9 +354,23 @@ function _add_package_configurations(package) package:add("configs", "asan", {builtin = true, description = "Enable the address sanitizer.", type = "boolean"}) end if package:extraconf("configs", "runtimes", "default") == nil then - package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", values = { - "MT", "MTd", "MD", "MDd", - "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"}}) + local values = {"MT", "MTd", "MD", "MDd", + "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"} + package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", values = values, restrict = function (value) + local values_set = hashset.from(values) + if type(value) == "string" then + if not values_set:has(value) then + return false + end + elseif type(value) == "table" then + for _, item in ipairs(value) do + if not values_set:has(item) then + return false + end + end + end + return true + end}) end if package:extraconf("configs", "toolchains", "default") == nil then package:add("configs", "toolchains", {builtin = true, description = "Set package toolchains only for cross-compilation."}) @@ -447,7 +461,11 @@ function _check_package_configurations(package) if config_type ~= nil and type(value) ~= config_type then raise("package(%s %s): invalid type(%s) for config(%s), need type(%s)!", package:displayname(), package:version_str(), type(value), name, config_type) end - if conf.values then + if conf.restrict then + if not conf.restrict(value) then + raise("package(%s %s): invalid value(%s) for config(%s)!", package:displayname(), package:version_str(), string.serialize(value, {indent = false}), name) + end + elseif conf.values then local found = false for _, config_value in ipairs(conf.values) do if tostring(value) == tostring(config_value) then @@ -459,11 +477,6 @@ function _check_package_configurations(package) raise("package(%s %s): invalid value(%s) for config(%s), please run `xmake require --info %s` to get all valid values!", package:displayname(), package:version_str(), value, name, package:name()) end end - if conf.restrict then - if not conf.restrict(value) then - raise("package(%s %s): invalid value(%s) for config(%s)!", package:displayname(), package:version_str(), value, name) - end - end else raise("package(%s %s): invalid config(%s), please run `xmake require --info %s` to get all configurations!", package:displayname(), package:version_str(), name, package:name()) end -- cgit v1.3.1 From a053cf76793f0b0ce3da1d709a0d10db4ec45a30 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 22:43:58 +0800 Subject: improve package runtime type --- xmake/modules/private/action/require/impl/package.lua | 16 +++++++++------- .../private/action/require/impl/remove_packages.lua | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index c46a62025..cd61404d0 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -356,14 +356,13 @@ function _add_package_configurations(package) if package:extraconf("configs", "runtimes", "default") == nil then local values = {"MT", "MTd", "MD", "MDd", "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"} - package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", values = values, restrict = function (value) + package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", type = "string", values = values, restrict = function (value) local values_set = hashset.from(values) - if type(value) == "string" then - if not values_set:has(value) then - return false - end - elseif type(value) == "table" then - for _, item in ipairs(value) do + if type(value) ~= "string" then + return false + end + if value then + for _, item in ipairs(value:split(",", {plain = true})) do if not values_set:has(item) then return false end @@ -539,6 +538,9 @@ function _init_requireinfo(requireinfo, package, opt) if project.policy("package.inherit_external_configs") then requireinfo.configs.runtimes = requireinfo.configs.runtimes or get_config("runtimes") or get_config("vs_runtime") end + if type(requireinfo.configs.runtimes) == "table" then + requireinfo.configs.runtimes = table.concat(requireinfo.configs.runtimes, ",") + end if requireinfo.configs.lto == nil then requireinfo.configs.lto = project.policy("build.optimization.lto") end diff --git a/xmake/modules/private/action/require/impl/remove_packages.lua b/xmake/modules/private/action/require/impl/remove_packages.lua index 1a5e99f83..3dcfeecf9 100644 --- a/xmake/modules/private/action/require/impl/remove_packages.lua +++ b/xmake/modules/private/action/require/impl/remove_packages.lua @@ -33,7 +33,7 @@ function _get_package_configs_str(manifest_file) if type(v) == "boolean" then table.insert(configs, k .. ":" .. (v and "y" or "n")) else - table.insert(configs, k .. ":" .. v) + table.insert(configs, k .. ":" .. string.serialize(v, {strip = true, indent = false})) end end local configs_str = #configs > 0 and "[" .. table.concat(configs, ", ") .. "]" or "" -- cgit v1.3.1 From cb4f23888446db5392ca67219a370328b459693a Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 22:46:09 +0800 Subject: improve package:config --- xmake/core/package/package.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index d5e82b13f..e271cc64c 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1391,6 +1391,19 @@ function _instance:config(name) local configs = self:configs() if configs then value = configs[name] + -- vs_runtime is deprecated now + if name == "vs_runtime" then + local runtimes = configs.runtimes + if runtimes then + for _, item in ipairs(runtimes:split(",")) do + if item:startswith("MT") or item:startswith("MD") then + value = item + break + end + end + end + utils.warning("please use package:runtimes() or package:has_runtime() instead of package:config(\"vs_runtime\")") + end end return value end -- cgit v1.3.1 From 2fb724f49f1ededb23998688c90ba01ec0d12467 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 22:51:51 +0800 Subject: pass runtimes to 3rd package --- xmake/core/package/package.lua | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index e271cc64c..992650005 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1130,6 +1130,34 @@ function _instance:build_envs(lazy_loading) return build_envs end +-- get runtimes +function _instance:runtimes() + local runtimes = self:_memcache():get("runtimes") + if runtimes == nil then + runtimes = self:config("runtimes") + if runtimes then + runtimes = table.unwrap(runtimes:split(",", {plain = true})) + end + runtimes = runtimes or false + self:_memcache():set("runtimes", runtimes) + end + return runtimes or nil +end + +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self._RUNTIMES_SET + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self._RUNTIMES_SET = runtimes_set + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end +end + -- get the given toolchain function _instance:toolchain(name) local toolchains_map = self._TOOLCHAINS_MAP @@ -1788,6 +1816,13 @@ function _instance:find_package(name, opt) if system == nil and not name:startswith("xmake::") then system = true -- find system package by default end + local configs = table.clone(self:configs()) or {} + if opt.configs then + table.join2(configs, opt.configs) + end + if configs.runtimes then + configs.runtimes = self:runtimes() + end return self._find_package(name, { force = opt.force, installdir = self:installdir({readonly = true}), @@ -1796,7 +1831,7 @@ function _instance:find_package(name, opt) mode = self:mode(), plat = self:plat(), arch = self:arch(), - configs = table.join(self:configs(), opt.configs), + configs = configs, components = self:components_orderlist(), components_extsources = opt.components_extsources, buildhash = self:buildhash(), -- for xmake package or 3rd package manager, e.g. go:: .. @@ -2678,7 +2713,8 @@ function package.load_from_system(packagename) -- on install script local on_install = function (pkg) local opt = {} - opt.configs = pkg:configs() + local configs = table.clone(pkg:configs()) or {} + opt.configs = configs opt.mode = pkg:is_debug() and "debug" or "release" opt.plat = pkg:plat() opt.arch = pkg:arch() @@ -2686,6 +2722,9 @@ function package.load_from_system(packagename) opt.buildhash = pkg:buildhash() opt.cachedir = pkg:cachedir() opt.installdir = pkg:installdir() + if configs.runtimes then + configs.runtimes = pkg:runtimes() + end import("package.manager.install_package")(pkg:name(), opt) end -- cgit v1.3.1 From 229bccd5eeca9fb6da8b93c76d0d13f9c2b85314 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 22:55:55 +0800 Subject: remove more vs_runtime --- tests/projects/package/components/xmake.lua | 2 +- xmake/core/package/package.lua | 18 +++++++++--------- xmake/modules/package/tools/cmake.lua | 20 ++++++++++---------- xmake/modules/package/tools/meson.lua | 8 ++++---- xmake/modules/package/tools/xmake.lua | 8 ++++---- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/projects/package/components/xmake.lua b/tests/projects/package/components/xmake.lua index 6185f5178..14dbe472d 100644 --- a/tests/projects/package/components/xmake.lua +++ b/tests/projects/package/components/xmake.lua @@ -175,7 +175,7 @@ package("sfml") table.insert(configs, "-DBUILD_SHARED_LIBS=ON") else table.insert(configs, "-DBUILD_SHARED_LIBS=OFF") - if package:is_plat("windows") and package:config("vs_runtime"):startswith("MT") then + if package:is_plat("windows") and package:runtimes():startswith("MT") then table.insert(configs, "-DSFML_USE_STATIC_STD_LIBS=ON") end end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 992650005..69d2b234d 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2260,21 +2260,21 @@ function _instance:_generate_build_configs(configs, opt) configs = table.join(self:fetch_librarydeps(), configs) if self:is_plat("windows") then local ld = self:build_getenv("ld") - local vs_runtime = self:config("vs_runtime") - -- since we are ignoring the vs_runtime of the headeronly library, - -- we can only get the vs_runtime from the dependency library to detect the link. - if self:is_headeronly() and not vs_runtime and self:librarydeps() then + local runtimes = self:runtimes() + -- since we are ignoring the runtimes of the headeronly library, + -- we can only get the runtimes from the dependency library to detect the link. + if self:is_headeronly() and not runtimes and self:librarydeps() then for _, dep in ipairs(self:librarydeps()) do - if dep:is_plat("windows") and dep:config("vs_runtime") then - vs_runtime = dep:config("vs_runtime") + if dep:is_plat("windows") and dep:runtimes() then + runtimes = dep:runtimes() break end end end - if vs_runtime and ld and path.basename(ld:lower()) == "link" then -- for msvc? + if runtimes and ld and path.basename(ld:lower()) == "link" then -- for msvc? configs.cxflags = table.wrap(configs.cxflags) - table.insert(configs.cxflags, "/" .. vs_runtime) - if vs_runtime:startswith("MT") then + table.insert(configs.cxflags, "/" .. runtimes) + if runtimes:startswith("MT") then configs.ldflags = table.wrap(configs.ldflags) table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib") end diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 859af33dc..cd176e58c 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -352,24 +352,24 @@ function _get_configs_for_windows(package, configs, opt) -- we maybe need patch `cmake_policy(SET CMP0091 NEW)` to enable this argument for some packages -- @see https://cmake.org/cmake/help/latest/policy/CMP0091.html#policy:CMP0091 -- https://github.com/xmake-io/xmake-repo/pull/303 - local vs_runtime = package:config("vs_runtime") - if vs_runtime == "MT" then + if package:has_runtime("MT") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded") - elseif vs_runtime == "MTd" then + elseif package:has_runtime("MTd") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug") - elseif vs_runtime == "MD" then + elseif package:has_runtime("MD") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL") - elseif vs_runtime == "MDd" then + elseif package:has_runtime("MDd") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL") end - if vs_runtime then + local runtimes = package:runtimes() + if runtimes then -- CMake default MSVC flags as of 3.21.2 local default_debug_flags = "/Zi /Ob0 /Od /RTC1" local default_release_flags = "/O2 /Ob2 /DNDEBUG" - table.insert(configs, '-DCMAKE_CXX_FLAGS_DEBUG=/' .. vs_runtime .. ' ' .. default_debug_flags) - table.insert(configs, '-DCMAKE_CXX_FLAGS_RELEASE=/' .. vs_runtime .. ' ' .. default_release_flags) - table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG=/' .. vs_runtime .. ' ' .. default_debug_flags) - table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE=/' .. vs_runtime .. ' ' .. default_release_flags) + table.insert(configs, '-DCMAKE_CXX_FLAGS_DEBUG=/' .. runtimes .. ' ' .. default_debug_flags) + table.insert(configs, '-DCMAKE_CXX_FLAGS_RELEASE=/' .. runtimes .. ' ' .. default_release_flags) + table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG=/' .. runtimes .. ' ' .. default_debug_flags) + table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE=/' .. runtimes .. ' ' .. default_release_flags) end if not opt._configs_str:find("CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY") then table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=pdb") diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 56fc35bc4..e4d740d16 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -316,10 +316,10 @@ function _get_configs(package, configs, opt) table.insert(configs, "-Db_sanitize=address") end - -- add vs_runtime flags - local vs_runtime = package:config("vs_runtime") - if package:is_plat("windows") and vs_runtime then - table.insert(configs, "-Db_vscrt=" .. vs_runtime:lower()) + -- add runtimes flags + local runtimes = package:runtimes() + if package:is_plat("windows") and runtimes then + table.insert(configs, "-Db_vscrt=" .. runtimes:lower()) end -- add cross file diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 379a46d19..27c0bd872 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -77,10 +77,10 @@ function _get_configs_for_windows(package, configs, opt) table.insert(configs, "--" .. name .. "=" .. tostring(value)) end end - -- pass vs_runtime from package configs - local vs_runtime = package:config("vs_runtime") - if vs_runtime then - table.insert(configs, "--vs_runtime=" .. vs_runtime) + -- pass runtimes from package configs + local runtimes = package:config("runtimes") + if runtimes then + table.insert(configs, "--runtimes=" .. runtimes) end _get_configs_for_qt(package, configs, opt) _get_configs_for_vcpkg(package, configs, opt) -- cgit v1.3.1 From eeb0f80823bfd4fdd45a9d9a4eede7f407905fea Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:00:29 +0800 Subject: remove toolchain runtimes --- xmake/core/platform/platform.lua | 28 ++-------------------------- xmake/core/project/target.lua | 1 - xmake/core/tool/toolchain.lua | 35 ----------------------------------- xmake/toolchains/ndk/load.lua | 12 +++++++++++- 4 files changed, 13 insertions(+), 63 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 4a4b4bf96..f9a8fba77 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -147,30 +147,6 @@ function _instance:runenvs() return runenvs end --- get runtimes -function _instance:runtimes() - local runtimes = self:_memcache():get("runtimes") - if runtimes == nil then - runtimes = config.get("runtimes") - if self:name() == "windows" then - runtimes = runtimes or config.get("vs_runtime") - elseif self:name() == "android" then - runtimes = runtimes or config.get("ndk_cxxstl") - end - if runtimes then - runtimes = runtimes:split(",", {plain = true}) - if #runtimes > 0 then - runtimes = table.unwrap(runtimes) - else - runtimes = nil - end - end - runtimes = runtimes or false - self:_memcache():set("runtimes", runtimes) - end - return runtimes or nil -end - -- get the toolchains function _instance:toolchains(opt) local toolchains = self:_memcache():get("toolchains") @@ -187,7 +163,7 @@ function _instance:toolchains(opt) local toolchain_given = config.get("toolchain") if toolchain_given then local toolchain_inst, errors = toolchain.load(toolchain_given, { - plat = self:name(), arch = self:arch(), runtimes = self:runtimes()}) + plat = self:name(), arch = self:arch()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(toolchain_given) @@ -207,7 +183,7 @@ function _instance:toolchains(opt) if names then for _, name in ipairs(table.wrap(names)) do local toolchain_inst, errors = toolchain.load(name, { - plat = self:name(), arch = self:arch(), runtimes = self:runtimes()}) + plat = self:name(), arch = self:arch()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index e2262049a..6d6fe66d5 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2435,7 +2435,6 @@ function _instance:toolchains() local toolchain_opt = table.copy(self:extraconf("toolchains", name)) toolchain_opt.arch = self:arch() toolchain_opt.plat = self:plat() - toolchain_opt.runtimes = self:runtimes() local toolchain_inst, errors = toolchain.load(name, toolchain_opt) -- attempt to load toolchain from project if not toolchain_inst and target._project() then diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ab9673c91..620b862d5 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -108,41 +108,6 @@ function _instance:is_arch(...) end end --- get toolchain runtimes -function _instance:runtimes() - local runtimes = self._RUNTIMES - if runtimes == nil then - runtimes = {} - local runtimes_supported = hashset.from(table.wrap(self:get("runtimes"))) - for _, runtime in ipairs(table.wrap(self:config("runtimes"))) do - if runtimes_supported:has(runtime) then - table.insert(runtimes, runtime) - end - end - if #runtimes > 0 then - runtimes = table.unwrap(runtimes) - else - runtimes = false - end - self._RUNTIMES = runtimes - end - return runtimes or nil -end - --- has the given runtime for the current toolchains? -function _instance:has_runtime(...) - local runtimes_set = self._RUNTIMES_SET - if runtimes_set == nil then - runtimes_set = hashset.from(table.wrap(self:runtimes())) - self._RUNTIMES_SET = runtimes_set - end - for _, v in ipairs(table.pack(...)) do - if runtimes_set:has(v) then - return true - end - end -end - -- get toolchain info function _instance:info() local arch = self:arch() diff --git a/xmake/toolchains/ndk/load.lua b/xmake/toolchains/ndk/load.lua index b9e06c8dd..896e4b837 100644 --- a/xmake/toolchains/ndk/load.lua +++ b/xmake/toolchains/ndk/load.lua @@ -19,6 +19,7 @@ -- -- imports +import("core.base.hashset") import("core.project.config") -- get triple @@ -207,8 +208,17 @@ function main(toolchain) -- get c++ stl sdk directory local cxxstl_sdkdir = nil - local ndk_cxxstl = toolchain:runtimes() or config.get("ndk_cxxstl") + local ndk_cxxstl = config.get("runtimes") or config.get("ndk_cxxstl") if ndk_cxxstl then + if ndk_cxxstl:find(",", 1, true) then + local runtimes_supported = hashset.from(toolchain:get("runtimes")) + for _, item in ipairs(ndk_cxxstl:split(",")) do + if runtimes_supported:has(item) then + ndk_cxxstl = item + break + end + end + end -- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then cxxstl_sdkdir = cxxstl_sdkdir_llvmstl -- cgit v1.3.1 From 5b7ead17c49b68f8cfd6ca5325f5ccfe1b3e82cc Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:07:54 +0800 Subject: limit runtimes --- xmake/core/package/package.lua | 24 +++++++++++++++++++----- xmake/core/project/target.lua | 22 ++++++++++++++++++---- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 69d2b234d..f6b3e2f4c 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1136,7 +1136,21 @@ function _instance:runtimes() if runtimes == nil then runtimes = self:config("runtimes") if runtimes then - runtimes = table.unwrap(runtimes:split(",", {plain = true})) + local runtimes_supported = hashset.new() + for _, toolchain_inst in ipairs(self:toolchains()) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end + end + end + local runtimes_current = {} + for _, runtime in ipairs(table.wrap(runtimes:split(",", {plain = true}))) do + if runtimes_supported:has(runtime) then + table.insert(runtimes_current, runtime) + end + end + runtimes = table.unwrap(runtimes_current) end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) @@ -1146,10 +1160,10 @@ end -- has the given runtime for the current toolchains? function _instance:has_runtime(...) - local runtimes_set = self._RUNTIMES_SET + local runtimes_set = self:_memcache():get("runtimes_set") if runtimes_set == nil then runtimes_set = hashset.from(table.wrap(self:runtimes())) - self._RUNTIMES_SET = runtimes_set + self:_memcache():set("runtimes_set", runtimes_set) end for _, v in ipairs(table.pack(...)) do if runtimes_set:has(v) then @@ -1160,7 +1174,7 @@ end -- get the given toolchain function _instance:toolchain(name) - local toolchains_map = self._TOOLCHAINS_MAP + local toolchains_map = self:_memcache():get("toolchains_map") if toolchains_map == nil then toolchains_map = {} local toolchains = self:toolchains() @@ -1169,7 +1183,7 @@ function _instance:toolchain(name) toolchains_map[toolchain_inst:name()] = toolchain_inst end end - self._TOOLCHAINS_MAP = toolchains_map + self:_memcache():set("toolchains_map", toolchains_map) end return toolchains_map[name] end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 6d6fe66d5..b5fe3b35b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2385,8 +2385,22 @@ function _instance:runtimes() local runtimes = self:_memcache():get("runtimes") if runtimes == nil then runtimes = self:get("runtimes") - if runtimes and #runtimes > 0 then - runtimes = table.unwrap(runtimes) + if runtimes then + local runtimes_supported = hashset.new() + for _, toolchain_inst in ipairs(self:toolchains()) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end + end + end + local runtimes_current = {} + for _, runtime in ipairs(table.wrap(runtimes)) do + if runtimes_supported:has(runtime) then + table.insert(runtimes_current, runtime) + end + end + runtimes = table.unwrap(runtimes_current) end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) @@ -2396,10 +2410,10 @@ end -- has the given runtime for the current toolchains? function _instance:has_runtime(...) - local runtimes_set = self._RUNTIMES_SET + local runtimes_set = self:_memcache():get("runtimes_set") if runtimes_set == nil then runtimes_set = hashset.from(table.wrap(self:runtimes())) - self._RUNTIMES_SET = runtimes_set + self:_memcache():set("runtimes_set", runtimes_set) end for _, v in ipairs(table.pack(...)) do if runtimes_set:has(v) then -- cgit v1.3.1 From 4e8b4b2c8bd84fb28aefcbf6ceb9eff5cd06143c Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:09:59 +0800 Subject: fix package runtimes --- xmake/core/package/package.lua | 11 +++++++---- xmake/core/project/target.lua | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f6b3e2f4c..30b2654a9 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1137,10 +1137,13 @@ function _instance:runtimes() runtimes = self:config("runtimes") if runtimes then local runtimes_supported = hashset.new() - for _, toolchain_inst in ipairs(self:toolchains()) do - if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then - for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do - runtimes_supported:insert(runtime) + local toolchains = self:toolchains() or platform.load(self:plat(), self:arch()):toolchains() + if toolchains then + for _, toolchain_inst in ipairs(toolchains) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end end end end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index b5fe3b35b..6e0b4d06d 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2387,10 +2387,13 @@ function _instance:runtimes() runtimes = self:get("runtimes") if runtimes then local runtimes_supported = hashset.new() - for _, toolchain_inst in ipairs(self:toolchains()) do - if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then - for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do - runtimes_supported:insert(runtime) + local toolchains = self:toolchains() or platform.load(self:plat(), self:arch()):toolchains() + if toolchains then + for _, toolchain_inst in ipairs(toolchains) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end end end end -- cgit v1.3.1 From 10f28484e790d677b805361875060ebde662bdb2 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:15:12 +0800 Subject: add vs_runtime config --- xmake/modules/private/action/require/impl/package.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index cd61404d0..7c6218f35 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -371,6 +371,10 @@ function _add_package_configurations(package) return true end}) end + -- deprecated, please use runtimes + if package:extraconf("configs", "vs_runtime", "default") == nil then + package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", values = {"MT", "MTd", "MD", "MDd"}}) + end if package:extraconf("configs", "toolchains", "default") == nil then package:add("configs", "toolchains", {builtin = true, description = "Set package toolchains only for cross-compilation."}) end -- cgit v1.3.1 From 6f05013ae1fcf9f050d949796c2d74b7aa27c1d9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:16:26 +0800 Subject: fix vs_runtime readonly --- xmake/modules/private/action/require/impl/package.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 7c6218f35..47ec0f8b5 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -578,7 +578,17 @@ function _finish_requireinfo(requireinfo, package) for _, name in ipairs(table.keys(requireinfo.configs)) do local current = requireinfo.configs[name] local default = package:extraconf("configs", name, "default") - if package:extraconf("configs", name, "readonly") and current ~= default then + local readonly = package:extraconf("configs", name, "readonly") + if name == "runtimes" then + -- vs_runtime is deprecated, but we need also support it now. + if default == nil then + default = package:extraconf("configs", "vs_runtime", "default") + end + if readonly == nil then + readonly = package:extraconf("configs", "vs_runtime", "readonly") + end + end + if readonly and current ~= default then wprint("configs.%s is readonly in package(%s), it's always %s", name, package:name(), default) -- package:config() will use default value after loading package requireinfo.configs[name] = nil -- cgit v1.3.1 From cfd58ddb7af2e99cca95087ba001103d327a8abf Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:16:42 +0800 Subject: add warning --- xmake/modules/private/action/require/impl/package.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 47ec0f8b5..eff4316cc 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -587,6 +587,9 @@ function _finish_requireinfo(requireinfo, package) if readonly == nil then readonly = package:extraconf("configs", "vs_runtime", "readonly") end + if default ~= nil or readonly ~= nil then + wprint("please use add_configs(\"runtimes\") instead of add_configs(\"vs_runtime\").") + end end if readonly and current ~= default then wprint("configs.%s is readonly in package(%s), it's always %s", name, package:name(), default) -- cgit v1.3.1 From 3618119fe36169f63bf9c4efcad5f9802ba37581 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Jan 2024 23:17:46 +0800 Subject: fix vs_runtime default --- xmake/core/package/package.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 30b2654a9..2435c8bf8 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1474,6 +1474,10 @@ function _instance:configs() local value = configs_required[name] if value == nil then value = self:extraconf("configs", name, "default") + -- support for the deprecated vs_runtime in add_configs + if name == "runtimes" and value == nil then + value = self:extraconf("configs", "vs_runtime", "default") + end end configs[name] = value end -- cgit v1.3.1 From a7a9aeb01e456651600b1fb8cb2b7e590036d3db Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Jan 2024 00:45:22 +0800 Subject: improve conan runtimes --- xmake/modules/package/manager/conan/v2/install_package.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index bf561124e..111b355d7 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -167,6 +167,7 @@ function _conan_generate_compiler_profile(profile, configs, opt) local conf local plat = opt.plat local arch = opt.arch + local runtimes = configs.runtimes if plat == "windows" then -- https://github.com/conan-io/conan/blob/353c63b16c31c90d370305b5cbb5dc175cf8a443/conan/tools/microsoft/visual.py#L13 local vsvers = {["2022"] = "193", @@ -182,7 +183,6 @@ function _conan_generate_compiler_profile(profile, configs, opt) if tonumber(vs) >= 2015 then profile:print("compiler.cppstd=14") end - local runtimes = configs.runtimes if runtimes then profile:print("compiler.runtime=" .. (runtimes:startswith("MD") and "dynamic" or "static")) profile:print("compiler.runtime_type=" .. (runtimes:endswith("d") and "Debug" or "Release")) @@ -212,9 +212,8 @@ function _conan_generate_compiler_profile(profile, configs, opt) if ndk_sdkver then profile:print("os.api_level=" .. ndk_sdkver) end - local ndk_cxxstl = config.get("ndk_cxxstl") - if ndk_cxxstl then - profile:print("compiler.libcxx=" .. ndk_cxxstl) + if runtimes then + profile:print("compiler.libcxx=" .. runtimes) end local program, toolname = ndk:tool("cc") local version = _conan_get_compiler_version(toolname, program) @@ -227,9 +226,10 @@ function _conan_generate_compiler_profile(profile, configs, opt) else local program, toolname = platform.tool("cc", plat, arch) if toolname == "gcc" or toolname == "clang" then + runtimes = table.wrap(runtimes) profile:print("compiler=" .. toolname) profile:print("compiler.cppstd=gnu17") - if toolname == "clang" then + if table.contains(runtimes, "c++_static", "c++_shared") then profile:print("compiler.libcxx=libc++") else profile:print("compiler.libcxx=libstdc++11") -- cgit v1.3.1 From 7c0fcf37dae8da15fe47f5ae8c35bcfa07570e0a Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Jan 2024 00:46:05 +0800 Subject: improve conan runtimes again --- xmake/modules/package/manager/conan/v2/install_package.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index 111b355d7..5d2bdd384 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -226,14 +226,15 @@ function _conan_generate_compiler_profile(profile, configs, opt) else local program, toolname = platform.tool("cc", plat, arch) if toolname == "gcc" or toolname == "clang" then - runtimes = table.wrap(runtimes) profile:print("compiler=" .. toolname) profile:print("compiler.cppstd=gnu17") - if table.contains(runtimes, "c++_static", "c++_shared") then - profile:print("compiler.libcxx=libc++") - else - profile:print("compiler.libcxx=libstdc++11") + local libcxx = "libstdc++11" + if runtimes and table.contains(table.wrap(runtimes), "c++_static", "c++_shared") then + libcxx = "libc++" + elseif not runtimes and toolname == "clang" then + libcxx = "libc++" end + profile:print("compiler.libcxx=" .. libcxx) local version = _conan_get_compiler_version(toolname, program) if version then profile:print("compiler.version=" .. version) -- cgit v1.3.1 From 3b3b6c0c1b3bec273a4af6052ec98e17bbc8ac39 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Jan 2024 22:34:36 +0800 Subject: check static libstdc++ --- xmake/modules/core/tools/clang.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 673500599..a34487686 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -178,6 +178,20 @@ function _has_ms_runtime_lib(self) return has_ms_runtime_lib end +-- has -static-libstdc++? +function _has_static_libstdcxx(self) + local has_static_libstdcxx = _g._HAS_STATIC_LIBSTDCXX + if has_static_libstdcxx == nil then + if self:has_flags("-static-libstdc++ -Werror", "ldflags", {flagskey = "clang_static_libstdcxx"}) then + has_static_libstdcxx = true + end + has_static_libstdcxx = has_static_libstdcxx or false + _g._HAS_STATIC_LIBSTDCXX = has_static_libstdcxx + end + return has_static_libstdcxx +end + + -- make the runtime flag -- @see https://github.com/xmake-io/xmake/issues/3546 function nf_runtime(self, runtime) @@ -217,11 +231,15 @@ function nf_runtime(self, runtime) } else maps = { - ["c++_static"] = {"-stdlib=libc++", "-static-libstdc++"}, + ["c++_static"] = "-stdlib=libc++", ["c++_shared"] = "-stdlib=libc++", - ["stdc++_static"] = {"-stdlib=libstdc++", "-static-libstdc++"}, + ["stdc++_static"] = "-stdlib=libstdc++", ["stdc++_shared"] = "-stdlib=libstdc++", } + if runtime:endswith("_static") and _has_static_libstdcxx(self) then + maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++") + maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++") + end end return maps and maps[runtime] end -- cgit v1.3.1 From c6445c7e401b348c5ca8afce229a1f4f45e9cf61 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Jan 2024 22:34:48 +0800 Subject: fix ld kind --- xmake/modules/core/tools/clang.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index a34487686..0ca812f39 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -229,7 +229,7 @@ function nf_runtime(self, runtime) ["stdc++_static"] = "-stdlib=libstdc++", ["stdc++_shared"] = "-stdlib=libstdc++", } - else + elseif kind == "ld" or kind == "sh" then maps = { ["c++_static"] = "-stdlib=libc++", ["c++_shared"] = "-stdlib=libc++", -- cgit v1.3.1 From fec77395b2f96bac0bde5cd4d79115fd6d4b377e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Jan 2024 22:39:30 +0800 Subject: split c and c++ languages --- xmake/languages/c++/load.lua | 13 +--- xmake/languages/c++/xmake.lua | 11 +-- xmake/languages/c/check_main.lua | 41 ++++++++++ xmake/languages/c/load.lua | 120 +++++++++++++++++++++++++++++ xmake/languages/c/xmake.lua | 152 +++++++++++++++++++++++++++++++++++++ xmake/modules/core/tools/clang.lua | 24 +++--- xmake/rules/c++/xmake.lua | 27 ++++++- 7 files changed, 359 insertions(+), 29 deletions(-) create mode 100644 xmake/languages/c/check_main.lua create mode 100644 xmake/languages/c/load.lua create mode 100644 xmake/languages/c/xmake.lua diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua index 932769a7c..b38f4874b 100644 --- a/xmake/languages/c++/load.lua +++ b/xmake/languages/c++/load.lua @@ -25,7 +25,6 @@ function _get_apis() -- target.add_xxx "target.add_links" , "target.add_syslinks" - , "target.add_cflags" , "target.add_cxflags" , "target.add_cxxflags" , "target.add_ldflags" @@ -37,15 +36,11 @@ function _get_apis() , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path , "target.add_forceincludes" -- option.add_xxx - , "option.add_cincludes" , "option.add_cxxincludes" - , "option.add_cfuncs" , "option.add_cxxfuncs" - , "option.add_ctypes" , "option.add_cxxtypes" , "option.add_links" , "option.add_syslinks" - , "option.add_cflags" , "option.add_cxflags" , "option.add_cxxflags" , "option.add_ldflags" @@ -58,7 +53,6 @@ function _get_apis() -- package.add_xxx , "package.add_links" , "package.add_syslinks" - , "package.add_cflags" , "package.add_cxflags" , "package.add_cxxflags" , "package.add_ldflags" @@ -75,7 +69,6 @@ function _get_apis() -- toolchain.add_xxx , "toolchain.add_links" , "toolchain.add_syslinks" - , "toolchain.add_cflags" , "toolchain.add_cxflags" , "toolchain.add_cxxflags" , "toolchain.add_ldflags" @@ -100,8 +93,7 @@ function _get_apis() } apis.paths = { -- target.set_xxx - "target.set_pcheader" - , "target.set_pcxxheader" + "target.set_pcxxheader" -- target.add_xxx , "target.add_headerfiles" , "target.add_linkdirs" @@ -116,8 +108,7 @@ function _get_apis() } apis.dictionary = { -- option.add_xxx - "option.add_csnippets" - , "option.add_cxxsnippets" + "option.add_cxxsnippets" } return apis end diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 22a69a417..487746303 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -20,11 +20,11 @@ language("c++") add_rules("c++") - set_sourcekinds {cc = ".c", cxx = {".cpp", ".cc", ".cxx", ".mpp", ".mxx", ".cppm", ".ixx", ".c++"}} - set_sourceflags {cc = {"cflags", "cxflags"}, cxx = {"cxxflags", "cxflags"}} + set_sourcekinds {cxx = {".cpp", ".cc", ".cxx", ".mpp", ".mxx", ".cppm", ".ixx", ".c++"}} + set_sourceflags {cxx = {"cxxflags", "cxflags"}} set_targetkinds {binary = "ld", static = "ar", shared = "sh"} set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - set_langkinds {c = "cc", cxx = "cxx"} + set_langkinds {cxx = "cxx"} set_mixingkinds("cc", "cxx", "as", "mrc") on_load("load") @@ -49,7 +49,6 @@ language("c++") , "target.frameworks" , "target.exceptions" , "target.encodings" - , "target.pcheader" , "target.pcxxheader" , "target.forceincludes" , "toolchain.includedirs" @@ -118,9 +117,8 @@ language("c++") config = { {category = "Cross Complation Configuration/Compiler Configuration" } - , {nil, "cc", "kv", nil, "The C Compiler" } , {nil, "cxx", "kv", nil, "The C++ Compiler" } - , {nil, "cpp", "kv", nil, "The C Preprocessor" } + , {nil, "cpp", "kv", nil, "The C/C++ Preprocessor" } , {category = "Cross Complation Configuration/Linker Configuration" } , {nil, "ld", "kv", nil, "The Linker" } @@ -129,7 +127,6 @@ language("c++") , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } , {category = "Cross Complation Configuration/Compiler Flags Configuration" } - , {nil, "cflags", "kv", nil, "The C Compiler Flags" } , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } diff --git a/xmake/languages/c/check_main.lua b/xmake/languages/c/check_main.lua new file mode 100644 index 000000000..55d00e2de --- /dev/null +++ b/xmake/languages/c/check_main.lua @@ -0,0 +1,41 @@ +--!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, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check_main.lua +-- + + +-- check it +function main(sourcefile) + + -- load source code + local sourcecode = io.readfile(sourcefile) + + -- remove comment first + sourcecode = sourcecode:gsub("/%*.-%*/", "") + sourcecode = sourcecode:gsub("//.-\n", "\n") + + -- find int main(int argc, char** argv) {} + if sourcecode:find("%s+main%s*%(.-%)") then + return true + end + + -- no main function + return false +end + + diff --git a/xmake/languages/c/load.lua b/xmake/languages/c/load.lua new file mode 100644 index 000000000..3c470e0eb --- /dev/null +++ b/xmake/languages/c/load.lua @@ -0,0 +1,120 @@ +--!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, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- get apis +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_cflags" + , "target.add_cxflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + , "target.add_forceincludes" + -- option.add_xxx + , "option.add_cincludes" + , "option.add_cfuncs" + , "option.add_ctypes" + , "option.add_links" + , "option.add_syslinks" + , "option.add_cflags" + , "option.add_cxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_cflags" + , "package.add_cxflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_defines" + , "package.add_undefines" + , "package.add_frameworks" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" --@note we need not uses paths for package, see https://github.com/xmake-io/xmake/issues/717 + , "package.add_sysincludedirs" + , "package.add_frameworkdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cflags" + , "toolchain.add_cxflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + , "toolchain.add_frameworkdirs" + } + apis.groups = { + -- target.add_xxx + "target.add_linkorders" + , "target.add_linkgroups" + -- package.add_xxx + , "package.add_linkorders" + , "package.add_linkgroups" + } + apis.paths = { + -- target.set_xxx + "target.set_pcheader" + -- target.add_xxx + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + , "option.add_frameworkdirs" + } + apis.dictionary = { + -- option.add_xxx + "option.add_csnippets" + } + return apis +end + +function main() + return {apis = _get_apis()} +end + + diff --git a/xmake/languages/c/xmake.lua b/xmake/languages/c/xmake.lua new file mode 100644 index 000000000..4e1a0041b --- /dev/null +++ b/xmake/languages/c/xmake.lua @@ -0,0 +1,152 @@ +--!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, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +language("c") + add_rules("c") + set_sourcekinds {cc = ".c"} + set_sourceflags {cc = {"cflags", "cxflags"}} + set_targetkinds {binary = "ld", static = "ar", shared = "sh"} + set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + set_langkinds {c = "cc"} + set_mixingkinds("cc", "cxx", "as", "mrc") + + on_load("load") + on_check_main("check_main") + + set_nameflags { + object = { + "config.includedirs" + , "config.frameworkdirs" + , "config.frameworks" + , "target.symbols" + , "target.warnings" + , "target.fpmodels" + , "target.optimize:check" + , "target.vectorexts:check" + , "target.languages" + , "target.runtimes" + , "target.includedirs" + , "target.defines" + , "target.undefines" + , "target.frameworkdirs" + , "target.frameworks" + , "target.exceptions" + , "target.encodings" + , "target.pcheader" + , "target.forceincludes" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" + , "target.sysincludedirs" + , "toolchain.sysincludedirs" + } + , binary = { + "config.linkdirs" + , "config.frameworkdirs" + , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "target.optimize:check" + , "target.runtimes" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" + , "config.links" + , "target.linkgroups" -- we must move it before target.links, because we need sort correct order for package and its deps + , "target.links" + , "toolchain.links" + , "config.frameworks" + , "target.frameworks" + , "toolchain.frameworks" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , shared = { + "config.linkdirs" + , "config.frameworkdirs" + , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "target.optimize:check" + , "target.runtimes" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" + , "config.links" + , "target.links" + , "target.linkgroups" + , "toolchain.links" + , "config.frameworks" + , "target.frameworks" + , "toolchain.frameworks" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , static = { + "target.strip" + , "target.symbols" + } + } + + set_menu { + config = + { + {category = "Cross Complation Configuration/Compiler Configuration" } + , {nil, "cc", "kv", nil, "The C Compiler" } + , {nil, "cpp", "kv", nil, "The C/C++ Preprocessor" } + + , {category = "Cross Complation Configuration/Linker Configuration" } + , {nil, "ld", "kv", nil, "The Linker" } + , {nil, "ar", "kv", nil, "The Static Library Linker" } + , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } + + , {category = "Cross Complation Configuration/Compiler Flags Configuration" } + , {nil, "cflags", "kv", nil, "The C Compiler Flags" } + , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } + + , {category = "Cross Complation Configuration/Linker Flags Configuration" } + , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } + , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } + , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } + + , {category = "Cross Complation Configuration/Builtin Flags Configuration" } + , {nil, "links", "kv", nil, "The Link Libraries" } + , {nil, "syslinks", "kv", nil, "The System Link Libraries" } + , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } + , {nil, "includedirs", "kv", nil, "The Include Search Directories" } + , {nil, "frameworks", "kv", nil, "The Frameworks" } + , {nil, "frameworkdirs", "kv", nil, "The Frameworks Search Directories" } + } + } + + + + + + diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 0ca812f39..313728894 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -194,7 +194,8 @@ end -- make the runtime flag -- @see https://github.com/xmake-io/xmake/issues/3546 -function nf_runtime(self, runtime) +function nf_runtime(self, runtime, opt) + opt = opt or {} local kind = self:kind() if self:is_plat("windows") and runtime then if not _has_ms_runtime_lib(self) then @@ -230,15 +231,18 @@ function nf_runtime(self, runtime) ["stdc++_shared"] = "-stdlib=libstdc++", } elseif kind == "ld" or kind == "sh" then - maps = { - ["c++_static"] = "-stdlib=libc++", - ["c++_shared"] = "-stdlib=libc++", - ["stdc++_static"] = "-stdlib=libstdc++", - ["stdc++_shared"] = "-stdlib=libstdc++", - } - if runtime:endswith("_static") and _has_static_libstdcxx(self) then - maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++") - maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++") + local target = opt.target + if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + if runtime:endswith("_static") and _has_static_libstdcxx(self) then + maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++") + maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++") + end end end return maps and maps[runtime] diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 80d2e1417..dedb63ed5 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -46,10 +46,35 @@ rule("c++.build") end end) +rule("c") + + -- add build rules + add_deps("c.build") + + -- set compiler runtime, e.g. vs runtime + add_deps("utils.compiler.runtime") + + -- inherit links and linkdirs of all dependent targets by default + add_deps("utils.inherit.links") + + -- support `add_files("src/*.o")` and `add_files("src/*.a")` to merge object and archive files to target + add_deps("utils.merge.object", "utils.merge.archive") + + -- we attempt to extract symbols to the independent file and + -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled + add_deps("utils.symbols.extract") + + -- add platform rules + add_deps("platform.wasm") + add_deps("platform.windows") + + -- add linker rules + add_deps("linker") + rule("c++") -- add build rules - add_deps("c++.build", "c.build") + add_deps("c++.build") -- set compiler runtime, e.g. vs runtime add_deps("utils.compiler.runtime") -- cgit v1.3.1 From eb17b64f82042e754000c4ae57a6e7184b19b8b0 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Jan 2024 22:44:38 +0800 Subject: compatible with vs_runtime buildhash --- xmake/core/package/package.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 2435c8bf8..870fa63d5 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1539,6 +1539,15 @@ function _instance:buildhash() str = str .. label end if configs then + + -- with old vs_runtime configs + -- https://github.com/xmake-io/xmake/issues/4477 + if opt.vs_runtime then + configs = table.clone(configs) + configs.vs_runtime = configs.runtimes + configs.runtimes = nil + end + -- since luajit v2.1, the key order of the table is random and undefined. -- We cannot directly deserialize the table, so the result may be different each time local configs_order = {} @@ -1616,6 +1625,16 @@ function _instance:buildhash() end end + -- we need to be compatible with the previous xmake version + -- with deprecated vs_runtime (< 2.8.7) + -- @see https://github.com/xmake-io/xmake/issues/4477 + if not buildhash then + buildhash = _get_buildhash(self:_configs_for_buildhash(), {vs_runtime = true}) + if not os.isdir(_get_installdir(buildhash)) then + buildhash = nil + end + end + -- get build hash for current version if not buildhash then buildhash = _get_buildhash(self:_configs_for_buildhash()) -- cgit v1.3.1 From 3781f4b6a26ce55b58b95fb704e5217afe231ce1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 25 Jan 2024 22:58:23 +0800 Subject: improve add files dynamiclly --- xmake/core/project/target.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 6e0b4d06d..fedac0404 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -272,6 +272,43 @@ function _instance:_visibility(opt) return visibility end +-- update file rules +-- +-- if we add files in on_load() dynamically, we need to update file rules, +-- otherwise it will cause: unknown source file: ... +-- +function _instance:_update_filerules() + local rulenames = {} + local extensions = {} + for _, sourcefile in ipairs(table.wrap(self:get("files"))) do + local extension = path.extension((sourcefile:gsub("|.*$", ""))) + if not extensions[extension] then + local lang = language.load_ex(extension) + if lang and lang:rules() then + table.join2(rulenames, lang:rules()) + end + extensions[extension] = true + end + end + rulenames = table.unique(rulenames) + for _, rulename in ipairs(rulenames) do + local r = target._project() and target._project().rule(rulename) or rule.rule(rulename) + if r then + -- only add target rules + if r:kind() == "target" then + if not self:rule(rulename) then + self:rule_add(r) + for _, deprule in ipairs(r:orderdeps()) do + if not self:rule(deprule:name()) then + self:rule_add(deprule) + end + end + end + end + end + end +end + -- invalidate the previous cache function _instance:_invalidate(name) self._CACHEID = self._CACHEID + 1 @@ -282,6 +319,7 @@ function _instance:_invalidate(name) self._FILESCONFIG = nil self._OBJECTFILES = nil self._SOURCEBATCHES = nil + self:_update_filerules() elseif name == "deps" then self._DEPS = nil self._ORDERDEPS = nil -- cgit v1.3.1 From 647e8c36c5d54635df12666f3a0bc45b45084389 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 25 Jan 2024 23:25:52 +0800 Subject: clear target cache --- xmake/core/project/target.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index fedac0404..8cc2ff824 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -313,6 +313,7 @@ end function _instance:_invalidate(name) self._CACHEID = self._CACHEID + 1 self._POLICIES = nil + self:_memcache():clear() -- we need to flush the source files cache if target/files are modified, e.g. `target:add("files", "xxx.c")` if name == "files" then self._SOURCEFILES = nil -- cgit v1.3.1 From 2a43a89241ff5044661fa7449d6455386cd3a449 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Jan 2024 23:46:36 +0800 Subject: select runtimes for buildhash --- xmake/core/package/package.lua | 31 ++++++++---------- .../private/action/require/impl/package.lua | 37 ++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 11 ++----- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 870fa63d5..5f9524019 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1136,23 +1136,7 @@ function _instance:runtimes() if runtimes == nil then runtimes = self:config("runtimes") if runtimes then - local runtimes_supported = hashset.new() - local toolchains = self:toolchains() or platform.load(self:plat(), self:arch()):toolchains() - if toolchains then - for _, toolchain_inst in ipairs(toolchains) do - if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then - for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do - runtimes_supported:insert(runtime) - end - end - end - end - local runtimes_current = {} - for _, runtime in ipairs(table.wrap(runtimes:split(",", {plain = true}))) do - if runtimes_supported:has(runtime) then - table.insert(runtimes_current, runtime) - end - end + local runtimes_current = runtimes:split(",", {plain = true}) runtimes = table.unwrap(runtimes_current) end runtimes = runtimes or false @@ -1515,6 +1499,10 @@ function _instance:_configs_for_buildhash() local value = configs_required[name] if value == nil then value = self:extraconf("configs", name, "default") + -- support for the deprecated vs_runtime in add_configs + if name == "runtimes" and value == nil then + value = self:extraconf("configs", "vs_runtime", "default") + end end configs[name] = value end @@ -1527,10 +1515,19 @@ function _instance:_configs_for_buildhash() return configs and configs or nil end +-- compute the build hash +function _instance:_compute_buildhash() + self._BUILDHASH_PREPRARED = true + self:buildhash() +end + -- get the build hash function _instance:buildhash() local buildhash = self._BUILDHASH if buildhash == nil then + if not self._BUILDHASH_PREPRARED then + os.raise("package:buildhash() must be called after loading package") + end local function _get_buildhash(configs, opt) opt = opt or {} local str = self:plat() .. self:arch() diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index eff4316cc..5d352ee01 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -28,6 +28,7 @@ import("core.cache.memcache") import("core.project.project") import("core.project.config") import("core.tool.toolchain") +import("core.platform.platform") import("core.package.package", {alias = "core_package"}) import("devel.git") import("private.action.require.impl.repository") @@ -805,6 +806,35 @@ function _select_artifacts(package, artifacts_manifest) end end +-- select package runtimes +function _select_package_runtimes(package) + local runtimes = package:config("runtimes") + if runtimes then + local runtimes_supported = hashset.new() + local toolchains = package:toolchains() or platform.load(package:plat(), package:arch()):toolchains() + if toolchains then + for _, toolchain_inst in ipairs(toolchains) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end + end + end + end + local runtimes_current = {} + for _, runtime in ipairs(table.wrap(runtimes:split(",", {plain = true}))) do + if runtimes_supported:has(runtime) then + table.insert(runtimes_current, runtime) + end + end + -- we need update runtimes for buildhash, configs ... + local requireinfo = package:requireinfo() + if requireinfo and requireinfo.configs then + requireinfo.configs.runtimes = #runtimes_current > 0 and table.concat(runtimes_current, ",") or nil + end + end +end + -- load required packages function _load_package(packagename, requireinfo, opt) @@ -938,6 +968,13 @@ function _load_package(packagename, requireinfo, opt) -- check package configurations _check_package_configurations(package) + -- we need to select package runtimes before computing buildhash + -- @see https://github.com/xmake-io/xmake/pull/4630#issuecomment-1910216561 + _select_package_runtimes(package) + + -- pre-compute the package buildhash + package:_compute_buildhash() + -- save artifacts info, we need to add it at last before buildhash need depend on package configurations -- it will switch to install precompiled binary package from xmake-mirror/build-artifacts if from_repo and not option.get("build") and not requireinfo.build then diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index ff304e3b2..2f9e6a053 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -18,20 +18,13 @@ -- @file xmake.lua -- --- define toolchain toolchain("xcode") - - -- set homepage + set_kind("standalone") set_homepage("https://developer.apple.com/xcode/") set_description("Xcode IDE") + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load(function (toolchain) -- set toolset -- cgit v1.3.1