-
I had installed cosmocc manually (added to So, I tried to improve the --!A cross-platform build utility based on Lua
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file find_cosmocc.lua
--
-- imports
import("lib.detect.find_tool")
import("lib.detect.find_program")
import("lib.detect.find_programver")
-- find cosmocc
--
-- @param opt the argument options, e.g. {version = true}
--
-- @return program, version
--
-- @code
--
-- local cosmocc = find_cosmocc()
--
-- @endcode
--
function main(opt)
opt = opt or {}
opt.shell = true
local cosmocc
local fprg = opt.program or "cosmocc"
local cosmocc_prg = find_program(fprg, opt)
if cosmocc_prg then
cosmocc = cosmocc_prg
else
local sh = find_tool("sh") or find_tool("bash") or find_tool("zsh")
if sh then
local find
if os.is_host("windows") then
find = format("where %s || echo", fprg)
else
find = format("command -v %s || echo", fprg)
end
cosmocc, _ = try { function() return os.iorunv(sh.program, { "-c", find }) end }
local first_line = string.gmatch(cosmocc, "[^\n]+")()
if first_line then
cosmocc = first_line:trim()
end
end
end
local program = nil
local version = nil
if cosmocc then
program = path.translate(cosmocc)
if program and is_host("windows") then
program = program:gsub("\\", "/")
end
if program and opt and opt.version then
-- the version will be of the underlying
-- tool being used by cosmocc and not of the
-- cosmocc toolchain package
version = find_programver(program, opt)
end
end
return program, version
end which helps on_fetch(function(package, opt)
if opt.system then
return package:find_tool("cosmocc")
end
end) The problem would still persist for to find the sdkdir and bindir in the toolchain config and hence, raises an Modifying the --!A cross-toolchain build utility based on Lua
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file check.lua
--
-- imports
import("core.project.config")
import("lib.detect.find_path")
import("lib.detect.find_tool")
import("detect.sdks.find_cross_toolchain")
-- check the cross toolchain
function main(toolchain)
-- get sdk directory
local sdkdir = toolchain:sdkdir()
local bindir = toolchain:bindir()
-- find and locate sdk directory
if not sdkdir then
local tool = find_tool("cosmocc")
if tool and tool.program then
sdkdir = path.directory(path.directory((tool.program)))
end
end
-- find cross toolchain from external envirnoment
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
break
end
end
end
end
if cross_toolchain then
toolchain:config_set("cross", cross_toolchain.cross)
toolchain:config_set("bindir", cross_toolchain.bindir)
toolchain:config_set("sdkdir", cross_toolchain.sdkdir)
toolchain:configs_save()
else
raise("cosmocc toolchain not found!")
end
return cross_toolchain
end works but what if the local toolchain is somehow gets corrupt and I'm willing to use the remote toolchain package, I think the local one would still prevail. Is there something that could force it? Maybe some kind of I'm willing to contribute to both this and xmake-repo after the conclusion of this discussion. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
find_program will call |
Beta Was this translation helpful? Give feedback.
-
Because I disabled to find them from $PATH by default.
The current cosmocc toolchain only supports finding it from the xmake-repo/cosmocc package, finding it from the PATH and other system paths is not supported. |
Beta Was this translation helpful? Give feedback.
try this patch #5281