diff options
| author | ruki <[email protected]> | 2024-01-26 23:01:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-26 23:01:44 +0800 |
| commit | fd85ae0a81de712ca3837b262e936fd67b8f483f (patch) | |
| tree | 97894c8d36a17ca6437aedd10400b8f24574d783 /xmake/modules | |
| parent | 042362f4c3f1dab8b6b5a32fcbbae20e66e224de (diff) | |
| parent | 2a43a89241ff5044661fa7449d6455386cd3a449 (diff) | |
Merge pull request #4630 from xmake-io/runtimes
Improve runtimes to support libc++/libstdc++
Diffstat (limited to 'xmake/modules')
20 files changed, 211 insertions, 79 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 2d60f2a1b..18f6ee868 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..313728894 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -178,18 +178,33 @@ function _has_ms_runtime_lib(self) return has_ms_runtime_lib end --- make vs runtime flag +-- 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, vs_runtime) - if self:is_plat("windows") and vs_runtime then +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 - 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 +220,32 @@ function nf_runtime(self, vs_runtime) MDd = "-nostdlib" } end - return maps and maps[vs_runtime] + return maps and maps[runtime] + elseif not self:is_plat("android") then -- we will set runtimes in android ndk toolchain + local maps + if kind == "cxx" then + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + elseif kind == "ld" or kind == "sh" then + 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] 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 604fbe505..127f51656 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -171,9 +171,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 - return '-Xcompiler "-' .. vs_runtime .. '"' +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[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..5d2bdd384 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,10 +183,9 @@ 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")) + 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 @@ -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) @@ -229,11 +228,13 @@ function _conan_generate_compiler_profile(profile, configs, opt) if toolname == "gcc" or toolname == "clang" then profile:print("compiler=" .. toolname) profile:print("compiler.cppstd=gnu17") - if toolname == "clang" 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) 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/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index ecee111d8..525507b3c 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) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 8bbeeee45..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") @@ -152,6 +153,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,6 +354,25 @@ 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", "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.", type = "string", values = values, restrict = function (value) + local values_set = hashset.from(values) + 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 + end + end + 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 @@ -438,7 +465,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 @@ -450,11 +481,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 @@ -513,9 +539,12 @@ 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 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") @@ -527,7 +556,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,15 +571,28 @@ 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 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 + 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) -- package:config() will use default value after loading package requireinfo.configs[name] = nil @@ -568,9 +610,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 +702,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 +723,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 @@ -764,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) @@ -838,7 +909,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 @@ -897,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/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 "" 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." }, {}, |
