From 6926dc82b90ee05088694821aa5e829d25d8a3b4 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 5 Sep 2024 22:45:29 +0800 Subject: [PATCH 1/3] improve to select runtimes --- xmake/modules/private/action/require/impl/package.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 878a1eaf4ea..48339fef3f6 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -1011,6 +1011,13 @@ function _load_package(packagename, requireinfo, opt) -- check package configurations _check_package_configurations(package) + -- we need to check package toolchains before on_load and select runtimes, + -- 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) + -- we need to select package runtimes before computing buildhash -- @see https://github.com/xmake-io/xmake/pull/4630#issuecomment-1910216561 _select_package_runtimes(package) From e96c3155ee33cdba5bd83f756d1134c55e4c9fa8 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 5 Sep 2024 22:48:39 +0800 Subject: [PATCH 2/3] improve to get link name --- xmake/core/project/target.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ace54441c0e..4ca895d0cf9 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2947,8 +2947,13 @@ function target.linkname(filename, opt) if count > 0 and linkname then return linkname end - -- for custom shared libraries name, xxx.so, xxx.dylib - if not filename:startswith("lib") and (filename:endswith(".so") or filename:endswith(".dylib")) then + -- fallback to the generic unix library name, libxxx.a, libxxx.so, .. + if filename:startswith("lib") then + if filename:endswith(".a") or filename:endswith(".so") then + return path.basename(filename:sub(4)) + end + elseif filename:endswith(".so") or filename:endswith(".dylib") then + -- for custom shared libraries name, xxx.so, xxx.dylib return filename end return nil From 82532a9c09fc8adc9e1b6c22ecfebfef0bd88792 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 5 Sep 2024 23:39:34 +0800 Subject: [PATCH 3/3] improve cosmocc --- xmake/toolchains/cosmocc/check.lua | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/xmake/toolchains/cosmocc/check.lua b/xmake/toolchains/cosmocc/check.lua index 5876db68f76..72f4cfe37c3 100644 --- a/xmake/toolchains/cosmocc/check.lua +++ b/xmake/toolchains/cosmocc/check.lua @@ -33,24 +33,25 @@ function main(toolchain) -- find cross toolchain from external envirnoment local envs - local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) - if not cross_toolchain then - -- find it from packages - for _, package in ipairs(toolchain:packages()) do - local installdir = package:installdir() - if installdir and os.isdir(installdir) then - cross_toolchain = find_cross_toolchain(installdir) - if cross_toolchain then - -- we need to bind msys2 shell envirnoments for calling cosmocc, - -- @see https://github.com/xmake-io/xmake/issues/5552 - if is_subhost("windows") then - envs = package:envs() - end - break + local cross_toolchain + -- find it from packages first, because we need bind msys2 envirnoments from package. + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir and os.isdir(installdir) then + cross_toolchain = find_cross_toolchain(installdir) + if cross_toolchain then + -- we need to bind msys2 shell envirnoments for calling cosmocc, + -- @see https://github.com/xmake-io/xmake/issues/5552 + if is_subhost("windows") then + envs = package:envs() end + break end end end + if not cross_toolchain then + cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + end if not cross_toolchain then local cosmocc = find_tool("cosmocc", {force = true}) if cosmocc and cosmocc.program then