Skip to content

Commit 4e9459e

Browse files
committed
load cosmocc envs
1 parent 8725288 commit 4e9459e

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

xmake/modules/detect/tools/find_cosmoar.lua

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import("lib.detect.find_program")
3636
function main(opt)
3737
opt = opt or {}
3838
opt.shell = true
39+
opt.envs = opt.envs or {PATH = os.getenv("PATH")}
3940
local program = find_program(opt.program or "cosmoar", opt)
4041
if program and is_host("windows") then
4142
program = program:gsub("\\", "/")

xmake/modules/detect/tools/find_cosmocc.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import("lib.detect.find_programver")
3737
function main(opt)
3838
opt = opt or {}
3939
opt.shell = true
40-
opt.envs = {PATH = os.getenv("PATH")}
40+
opt.envs = opt.envs or {PATH = os.getenv("PATH")}
4141
local program = find_program(opt.program or "cosmocc", opt)
4242
if program and is_host("windows") then
4343
program = program:gsub("\\", "/")

xmake/modules/detect/tools/find_cosmocxx.lua

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import("lib.detect.find_programver")
3737
function main(opt)
3838
opt = opt or {}
3939
opt.shell = true
40+
opt.envs = opt.envs or {PATH = os.getenv("PATH")}
4041
local program = find_program(opt.program or "cosmoc++", opt)
4142
if program and is_host("windows") then
4243
program = program:gsub("\\", "/")

xmake/toolchains/cosmocc/check.lua

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function main(toolchain)
3232
local bindir = toolchain:bindir()
3333

3434
-- find cross toolchain from external envirnoment
35+
local envs
3536
local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir})
3637
if not cross_toolchain then
3738
-- find it from packages
@@ -40,6 +41,11 @@ function main(toolchain)
4041
if installdir and os.isdir(installdir) then
4142
cross_toolchain = find_cross_toolchain(installdir)
4243
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
4349
break
4450
end
4551
end
@@ -57,9 +63,13 @@ function main(toolchain)
5763
toolchain:config_set("cross", cross_toolchain.cross)
5864
toolchain:config_set("bindir", cross_toolchain.bindir)
5965
toolchain:config_set("sdkdir", cross_toolchain.sdkdir)
66+
if envs then
67+
toolchain:config_set("envs", envs)
68+
end
6069
toolchain:configs_save()
6170
else
6271
raise("cosmocc toolchain not found!")
6372
end
6473
return cross_toolchain
6574
end
75+

xmake/toolchains/cosmocc/xmake.lua

+8
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ toolchain("cosmocc")
4545
toolchain:set("toolset", "ranlib", "aarch64-linux-cosmo-ranlib")
4646
toolchain:set("toolset", "strip", "aarch64-linux-cosmo-strip")
4747
end
48+
-- @see https://github.com/xmake-io/xmake/issues/5552
49+
local envs = toolchain:config("envs")
50+
if envs then
51+
for k, v in pairs(envs) do
52+
toolchain:add("runenvs", k, v)
53+
end
54+
end
4855
end)
56+

0 commit comments

Comments
 (0)