Skip to content

Commit a3f5028

Browse files
authored
Merge pull request #5572 from xmake-io/cosmocc
improve to select runtimes
2 parents fe2154b + 82532a9 commit a3f5028

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

xmake/core/project/target.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -2947,8 +2947,13 @@ function target.linkname(filename, opt)
29472947
if count > 0 and linkname then
29482948
return linkname
29492949
end
2950-
-- for custom shared libraries name, xxx.so, xxx.dylib
2951-
if not filename:startswith("lib") and (filename:endswith(".so") or filename:endswith(".dylib")) then
2950+
-- fallback to the generic unix library name, libxxx.a, libxxx.so, ..
2951+
if filename:startswith("lib") then
2952+
if filename:endswith(".a") or filename:endswith(".so") then
2953+
return path.basename(filename:sub(4))
2954+
end
2955+
elseif filename:endswith(".so") or filename:endswith(".dylib") then
2956+
-- for custom shared libraries name, xxx.so, xxx.dylib
29522957
return filename
29532958
end
29542959
return nil

xmake/modules/private/action/require/impl/package.lua

+7
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,13 @@ function _load_package(packagename, requireinfo, opt)
10111011
-- check package configurations
10121012
_check_package_configurations(package)
10131013

1014+
-- we need to check package toolchains before on_load and select runtimes,
1015+
-- because we will call compiler-specific apis in on_load/on_fetch/find_package ..
1016+
--
1017+
-- @see https://github.com/xmake-io/xmake/pull/5466
1018+
-- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801
1019+
_check_package_toolchains(package)
1020+
10141021
-- we need to select package runtimes before computing buildhash
10151022
-- @see https://github.com/xmake-io/xmake/pull/4630#issuecomment-1910216561
10161023
_select_package_runtimes(package)

xmake/toolchains/cosmocc/check.lua

+15-14
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,25 @@ function main(toolchain)
3333

3434
-- find cross toolchain from external envirnoment
3535
local envs
36-
local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir})
37-
if not cross_toolchain then
38-
-- find it from packages
39-
for _, package in ipairs(toolchain:packages()) do
40-
local installdir = package:installdir()
41-
if installdir and os.isdir(installdir) then
42-
cross_toolchain = find_cross_toolchain(installdir)
43-
if cross_toolchain then
44-
-- we need to bind msys2 shell envirnoments for calling cosmocc,
45-
-- @see https://github.com/xmake-io/xmake/issues/5552
46-
if is_subhost("windows") then
47-
envs = package:envs()
48-
end
49-
break
36+
local cross_toolchain
37+
-- find it from packages first, because we need bind msys2 envirnoments from package.
38+
for _, package in ipairs(toolchain:packages()) do
39+
local installdir = package:installdir()
40+
if installdir and os.isdir(installdir) then
41+
cross_toolchain = find_cross_toolchain(installdir)
42+
if cross_toolchain then
43+
-- we need to bind msys2 shell envirnoments for calling cosmocc,
44+
-- @see https://github.com/xmake-io/xmake/issues/5552
45+
if is_subhost("windows") then
46+
envs = package:envs()
5047
end
48+
break
5149
end
5250
end
5351
end
52+
if not cross_toolchain then
53+
cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir})
54+
end
5455
if not cross_toolchain then
5556
local cosmocc = find_tool("cosmocc", {force = true})
5657
if cosmocc and cosmocc.program then

0 commit comments

Comments
 (0)