From 4fd8d5eec226060ee62b24c56ae4e303d4ededba Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Sep 2024 00:38:24 +0800 Subject: [PATCH 1/9] improve host toolchain #5639 --- xmake/actions/config/xmake.lua | 6 +++ xmake/core/package/package.lua | 45 ++++++++++------- xmake/core/platform/platform.lua | 48 ++++++++++++------- .../private/action/require/impl/package.lua | 26 ++++------ .../action/require/impl/utils/requirekey.lua | 9 ++++ .../modules/private/xrepo/action/download.lua | 32 ++++++++----- xmake/modules/private/xrepo/action/export.lua | 34 +++++++------ xmake/modules/private/xrepo/action/fetch.lua | 46 ++++++++++-------- .../modules/private/xrepo/action/install.lua | 4 ++ xmake/modules/private/xrepo/action/remove.lua | 32 +++++++------ 10 files changed, 168 insertions(+), 114 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 4bf43c787b1..a2106bf0768 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -213,6 +213,12 @@ task("config") , " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx" , " - run `xmake show -l toolchains` to get all toolchains" , values = _toolchain_values}, + {nil, "toolchain_host", "kv", nil, "Set host toolchain name, it's only for building packages on host machine." + , "e.g. " + , " - xmake f --toolchain_host=clang" + , " - xmake f --toolchain_host=[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" diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 00ae72768d1..fe77bd999a6 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -166,8 +166,7 @@ function _instance:plat() if self._PLAT then return self._PLAT end - -- @note we uses os.host() instead of them for the binary package - if self:is_binary() then + if self:is_host() then return os.subhost() end local requireinfo = self:requireinfo() @@ -182,8 +181,7 @@ function _instance:arch() if self._ARCH then return self._ARCH end - -- @note we uses os.arch() instead of them for the binary package - if self:is_binary() then + if self:is_host() then return os.subarch() end return self:targetarch() @@ -668,6 +666,31 @@ function _instance:is_local() return self._IS_LOCAL or self:is_source_embed() or self:is_binary_embed() or self:is_thirdparty() end +-- is debug package? (deprecated) +function _instance:debug() + return self:is_debug() +end + +-- is host package? +-- +-- @note It is different from not is_cross() in that users do not use host packages directly, +-- they are usually used to build library packages. +function _instance:is_host() + local requireinfo = self:requireinfo() + if requireinfo and requireinfo.host then + return true + end + return self:is_binary() +end + +-- is cross-compilation? +function _instance:is_cross() + if self:is_host() then + return false + end + return is_cross(self:plat(), self:arch()) +end + -- mark it as local package function _instance:_mark_as_local(is_local) if self:is_local() ~= is_local then @@ -699,16 +722,6 @@ function _instance:use_external_includes() return external end --- is debug package? (deprecated) -function _instance:debug() - return self:is_debug() -end - --- is cross-compilation? -function _instance:is_cross() - return is_cross(self:plat(), self:arch()) -end - -- get the filelock of the whole package directory function _instance:filelock() local filelock = self._FILELOCK @@ -1267,7 +1280,7 @@ function _instance:tool(toolkind) local cachekey = "package_" .. tostring(self) return toolchain.tool(self:toolchains(), toolkind, {cachekey = cachekey, plat = self:plat(), arch = self:arch()}) else - return platform.tool(toolkind, self:plat(), self:arch()) + return platform.tool(toolkind, self:plat(), self:arch(), {host = self:is_host()}) end end @@ -1277,7 +1290,7 @@ function _instance:toolconfig(name) local cachekey = "package_" .. tostring(self) return toolchain.toolconfig(self:toolchains(), name, {cachekey = cachekey, plat = self:plat(), arch = self:arch()}) else - return platform.toolconfig(name, self:plat(), self:arch()) + return platform.toolconfig(name, self:plat(), self:arch(), {host = self:is_host()}) end end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 913d44691ad..1a8beb35799 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -27,20 +27,22 @@ local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local table = require("base/table") +local global = require("base/global") local interpreter = require("base/interpreter") local toolchain = require("tool/toolchain") local memcache = require("cache/memcache") local sandbox = require("sandbox/sandbox") local config = require("project/config") -local global = require("base/global") local scheduler = require("sandbox/modules/import/core/base/scheduler") -- new an instance -function _instance.new(name, arch, info) +function _instance.new(name, info, opt) + opt = opt or{} local instance = table.inherit(_instance) instance._NAME = name - instance._ARCH = arch instance._INFO = info + instance._ARCH = opt.arch + instance._IS_HOST = opt.host or false return instance end @@ -54,6 +56,11 @@ function _instance:_memcache() return cache end +-- the toolchains cache key for names +function _instance:_toolchains_key() + return "__toolchains_" .. self:name() .. "_" .. self:arch() .. (self:is_host() and "_host" or "") +end + -- get platform name function _instance:name() return self._NAME @@ -74,6 +81,11 @@ function _instance:arch_set(arch) end end +-- is host platform, it will use the host toolchain +function _instance:is_host() + return self._IS_HOST +end + -- set the value to the platform configuration function _instance:set(name, ...) self._INFO:apival_set(name, ...) @@ -157,11 +169,11 @@ function _instance:toolchains(opt) local names = nil toolchains = {} if not (opt and opt.all) then - names = config.get("__toolchains_" .. self:name() .. "_" .. self:arch()) + names = config.get(self:_toolchains_key()) end if not names then -- get the given toolchain - local toolchain_given = config.get("toolchain") + local toolchain_given = config.get(self:is_host() and "toolchain_host" or "toolchain") if toolchain_given then local toolchain_inst, errors = toolchain.load(toolchain_given, { plat = self:name(), arch = self:arch()}) @@ -276,7 +288,7 @@ function _instance:check() end -- save valid toolchains - config.set("__toolchains_" .. self:name() .. "_" .. self:arch(), toolchains_valid) + config.set(self:_toolchains_key(), toolchains_valid) self:_memcache():set("checked", true) scheduler.co_unlock(lockname) return true @@ -407,14 +419,16 @@ function platform.add_directories(...) end -- load the given platform -function platform.load(plat, arch) - - -- get platform name +function platform.load(plat, arch, opt) + opt = opt or {} plat = plat or config.get("plat") or os.host() arch = arch or config.get("arch") or os.arch() -- get cache key local cachekey = plat .. "_" .. arch + if opt.host then + cachekey = cachekey .. "_host" + end -- get it directly from cache dirst platform._PLATFORMS = platform._PLATFORMS or {} @@ -425,8 +439,6 @@ function platform.load(plat, arch) -- find the platform script path local scriptpath = nil for _, dir in ipairs(platform.directories()) do - - -- find this directory scriptpath = path.join(dir, plat, "xmake.lua") if os.isfile(scriptpath) then break @@ -469,14 +481,14 @@ function platform.load(plat, arch) end -- save instance to the cache - local instance = _instance.new(plat, arch, result) + local instance = _instance.new(plat, result, {arch = arch, host = opt.host}) platform._PLATFORMS[cachekey] = instance return instance end -- get the given platform configuration -function platform.get(name, plat, arch) - local instance, errors = platform.load(plat, arch) +function platform.get(name, plat, arch, opt) + local instance, errors = platform.load(plat, arch, opt) if instance then return instance:get(name) else @@ -488,8 +500,8 @@ end -- -- e.g. cc, cxx, mm, mxx, as, ar, ld, sh, .. -- -function platform.tool(toolkind, plat, arch) - local instance, errors = platform.load(plat, arch) +function platform.tool(toolkind, plat, arch, opt) + local instance, errors = platform.load(plat, arch, opt) if instance then return instance:tool(toolkind) else @@ -498,8 +510,8 @@ function platform.tool(toolkind, plat, arch) end -- get the given tool configuration -function platform.toolconfig(name, plat, arch) - local instance, errors = platform.load(plat, arch) +function platform.toolconfig(name, plat, arch, opt) + local instance, errors = platform.load(plat, arch, opt) if instance then return instance:toolconfig(name) else diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 307d1620a47..c3fbdd0d046 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -160,17 +160,6 @@ function _load_require(require_str, requires_extra, parentinfo) 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 - -- we need to pass plat/arch to avoid repeat installation - -- @see https://github.com/xmake-io/xmake/issues/1579 - else - require_extra.plat = os.subhost() - require_extra.arch = os.subarch() - end - end - -- check require options local extra_options = hashset.of("plat", "arch", "kind", "host", "targetos", "alias", "group", "system", "option", "default", "optional", "debug", @@ -197,6 +186,7 @@ function _load_require(require_str, requires_extra, parentinfo) originstr = require_str, reponame = reponame, version = require_extra.version or version, + host = require_extra.host, -- this package is only for host machine plat = require_extra.plat, -- require package in the given platform arch = require_extra.arch, -- require package in the given architecture targetos = require_extra.targetos, -- require package in the given target os @@ -579,13 +569,6 @@ end -- finish requireinfo function _finish_requireinfo(requireinfo, package) - -- we need to synchronise the plat/arch inherited from the parent package as early as possible - if requireinfo.plat then - package:plat_set(requireinfo.plat) - end - if requireinfo.arch then - package:arch_set(requireinfo.arch) - end requireinfo.configs = requireinfo.configs or {} if package:is_plat("windows") then -- @see https://github.com/xmake-io/xmake/issues/4477#issuecomment-1913249489 @@ -718,6 +701,7 @@ end -- get package key function _get_packagekey(packagename, requireinfo, version) return _get_requirekey(requireinfo, {name = packagename, + host = requireinfo.host, plat = requireinfo.plat, arch = requireinfo.arch, kind = requireinfo.kind, @@ -752,6 +736,9 @@ function _inherit_parent_configs(requireinfo, package, parentinfo) if parentinfo.arch then requireinfo.arch = parentinfo.arch end + if parentinfo.host then + requireinfo.host = parentinfo.host + end requireinfo_configs.toolchains = requireinfo_configs.toolchains or parentinfo_configs.toolchains requireinfo_configs.runtimes = requireinfo_configs.runtimes or parentinfo_configs.runtimes requireinfo_configs.lto = requireinfo_configs.lto or parentinfo_configs.lto @@ -1323,6 +1310,9 @@ function get_configs_str(package) if requireinfo.arch then table.insert(configs, requireinfo.arch) end + if requireinfo.host then + table.insert(configs, requireinfo.host) + end if requireinfo.kind then table.insert(configs, requireinfo.kind) end diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index bfd724d06eb..9378a8cb700 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -20,6 +20,7 @@ -- imports import("core.base.hashset") +import("core.package.package", {alias = "core_package"}) -- get require key from requireinfo function main(requireinfo, opt) @@ -43,6 +44,14 @@ function main(requireinfo, opt) if requireinfo.label then key = key .. "/" .. requireinfo.label end + if requireinfo.host then + if is_subhost(core_package.targetplat()) and os.subarch() == core_package.targetarch() then + -- we need to pass plat/arch to avoid repeat installation + -- @see https://github.com/xmake-io/xmake/issues/1579 + else + key = key .. "/host" + end + end if requireinfo.system then key = key .. "/system" end diff --git a/xmake/modules/private/xrepo/action/download.lua b/xmake/modules/private/xrepo/action/download.lua index be694c52b2c..db68e50b064 100644 --- a/xmake/modules/private/xrepo/action/download.lua +++ b/xmake/modules/private/xrepo/action/download.lua @@ -31,24 +31,26 @@ function menu_options() local options = { {'k', "kind", "kv", nil, "Enable static/shared library.", - values = {"static", "shared"} }, - {'p', "plat", "kv", nil, "Set the given platform." }, - {'a', "arch", "kv", nil, "Set the given architecture." }, + values = {"static", "shared"}}, + {'p', "plat", "kv", nil, "Set the given platform." }, + {'a', "arch", "kv", nil, "Set the given architecture." }, {'m', "mode", "kv", nil, "Set the given mode.", - values = {"release", "debug"} }, + values = {"release", "debug"}}, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", " - xrepo download -f \"runtimes='MD'\" zlib", - " - xrepo download -f \"regex=true,thread=true\" boost"}, + " - xrepo download -f \"regex=true,thread=true\" boost" }, {'j', "jobs", "kv", tostring(os.default_njob()), - "Set the number of parallel download jobs."}, + "Set the number of parallel download jobs." }, + {nil, "toolchain", "kv", nil, "Set the toolchain name." }, + {nil, "toolchain_host", "kv", nil, "Set the host toolchain name." }, {nil, "includes", "kv", nil, "Includes extra lua configuration files.", "e.g.", - " - xrepo download -p cross --toolchain=mytool --includes='toolchain1.lua" .. path.envsep() .. "toolchain2.lua'"}, - {category = "Other Configuration" }, - {nil, "force", "k", nil, "Force to redownload all packages."}, - {'o', "outputdir", "kv", "packages","Set the packages download output directory."}, - {}, + " - xrepo download -p cross --toolchain=mytool --includes='toolchain1.lua" .. path.envsep() .. "toolchain2.lua'" }, + {category = "Other Configuration" }, + {nil, "force", "k", nil, "Force to redownload all packages." }, + {'o', "outputdir", "kv", "packages","Set the packages download output directory." }, + { }, {nil, "packages", "vs", nil, "The packages list.", "e.g.", " - xrepo download zlib boost", @@ -57,7 +59,7 @@ function menu_options() " - xrepo download -p android [--ndk=/xxx] -m debug \"pcre2 10.x\"", " - xrepo download -p mingw [--mingw=/xxx] -k shared zlib", " - xrepo download conan::zlib/1.2.11 vcpkg::zlib", - values = function (complete, opt) return import("private.xrepo.quick_search.completion")(complete, opt) end} + values = function (complete, opt) return import("private.xrepo.quick_search.completion")(complete, opt) end } } -- show menu options @@ -134,6 +136,12 @@ function _download_packages(packages) table.insert(config_argv, "-a") table.insert(config_argv, option.get("arch")) end + if option.get("toolchain") then + table.insert(config_argv, "--toolchain=" .. option.get("toolchain")) + end + if option.get("toolchain_host") then + table.insert(config_argv, "--toolchain_host=" .. option.get("toolchain_host")) + end local mode = option.get("mode") if mode then table.insert(config_argv, "-m") diff --git a/xmake/modules/private/xrepo/action/export.lua b/xmake/modules/private/xrepo/action/export.lua index e5a0fc78677..1b6e2e88511 100644 --- a/xmake/modules/private/xrepo/action/export.lua +++ b/xmake/modules/private/xrepo/action/export.lua @@ -31,28 +31,29 @@ function menu_options() -- menu options local options = { - {'k', "kind", "kv", nil, "Enable static/shared library.", - values = {"static", "shared"} }, - {'p', "plat", "kv", nil, "Set the given platform." }, - {'a', "arch", "kv", nil, "Set the given architecture." }, - {'m', "mode", "kv", nil, "Set the given mode.", - values = {"release", "debug"} }, - {'f', "configs", "kv", nil, "Set the given extra package configs.", + {'k', "kind", "kv", nil, "Enable static/shared library.", + values = {"static", "shared"} }, + {'p', "plat", "kv", nil, "Set the given platform." }, + {'a', "arch", "kv", nil, "Set the given architecture." }, + {'m', "mode", "kv", nil, "Set the given mode.", + values = {"release", "debug"} }, + {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", " - xrepo export -f \"runtimes='MD'\" zlib", - " - xrepo export -f \"regex=true,thread=true\" boost"}, - {}, - {nil, "includes", "kv", nil, "Includes extra lua configuration files."}, - {nil, "toolchain", "kv", nil, "Set the toolchain name." }, - {nil, "shallow", "k", nil, "Does not export dependent packages."}, - {'o', "packagedir", "kv", "packages","Set the exported packages directory."}, - {nil, "packages", "vs", nil, "The packages list.", + " - xrepo export -f \"regex=true,thread=true\" boost" }, + { }, + {nil, "includes", "kv", nil, "Includes extra lua configuration files." }, + {nil, "toolchain", "kv", nil, "Set the toolchain name." }, + {nil, "toolchain_host", "kv", nil, "Set the host toolchain name." }, + {nil, "shallow", "k", nil, "Does not export dependent packages." }, + {'o', "packagedir", "kv", "packages","Set the exported packages directory." }, + {nil, "packages", "vs", nil, "The packages list.", "e.g.", " - xrepo export zlib boost", " - xrepo export -p iphoneos -a arm64 \"zlib >=1.2.0\"", " - xrepo export -p android -m debug \"pcre2 10.x\"", " - xrepo export -p mingw -k shared zlib", - " - xrepo export conan::zlib/1.2.11 vcpkg::zlib"} + " - xrepo export conan::zlib/1.2.11 vcpkg::zlib" } } -- show menu options @@ -129,6 +130,9 @@ function _export_packages(packages) if option.get("toolchain") then table.insert(config_argv, "--toolchain=" .. option.get("toolchain")) end + if option.get("toolchain_host") then + table.insert(config_argv, "--toolchain_host=" .. option.get("toolchain_host")) + end local mode = option.get("mode") if mode then table.insert(config_argv, "-m") diff --git a/xmake/modules/private/xrepo/action/fetch.lua b/xmake/modules/private/xrepo/action/fetch.lua index 06178d02b6f..6fc25656c23 100644 --- a/xmake/modules/private/xrepo/action/fetch.lua +++ b/xmake/modules/private/xrepo/action/fetch.lua @@ -30,29 +30,30 @@ function menu_options() -- menu options local options = { - {'k', "kind", "kv", nil, "Enable static/shared library.", - values = {"static", "shared"} }, - {'p', "plat", "kv", nil, "Set the given platform." }, - {'a', "arch", "kv", nil, "Set the given architecture." }, - {'m', "mode", "kv", nil, "Set the given mode.", - values = {"release", "debug"} }, - {'f', "configs", "kv", nil, "Set the given extra package configs.", + {'k', "kind", "kv", nil, "Enable static/shared library.", + values = {"static", "shared"}}, + {'p', "plat", "kv", nil, "Set the given platform." }, + {'a', "arch", "kv", nil, "Set the given architecture." }, + {'m', "mode", "kv", nil, "Set the given mode.", + values = {"release", "debug"}}, + {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", " - xrepo fetch --configs=\"runtimes='MD'\" zlib", - " - xrepo fetch --configs=\"regex=true,thread=true\" boost"}, - {nil, "system", "k", "false", "Only fetch package on current system."}, - {}, - {nil, "toolchain", "kv", nil, "Set the toolchain name." }, - {nil, "includes", "kv", nil, "Includes extra lua configuration files.", + " - xrepo fetch --configs=\"regex=true,thread=true\" boost" }, + {nil, "system", "k", "false", "Only fetch package on current system." }, + { }, + {nil, "toolchain", "kv", nil, "Set the toolchain name." }, + {nil, "toolchain_host", "kv", nil, "Set the host toolchain name." }, + {nil, "includes", "kv", nil, "Includes extra lua configuration files.", "e.g.", - " - xrepo fetch -p cross --toolchain=mytool --includes='toolchain1.lua" .. path.envsep() .. "toolchain2.lua'"}, - {nil, "deps", "k", nil, "Fetch packages with dependencies." }, - {nil, "cflags", "k", nil, "Fetch cflags of the given packages." }, - {nil, "ldflags", "k", nil, "Fetch ldflags of the given packages."}, - {'e', "external", "k", nil, "Show cflags as external packages with -isystem."}, - {nil, "json", "k", nil, "Output package info as json format." }, - {}, - {nil, "packages", "vs", nil, "The packages list.", + " - xrepo fetch -p cross --toolchain=mytool --includes='toolchain1.lua" .. path.envsep() .. "toolchain2.lua'" }, + {nil, "deps", "k", nil, "Fetch packages with dependencies." }, + {nil, "cflags", "k", nil, "Fetch cflags of the given packages." }, + {nil, "ldflags", "k", nil, "Fetch ldflags of the given packages." }, + {'e', "external", "k", nil, "Show cflags as external packages with -isystem." }, + {nil, "json", "k", nil, "Output package info as json format." }, + { }, + {nil, "packages", "vs", nil, "The packages list.", "e.g.", " - xrepo fetch zlib boost", " - xrepo fetch /tmp/zlib.lua", @@ -62,7 +63,7 @@ function menu_options() " - xrepo fetch conan::zlib/1.2.11 vcpkg::zlib", " - xrepo fetch brew::zlib", " - xrepo fetch system::zlib (from pkgconfig, brew, /usr/lib ..)", - " - xrepo fetch pkgconfig::zlib"} + " - xrepo fetch pkgconfig::zlib" } } -- show menu options @@ -138,6 +139,9 @@ function _fetch_packages(packages) if option.get("toolchain") then table.insert(config_argv, "--toolchain=" .. option.get("toolchain")) end + if option.get("toolchain_host") then + table.insert(config_argv, "--toolchain_host=" .. option.get("toolchain_host")) + end local mode = option.get("mode") if mode then table.insert(config_argv, "-m") diff --git a/xmake/modules/private/xrepo/action/install.lua b/xmake/modules/private/xrepo/action/install.lua index 5f9b2bc3e92..873c52cc020 100644 --- a/xmake/modules/private/xrepo/action/install.lua +++ b/xmake/modules/private/xrepo/action/install.lua @@ -70,6 +70,7 @@ function menu_options() {category = "Cross Compilation Configuration" }, {nil, "sdk", "kv", nil, "Set the SDK directory of cross toolchain." }, {nil, "toolchain", "kv", nil, "Set the toolchain name." }, + {nil, "toolchain_host","kv", nil, "Set the host toolchain name." }, {category = "MingW Configuration" }, {nil, "mingw", "kv", nil, "Set the MingW SDK directory." }, {category = "XCode SDK Configuration" }, @@ -209,6 +210,9 @@ function _install_packages(packages) if option.get("toolchain") then table.insert(config_argv, "--toolchain=" .. option.get("toolchain")) end + if option.get("toolchain_host") then + table.insert(config_argv, "--toolchain_host=" .. option.get("toolchain_host")) + end -- for mingw if option.get("mingw") then table.insert(config_argv, "--mingw=" .. option.get("mingw")) diff --git a/xmake/modules/private/xrepo/action/remove.lua b/xmake/modules/private/xrepo/action/remove.lua index 71b52f79fb2..2744da94374 100644 --- a/xmake/modules/private/xrepo/action/remove.lua +++ b/xmake/modules/private/xrepo/action/remove.lua @@ -31,31 +31,32 @@ function menu_options() -- menu options local options = { - {'k', "kind", "kv", nil, "Enable static/shared library.", - values = {"static", "shared"} }, - {'p', "plat", "kv", nil, "Set the given platform." }, - {'a', "arch", "kv", nil, "Set the given architecture." }, - {'m', "mode", "kv", nil, "Set the given mode.", - values = {"release", "debug"} }, - {'f', "configs", "kv", nil, "Set the given extra package configs.", + {'k', "kind", "kv", nil, "Enable static/shared library.", + values = {"static", "shared"} }, + {'p', "plat", "kv", nil, "Set the given platform." }, + {'a', "arch", "kv", nil, "Set the given architecture." }, + {'m', "mode", "kv", nil, "Set the given mode.", + values = {"release", "debug"} }, + {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", " - xrepo remove -f \"runtimes='MD'\" zlib", - " - xrepo remove -f \"regex=true,thread=true\" boost"}, - {nil, "toolchain", "kv", nil, "Set the toolchain name." }, - {}, - {nil, "all", "k", nil, "Remove all packages and ignore extra package configs.", + " - xrepo remove -f \"regex=true,thread=true\" boost" }, + {nil, "toolchain", "kv", nil, "Set the toolchain name." }, + {nil, "toolchain_host", "kv", nil, "Set the host toolchain name." }, + { }, + {nil, "all", "k", nil, "Remove all packages and ignore extra package configs.", "If `--all` is enabled, the package name parameter will support lua pattern", "e.g.", " - xrepo remove --all", " - xrepo remove --all zlib boost", - " - xrepo remove --all zl* boo*"}, - {nil, "packages", "vs", nil, "The packages list.", + " - xrepo remove --all zl* boo*" }, + {nil, "packages", "vs", nil, "The packages list.", "e.g.", " - xrepo remove zlib boost", " - xrepo remove -p iphoneos -a arm64 \"zlib >=1.2.0\"", " - xrepo remove -p android -m debug \"pcre2 10.x\"", " - xrepo remove -p mingw -k shared zlib", - " - xrepo remove conan::zlib/1.2.11 vcpkg::zlib"} + " - xrepo remove conan::zlib/1.2.11 vcpkg::zlib" } } -- show menu options @@ -141,6 +142,9 @@ function _remove_packages(packages) if option.get("toolchain") then table.insert(config_argv, "--toolchain=" .. option.get("toolchain")) end + if option.get("toolchain_host") then + table.insert(config_argv, "--toolchain_host=" .. option.get("toolchain_host")) + end local envs = {} if #rcfiles > 0 then envs.XMAKE_RCFILES = path.joinenv(rcfiles) From 7af1ca50e38a7cf21048be7a62bd30103421cceb Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Sep 2024 00:56:56 +0800 Subject: [PATCH 2/9] fix host toolchain --- xmake/core/platform/platform.lua | 5 ++++- xmake/core/tool/compiler.lua | 12 +++++++++++- xmake/core/tool/linker.lua | 12 +++++++++++- xmake/core/tool/tool.lua | 6 ++---- xmake/core/tool/toolchain.lua | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1a8beb35799..a58d225e5a1 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -204,7 +204,10 @@ function _instance:toolchains(opt) if not toolchain_inst then os.raise(errors) end - table.insert(toolchains, toolchain_inst) + -- ignore cross toolchains for the host platform:w + if (self:is_host() and not toolchain_inst:is_cross()) or not self:is_host() then + table.insert(toolchains, toolchain_inst) + end end end self:_memcache():set("toolchains", toolchains) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index c11b2ba1dae..d90ccb7c172 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -100,8 +100,18 @@ function compiler._load_tool(sourcekind, target) program, toolname, toolchain_info = target:tool(sourcekind) end + -- is host? + local is_host + if target and target.is_host then + is_host = target:is_host() + end + -- load the compiler tool from the source kind - local result, errors = tool.load(sourcekind, {program = program, toolname = toolname, toolchain_info = toolchain_info}) + local result, errors = tool.load(sourcekind, { + host = is_host, + program = program, + toolname = toolname, + toolchain_info = toolchain_info}) if not result then return nil, errors end diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 2094d40a5a5..d91da81d88c 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -88,8 +88,18 @@ function linker._load_tool(targetkind, sourcekinds, target) program, toolname, toolchain_info = target:tool(_linkerinfo.linkerkind) end + -- is host? + local is_host + if target and target.is_host then + is_host = target:is_host() + end + -- load the linker tool from the linker kind (with cache) - linkertool, errors = tool.load(_linkerinfo.linkerkind, {program = program, toolname = toolname, toolchain_info = toolchain_info}) + linkertool, errors = tool.load(_linkerinfo.linkerkind, { + host = is_host, + program = program, + toolname = toolname, + toolchain_info = toolchain_info}) if linkertool then linkerinfo = _linkerinfo linkerinfo.program = program diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 8a453e1f0e8..9022880a4b9 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -237,8 +237,6 @@ end -- @param opt.toolchain_info the toolchain info (optional) -- function tool.load(kind, opt) - - -- get tool information opt = opt or {} local program = opt.program local toolname = opt.toolname @@ -249,7 +247,7 @@ function tool.load(kind, opt) local arch = toolchain_info.arch or config.get("arch") or os.arch() -- init cachekey - local cachekey = kind .. (program or "") .. plat .. arch + local cachekey = kind .. (program or "") .. plat .. arch .. (opt.host and "host" or "") -- get it directly from cache dirst tool._TOOLS = tool._TOOLS or {} @@ -273,7 +271,7 @@ function tool.load(kind, opt) -- get the tool program and name if not program then - program, toolname, toolchain_info = platform.tool(kind, plat, arch) + program, toolname, toolchain_info = platform.tool(kind, plat, arch, {host = opt.host}) if toolchain_info then assert(toolchain_info.plat == plat) assert(toolchain_info.arch == arch) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ce6b834a658..a8c4e514a41 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -167,7 +167,7 @@ end function _instance:is_cross() if self:kind() == "cross" then return true - elseif self:kind() == "standalone" and (self:cross() or self:sdkdir()) then + elseif self:kind() == "standalone" and (self:cross() or self:config("sdkdir") or self:info():get("sdkdir")) then return true end end From 62cf6e8821c974cb450ed3fb208d8331860db98a Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Sep 2024 22:19:13 +0800 Subject: [PATCH 3/9] fix host arguments --- .../modules/import/core/platform/platform.lua | 16 ++++++++-------- .../private/action/require/impl/package.lua | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 90cb487e2fd..0104ce40de6 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -26,8 +26,8 @@ local platform = require("platform/platform") local raise = require("sandbox/modules/raise") -- load the current platform -function sandbox_core_platform.load(plat, arch) - local instance, errors = platform.load(plat, arch) +function sandbox_core_platform.load(plat, arch, opt) + local instance, errors = platform.load(plat, arch, opt) if not instance then raise(errors) end @@ -55,21 +55,21 @@ function sandbox_core_platform.archs(plat, arch) end -- get the current platform configuration -function sandbox_core_platform.get(name, plat, arch) - return platform.get(name, plat, arch) +function sandbox_core_platform.get(name, plat, arch, opt) + return platform.get(name, plat, arch, opt) end -- get the platform tool from the kind -- -- e.g. cc, cxx, mm, mxx, as, ar, ld, sh, .. -- -function sandbox_core_platform.tool(toolkind, plat, arch) - return platform.tool(toolkind, plat, arch) +function sandbox_core_platform.tool(toolkind, plat, arch, opt) + return platform.tool(toolkind, plat, arch, opt) end -- get the current platform tool configuration -function sandbox_core_platform.toolconfig(name, plat, arch) - return platform.toolconfig(name, plat, arch) +function sandbox_core_platform.toolconfig(name, plat, arch, opt) + return platform.toolconfig(name, plat, arch, opt) end -- return module diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index c3fbdd0d046..18d4db5928d 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -487,7 +487,7 @@ function _check_package_toolchains(package) end else -- maybe this package is host package, it's platform and toolchain has been not checked yet. - local platform_inst = platform.load(package:plat(), package:arch()) + local platform_inst = platform.load(package:plat(), package:arch(), {host = package:is_host()}) if not platform_inst:check() then raise("no any matched platform for this package(%s)!", package:name()) end From 42493b00d94baf4a19a153c4759d323fedd1089d Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Sep 2024 23:33:41 +0800 Subject: [PATCH 4/9] fix package tips --- .../modules/private/action/require/impl/install_packages.lua | 4 ++-- xmake/modules/private/action/require/impl/package.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index eed6fa0b7b5..0dc0e61ee2b 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -738,9 +738,9 @@ function _install_packages(requires, opt) -- exists unsupported packages? if #packages_unsupported > 0 then - cprint("${bright color.warning}note: ${clear}the following packages are unsupported on $(plat)/$(arch):") + cprint("${bright color.warning}note: ${clear}the following packages are unsupported:") for _, instance in ipairs(packages_unsupported) do - print(" -> %s %s", instance:displayname(), instance:version_str() or "") + cprint(" ${yellow}->${clear} %s %s ${dim}%s", instance:displayname(), instance:version_str() or "", package.get_configs_str(instance)) end has_errors = true end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 18d4db5928d..87c91aedd0e 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -1311,7 +1311,7 @@ function get_configs_str(package) table.insert(configs, requireinfo.arch) end if requireinfo.host then - table.insert(configs, requireinfo.host) + table.insert(configs, "host") end if requireinfo.kind then table.insert(configs, requireinfo.kind) From feb7563b4ea3712079063c3a81a13e189f49ac75 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Sep 2024 23:42:14 +0800 Subject: [PATCH 5/9] improve tips --- .../action/require/impl/install_packages.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 0dc0e61ee2b..303b300d9c5 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -738,9 +738,18 @@ function _install_packages(requires, opt) -- exists unsupported packages? if #packages_unsupported > 0 then - cprint("${bright color.warning}note: ${clear}the following packages are unsupported:") + local packages_unsupported_maps = {} for _, instance in ipairs(packages_unsupported) do - cprint(" ${yellow}->${clear} %s %s ${dim}%s", instance:displayname(), instance:version_str() or "", package.get_configs_str(instance)) + local key = instance:plat() .. "/" .. instance:arch() + packages_unsupported_maps[key] = packages_unsupported_maps[key] or {} + table.insert(packages_unsupported_maps[key], instance) + end + for key, instances in pairs(packages_unsupported_maps) do + cprint("${bright color.warning}note: ${clear}the following packages are unsupported on %s:", key) + for _, instance in ipairs(instances) do + cprint(" ${yellow}->${clear} %s %s ${dim}%s", + instance:displayname(), instance:version_str() or "", package.get_configs_str(instance)) + end end has_errors = true end From ac62c9c9ed4ad7eff47b90c56fabdc6f6df6c492 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Sep 2024 23:52:52 +0800 Subject: [PATCH 6/9] improve package configs str --- xmake/modules/private/action/require/impl/package.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 87c91aedd0e..072b7e9c402 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -1302,6 +1302,9 @@ function get_configs_str(package) if package:is_private() then table.insert(configs, "private") end + if package:is_host() then + table.insert(configs, "host") + end local requireinfo = package:requireinfo() if requireinfo then if requireinfo.plat then @@ -1310,9 +1313,6 @@ function get_configs_str(package) if requireinfo.arch then table.insert(configs, requireinfo.arch) end - if requireinfo.host then - table.insert(configs, "host") - end if requireinfo.kind then table.insert(configs, requireinfo.kind) end From fa452cfb19df74c9461fb97b987ec2e792bcb4f2 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 23 Sep 2024 23:14:28 +0800 Subject: [PATCH 7/9] all package deps inherit host --- xmake/modules/private/action/require/impl/package.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 072b7e9c402..5fc10ee0ed6 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -619,6 +619,12 @@ function _finish_requireinfo(requireinfo, package) requireinfo.configs[k] = nil end end + + -- all binary packages are host package + -- we need to synchronize the setup to requireinfo so that all its dependent packages inherit from it. + if package:is_binary() then + requireinfo.host = true + end end -- merge requireinfo from `add_requireconfs()` From 35699f52bd368650b4cfb1fc7d8a11dcf280e10f Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 23 Sep 2024 23:14:54 +0800 Subject: [PATCH 8/9] remove private tag in require key --- .../modules/private/action/require/impl/utils/requirekey.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index 9378a8cb700..2e1b0f400a7 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -55,9 +55,11 @@ function main(requireinfo, opt) if requireinfo.system then key = key .. "/system" end + --[[ + -- @see https://github.com/xmake-io/xmake/issues/4934 if requireinfo.private then key = key .. "/private" - end + end]] if key:startswith("/") then key = key:sub(2) end From 3f025d4e605ff5e0707af8a0f4d00402d8dbea3c Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 24 Sep 2024 00:59:41 +0800 Subject: [PATCH 9/9] test host --- xmake/modules/private/action/require/impl/utils/requirekey.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index 2e1b0f400a7..633abb0d1de 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -55,11 +55,10 @@ function main(requireinfo, opt) if requireinfo.system then key = key .. "/system" end - --[[ -- @see https://github.com/xmake-io/xmake/issues/4934 if requireinfo.private then key = key .. "/private" - end]] + end if key:startswith("/") then key = key:sub(2) end