diff options
| author | ruki <[email protected]> | 2024-08-18 22:54:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-08-23 08:14:32 +0800 |
| commit | 3000c00cfabfed31edd9e9a67d64045f5de7e589 (patch) | |
| tree | 9b63dde886a3abb8ff3ba36c3c1caee1be3e9e07 /xmake/modules | |
| parent | 9b81b86e21ce132cc3a4d03b1868c2a7748c8345 (diff) | |
install toolchain packages first
Diffstat (limited to 'xmake/modules')
4 files changed, 45 insertions, 56 deletions
diff --git a/xmake/modules/package/manager/system/find_package.lua b/xmake/modules/package/manager/system/find_package.lua index 4d939e495..632db0c63 100644 --- a/xmake/modules/package/manager/system/find_package.lua +++ b/xmake/modules/package/manager/system/find_package.lua @@ -38,26 +38,6 @@ function _get_package_items() return items end --- check package toolchains -function _check_package_toolchains(package) - local has_standalone - if package:toolchains() then - for _, toolchain_inst in ipairs(package:toolchains()) do - if toolchain_inst:check() and toolchain_inst:is_standalone() then - has_standalone = true - end - end - else - -- we need also check platform toolchain, perhaps it has a different platform arch. - -- @see https://github.com/xmake-io/xmake/issues/4043#issuecomment-2102486249 - local platform_inst = platform.load(package:plat(), package:arch()) - if platform_inst:check() then - has_standalone = true - end - end - return has_standalone -end - -- find package from system and compiler -- @see https://github.com/xmake-io/xmake/issues/4596 -- @@ -80,16 +60,6 @@ function main(name, opt) end snippet_configs.links = snippet_configs.links or name - -- We need to check package toolchain first - -- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801 - -- - -- But if it depends on some toolchain packages, - -- then they can't be detected early in the fetch and we have to disable system.find_package - local package = opt.package - if package and not _check_package_toolchains(package) then - return - end - local snippet_opt = { verbose = opt.verbose, target = opt.package, diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index e3e81aa22..04ecd0036 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -223,23 +223,6 @@ function _fix_paths_for_precompiled_package(package) end end --- check package toolchains -function _check_package_toolchains(package) - if package:toolchains() then - for _, toolchain_inst in pairs(package:toolchains()) do - if not toolchain_inst:check() then - raise("toolchain(\"%s\"): not found!", toolchain_inst:name()) - end - 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()) - if not platform_inst:check() then - raise("no any matched platform for this package(%s)!", package:name()) - end - end -end - -- get failed install directory function _get_installdir_failed(package) return path.join(package:cachedir(), "installdir.failed") @@ -404,9 +387,6 @@ function main(package) -- enter the environments of all package dependencies _enter_package_installenvs(package) - -- check package toolchains - _check_package_toolchains(package) - -- do install if script ~= nil then filter.call(script, package, {oldenvs = oldenvs}) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 14dd87e33..8b9a36cf9 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -379,8 +379,8 @@ function _should_install_package(instance) return result end --- install packages -function _install_packages(packages_install, packages_download, installdeps) +-- do install packages +function _do_install_packages(packages_install, packages_download, installdeps) -- we need to hide wait characters if is not a tty local show_wait = io.isatty() @@ -663,9 +663,7 @@ function _get_package_installdeps(packages) end -- install packages -function main(requires, opt) - - -- init options +function _install_packages(requires, opt) opt = opt or {} -- load packages @@ -794,7 +792,7 @@ function main(requires, opt) _sort_packages_urls(packages_download) -- install all required packages from repositories - _install_packages(packages_install, packages_download, installdeps) + _do_install_packages(packages_install, packages_download, installdeps) -- disable other packages in same group _disable_other_packages_in_group(packages) @@ -813,3 +811,13 @@ function main(requires, opt) return packages end +function main(requires, opt) + -- we need to install toolchain packages first, + -- because we will call compiler-specific api in package.on_load, + -- and we will check package toolchains before calling package.on_load + -- + -- @see https://github.com/xmake-io/xmake/pull/5466 + _install_packages(requires, table.join(opt or {}, {toolchain = true})) + return _install_packages(requires, opt) +end + diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 4fe91b636..0eb2b917c 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -487,6 +487,23 @@ function _check_package_configurations(package) end end +-- check package toolchains +function _check_package_toolchains(package) + if package:toolchains() then + for _, toolchain_inst in pairs(package:toolchains()) do + if not toolchain_inst:check() then + raise("toolchain(\"%s\"): not found!", toolchain_inst:name()) + end + 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()) + if not platform_inst:check() then + raise("no any matched platform for this package(%s)!", package:name()) + end + end +end + -- match require path function _match_requirepath(requirepath, requireconf) @@ -937,6 +954,13 @@ function _load_package(packagename, requireinfo, opt) -- save require info package:requireinfo_set(requireinfo) + -- only load toolchain package and its deps + if opt.toolchain then + if package:is_toplevel() and not package:is_toolchain()then + return + end + end + -- init urls source package:_init_source() @@ -1004,6 +1028,13 @@ function _load_package(packagename, requireinfo, opt) end end + -- we need to check package toolchains before on_load, + -- because we will call compiler-specific apis in on_load/on_fetch/find_package .. + -- + -- @see https://github.com/xmake-io/xmake/pull/5466 + -- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801 + _check_package_toolchains(package) + -- do load package:_load() |
