Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/service/xmake.lua | --!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 service.lua
--
task("service")
set_category("action")
on_run("main")
set_menu {usage = "xmake service [options]",
description = "Start service for remote or distributed compilation and etc.",
options = {
{nil, "start", "k", nil, "Start daemon service.",
"e.g.",
" - xmake service --start",
" - xmake service --start --remote",
" - xmake service --start --distcc",
" - xmake service --start --remote --distcc" },
{nil, "restart", "k", nil, "Restart daemon service." },
{nil, "stop" , "k", nil, "Stop daemon service." },
{nil, "connect" , "k", nil, "Connect current project to the remote daemon service.",
"e.g.",
" - xmake service --connect",
" - xmake service --connect --remote",
" - xmake service --connect --distcc",
" - xmake service --connect --remote --distcc" },
{nil, "session" , "kv", nil,"Connect with the given session name, it will generate a session id via name.",
"e.g.",
" -- xmake service --connect --ccache --session=foo" },
{nil, "reconnect", "k", nil, "Reconnect current project to the remote daemon service." },
{nil, "disconnect", "k", nil, "Disconnect current project in the remote daemon service." },
{nil, "remote", "k", nil, "Start or connect the remote build service." },
{nil, "distcc", "k", nil, "Start or connect the distributed build service." },
{nil, "ccache", "k", nil, "Start or connect the remote c/c++ cache service." },
{nil, "sync", "k", nil, "Sync current project files in the remote daemon service." },
{nil, "xmakesrc", "kv", nil, "Sync xmake program files in the remote daemon service.",
"e.g.",
" - xmake service --sync --xmakesrc=/xmakeproj/xmake" },
{nil, "pull", "k", nil, "Pull the given file or directory in the remote daemon service.",
"e.g.",
" - xmake service --pull build outputdir",
" - xmake service --pull 'build/**' outputdir" },
{nil, "clean", "k", nil, "Clean current project files in the remote daemon service." },
{nil, "all", "k", nil, "Clean all project files in the remote daemon service.",
"e.g.",
" - xmake service --clean --all" },
{nil, "add-user", "kv", nil, "Add user in the server.",
"e.g.",
" - xmake service --add-user=root" },
{nil, "rm-user", "kv", nil, "Remove user in the server.",
"e.g.",
" - xmake service --rm-user=root" },
{nil, "gen-token", "k", nil, "Generate a new token in the server.",
"e.g.",
" - xmake service --gen-token" },
{nil, "logs", "k", nil, "Show service logs if the daemon service has been started." },
{nil, "status", "k", nil, "Show service status if the daemon service has been started." },
{nil, "values", "vs", nil, "The values list for pull/.. options." }
}}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/create/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.project.project")
import("core.project.template")
-- get the builtin variables
function _get_builtinvars(tempinst, targetname)
return {TARGETNAME = targetname,
FAQ = function() return io.readfile(path.join(os.programdir(), "scripts", "faq.lua")) end}
end
-- create project from template
function _create_project(language, templateid, targetname)
-- check the targetname
assert(targetname ~= ".", "you should specify ${red}-P${reset} instead of directly using ${red}.${reset}")
-- check the language
assert(language, "no language!")
-- check the template id
assert(templateid, "no template id!")
-- load all templates for the given language
local templates = template.templates(language)
-- TODO: deprecated
-- in order to be compatible with the old version template
local templates_new = { quickapp_qt = "qt.quickapp",
widgetapp_qt = "qt.widgetapp",
console_qt = "qt.console",
static_qt = "qt.static",
shared_qt = "qt.shared",
console_tbox = "tbox.console",
static_tbox = "tbox.static",
shared_tbox = "tbox.shared"}
if templates_new[templateid] then
cprint("${yellow}deprecated: please uses template(%s) instead of template(%s)!", templates_new[templateid], templateid)
templateid = templates_new[templateid]
end
-- get the given template instance
local tempinst = nil
if templates then
for _, t in ipairs(templates) do
if t:name() == templateid then
tempinst = t
break
end
end
end
assert(tempinst and tempinst:scriptdir(), "invalid template id: %s!", templateid)
-- get project directory
local projectdir = path.absolute(option.get("project") or path.join(os.curdir(), targetname))
if not os.isdir(projectdir) then
-- make the project directory if not exists
os.mkdir(projectdir)
end
-- xmake.lua exists?
if os.isfile(path.join(projectdir, "xmake.lua")) and not option.get("force") then
raise("project (${underline}%s/xmake.lua${reset}) exists!", projectdir)
end
-- empty project?
os.tryrm(path.join(projectdir, ".xmake"))
if not os.emptydir(projectdir) and not option.get("force") then
-- otherwise, check whether it is empty
raise("project directory (${underline}%s${reset}) is not empty!", projectdir)
end
-- enter the project directory
os.cd(projectdir)
-- create project
local filedirs = {}
local sourcedir = path.join(tempinst:scriptdir(), "project")
if os.isdir(sourcedir) then
for _, filedir in ipairs(os.filedirs(path.join(sourcedir, "*"))) do
-- https://github.com/xmake-io/xmake/issues/5138#issuecomment-2329238617
os.cp(filedir, projectdir, {writeable = true})
table.insert(filedirs, path.relative(filedir, sourcedir))
end
os.cp(path.join(os.programdir(), "scripts", "gitignore"), path.join(projectdir, ".gitignore"))
table.insert(filedirs, ".gitignore")
else
raise("template(%s): project not found!", templateid)
end
-- get the builtin variables
local builtinvars = _get_builtinvars(tempinst, targetname)
-- replace all variables
for _, configfile in ipairs(tempinst:get("configfiles")) do
local pattern = "%${(.-)}"
io.gsub(configfile, "(" .. pattern .. ")", function(_, variable)
variable = variable:trim()
local value = builtinvars[variable]
return type(value) == "function" and value() or value
end)
end
-- do after_create
local after_create = tempinst:get("create_after")
if after_create then
after_create(tempinst, {targetname = targetname})
end
-- trace
for _, filedir in ipairs(filedirs) do
if os.isdir(filedir) then
for _, file in ipairs(os.files(path.join(filedir, "**"))) do
cprint(" ${green}[+]: ${clear}%s", file)
end
else
cprint(" ${green}[+]: ${clear}%s", filedir)
end
end
end
-- main
function main()
-- enter the original working directory, because the default directory is in the project directory
os.cd(os.workingdir())
-- the target name
local targetname = option.get("target") or path.basename(project.directory()) or "demo"
-- trace
cprint("${bright}create %s ...", targetname)
-- create project from template
_create_project(option.get("language"), option.get("template"), targetname)
-- trace
cprint("${color.success}create ok!")
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/create/xmake.lua | --!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 xmake.lua
--
-- define task
task("create")
-- set category
set_category("action")
-- on run
on_run("main")
-- set menu
set_menu {
-- usage
usage = "xmake create [options] [target]"
-- description
, description = "Create a new project."
-- options
, options =
{
{'f', "force", "k", nil, "Force to create project in a non-empty directory."}
, {'l', "language", "kv", "c++", "The project language"
-- show the description of all languages
, values = function (complete, opt)
-- import template
import("core.project.template")
-- get languages
local languages = template.languages()
if not complete or not opt.template then return languages end
local accepted_lang = {}
for _, l in ipairs(languages) do
for _, t in ipairs(template.templates(l)) do
if t:name() == opt.template then
table.insert(accepted_lang, l)
break
end
end
end
return accepted_lang
end }
, {'t', "template", "kv", "console", "Select the project template id or name of the given language.",
-- show the description of all templates
function ()
-- import template
import("core.project.template")
-- get templates
local templates = {}
for _, l in ipairs(template.languages()) do
for _, t in ipairs(template.templates(l)) do
templates[t:name()] = templates[t:name()] or {}
table.insert(templates[t:name()], l)
end
end
-- get sorted templates
local templates_sorted = {}
for name, languages in pairs(templates) do
table.insert(templates_sorted, {name = name, languages = languages})
end
table.sort(templates_sorted, function(a, b) return a.name < b.name end)
-- make description
local description = {}
for _, t in ipairs(templates_sorted) do
table.insert(description, " - " .. t.name .. ": " .. table.concat(t.languages, ", "))
end
return description
end
, values = function (complete, opt)
if not complete then return end
-- import template
import("core.project.template")
-- get templates
local templates = {}
for _, l in ipairs(opt.language and {opt.language} or template.languages()) do
for _, t in ipairs(template.templates(l)) do
table.insert(templates, t:name())
end
end
return templates
end }
, {}
, {nil, "target", "v", nil, "Create the given target."
, "Uses the project name as target if not exists." }
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/run/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.task")
import("core.project.config")
import("core.base.global")
import("core.project.project")
import("core.platform.platform")
import("devel.debugger")
import("async.runjobs")
import("private.action.run.runenvs")
import("private.service.remote_build.action", {alias = "remote_build_action"})
-- run target
function _do_run_target(target)
-- only for binary program
if not target:is_binary() then
return
end
-- get the run directory of target
local rundir = target:rundir()
-- get the absolute target file path
local targetfile = path.absolute(target:targetfile())
-- get the run environments
local addenvs, setenvs = runenvs.make(target)
-- get run arguments
local args = table.wrap(option.get("arguments") or target:get("runargs"))
-- debugging?
if option.get("debug") then
debugger.run(targetfile, args, {curdir = rundir, addenvs = addenvs, setenvs = setenvs})
else
os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs})
end
end
-- run target
function _on_run_target(target)
-- build target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_run = r:script("run")
if on_run then
on_run(target)
done = true
end
end
if done then return end
-- do run
_do_run_target(target)
end
-- recursively add target envs
function _add_target_pkgenvs(target, targets_added)
if targets_added[target:name()] then
return
end
targets_added[target:name()] = true
os.addenvs(target:pkgenvs())
for _, dep in ipairs(target:orderdeps()) do
_add_target_pkgenvs(dep, targets_added)
end
end
-- find target names matching a specific name
function _find_matching_target_names(targetname)
targetname = targetname:lower()
local matching_targetnames = {}
for _, target in ipairs(project.ordertargets()) do
if target:name():lower():find(targetname, 1, true) then
table.insert(matching_targetnames, target:name())
end
end
table.sort(matching_targetnames)
return matching_targetnames
end
-- run the given target
function _run(target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- enter the environments of the target packages
local oldenvs = os.getenvs()
_add_target_pkgenvs(target, {})
-- the target scripts
local scripts =
{
target:script("run_before")
, function (target)
for _, r in ipairs(target:orderules()) do
local before_run = r:script("run_before")
if before_run then
before_run(target)
end
end
end
, target:script("run", _on_run_target)
, function (target)
for _, r in ipairs(target:orderules()) do
local after_run = r:script("run_after")
if after_run then
after_run(target)
end
end
end
, target:script("run_after")
}
-- run the target scripts
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
end
-- check targets
function _check_targets(targetname, group_pattern)
-- get targets
local targets = {}
if targetname then
local target = project.target(targetname)
if not target then
-- check if the name is part of other target to help
local possible_targetnames = _find_matching_target_names(targetname)
local errors = targetname .. " is not a valid target name for this project"
if #possible_targetnames > 0 then
errors = errors .. "\nlist of valid target names close to your input:\n - " .. table.concat(possible_targetnames, '\n - ')
end
raise(errors)
end
table.insert(targets, target)
else
for _, target in ipairs(project.ordertargets()) do
if target:is_binary() or target:script("run") then
local group = target:get("group")
if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
end
end
-- filter and check targets with builtin-run script
local targetnames = {}
for _, target in ipairs(targets) do
if target:targetfile() and target:is_enabled() and not target:script("run") then
local targetfile = target:targetfile()
if targetfile and not os.isfile(targetfile) then
table.insert(targetnames, target:name())
end
end
end
-- there are targets that have not yet been built?
if #targetnames > 0 then
raise("please run `$xmake build [target]` to build the following targets first:\n -> " .. table.concat(targetnames, '\n -> '))
end
end
-- main
function main()
-- do action for remote?
if remote_build_action.enabled() then
return remote_build_action()
end
-- load config first
config.load()
-- Automatically build before running
if project.policy("run.autobuild") then
-- we need clear the previous config and reload it
-- to avoid trigger recheck configs
config.clear()
task.run("build", {target = option.get("target"), all = option.get("all")})
end
-- load targets
project.load_targets()
-- check targets first
local targetname
local group_pattern = option.get("group")
if group_pattern then
group_pattern = "^" .. path.pattern(group_pattern) .. "$"
else
targetname = option.get("target")
end
_check_targets(targetname, group_pattern)
-- enter project directory
local oldir = os.cd(project.directory())
-- run the given target?
if targetname then
_run(project.target(targetname))
else
local targets = {}
for _, target in ipairs(project.ordertargets()) do
if target:is_binary() or target:script("run") then
local group = target:get("group")
if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
table.insert(targets, target)
end
end
end
local jobs = tonumber(option.get("jobs") or "1")
runjobs("run_targets", function (index)
local target = targets[index]
if target then
_run(target)
end
end, {total = #targets,
comax = jobs,
isolate = true})
end
-- leave project directory
os.cd(oldir)
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/run/xmake.lua | --!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 xmake.lua
--
-- define task
task("run")
-- set category
set_category("action")
-- on run
on_run("main")
-- set menu
set_menu {
-- usage
usage = "xmake run|r [options] [target] [arguments]"
-- description
, description = "Run the project target."
-- xmake r
, shortname = 'r'
-- options
, options =
{
{'d', "debug", "k", nil , "Run and debug the given target." }
, {'a', "all", "k", nil , "Run all targets." }
, {'g', "group", "kv", nil , "Run all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake run -g test",
" xmake run -g test_*",
" xmake run --group=benchmark/*" }
, {'w', "workdir", "kv", nil , "Work directory of running targets, default is folder of targetfile",
"e.g.",
" xmake run -w .",
" xmake run --workdir=`pwd`" }
, {'j', "jobs", "kv", "1", "Set the number of parallel compilation jobs." }
, {nil, "detach", "k", nil, "Run targets in detached processes." }
, {}
, {nil, "target", "v", nil , "The target name. It will run all default targets if this parameter is not specified."
, values = function (complete, opt)
return import("private.utils.complete_helper.runable_targets")(complete, opt)
end }
, {nil, "arguments", "vs", nil , "The target arguments" }
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/clean/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.task")
import("core.project.rule")
import("core.project.config")
import("core.base.global")
import("core.project.project")
import("core.platform.platform")
import("private.action.clean.remove_files")
import("target.action.clean", {alias = "_do_clean_target"})
import("private.service.remote_build.action", {alias = "remote_build_action"})
-- on clean target
function _on_clean_target(target)
-- build target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_clean = r:script("clean")
if on_clean then
on_clean(target)
done = true
end
end
if done then return end
-- do clean
_do_clean_target(target)
end
-- clean the given target files
function _clean_target(target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- enter the environments of the target packages
local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
{
target:script("clean_before")
, function (target)
for _, r in ipairs(target:orderules()) do
local before_clean = r:script("clean_before")
if before_clean then
before_clean(target)
end
end
end
, target:script("clean", _on_clean_target)
, function (target)
for _, r in ipairs(target:orderules()) do
local after_clean = r:script("clean_after")
if after_clean then
after_clean(target)
end
end
end
, target:script("clean_after")
}
-- run the target scripts
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
end
-- clean the given targets
function _clean_targets(targets)
for _, target in ipairs(targets) do
_clean_target(target)
end
end
-- clean target
function _clean(targetname)
if targetname then
local target = project.target(targetname)
_clean_target(target)
else
_clean_targets(project.ordertargets())
end
end
-- clean configuration cache
function _clean_configs()
if option.get("all") then
-- we need to close it first after removing file lock
project.filelock():close()
remove_files(config.directory())
end
end
-- do clean for the third-party buildsystem
function _try_clean()
-- load config
config.load()
-- get the buildsystem tool
local configfile = nil
local tool = nil
local trybuild = config.get("trybuild")
if trybuild then
tool = import("private.action.trybuild." .. trybuild, {try = true, anonymous = true})
if tool then
configfile = tool.detect()
end
end
-- try cleaning it
if configfile and tool and trybuild then
tool.clean()
end
end
function main()
-- try cleaning it using third-party buildsystem if xmake.lua not exists
if not os.isfile(project.rootfile()) then
return _try_clean()
end
-- do action for remote?
if remote_build_action.enabled() then
return remote_build_action()
end
-- load config first
task.run("config", {require = false}, {disable_dump = true})
-- lock the whole project
project.lock()
-- get the target name
local targetname = option.get("target")
-- enter project directory
local oldir = os.cd(project.directory())
-- clean target
_clean(targetname)
-- unlock the whole project
project.unlock()
-- we must call it after unlocking project because it will remove project lockfile
_clean_configs()
-- leave project directory
os.cd(oldir)
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/clean/xmake.lua | --!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 xmake.lua
--
task("clean")
set_category("action")
on_run("main")
set_menu {
usage = "xmake clean|c [options] [target]"
, description = "Remove all binary and temporary files."
, shortname = 'c'
, options =
{
{'a', "all", "k", nil , "Clean all auto-generated files by xmake." }
, {}
, {nil, "target", "v", nil , "The target name. It will clean all default targets if this parameter is not specified."
, values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end }
}
}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/config/configfiles.lua | --!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 configfiles.lua
--
-- imports
import("core.base.option")
import("core.base.semver")
import("core.project.config")
import("core.project.depend")
import("core.project.project")
import("core.platform.platform")
import("lib.detect.find_tool")
-- get all configuration files
function _get_configfiles()
local configfiles = {}
for _, target in table.orderpairs(project.targets()) do
if target:is_enabled() then
-- get configuration files for target
local srcfiles, dstfiles, fileinfos = target:configfiles()
for idx, srcfile in ipairs(srcfiles) do
-- get destinate file and file info
local dstfile = dstfiles[idx]
local fileinfo = fileinfos[idx]
-- get source info
local srcinfo = configfiles[dstfile]
if not srcinfo then
srcinfo = {}
configfiles[dstfile] = srcinfo
end
-- save source file
if srcinfo.srcfile then
assert(path.absolute(srcinfo.srcfile) == path.absolute(srcfile), "file(%s) and file(%s) are writing a same file(%s)", srcfile, srcinfo.srcfile, dstfile)
else
srcinfo.srcfile = srcfile
srcinfo.fileinfo = fileinfo
end
-- we use first target to get dependfile path
-- @see https://github.com/xmake-io/xmake/issues/3321
if not srcinfo.dependfile then
srcinfo.dependfile = target:dependfile(srcfile)
end
-- always update?
local always_update = target:policy("build.always_update_configfiles")
if always_update == nil then
always_update = project.policy("build.always_update_configfiles")
end
srcinfo.always_update = always_update
-- save targets
srcinfo.targets = srcinfo.targets or {}
table.insert(srcinfo.targets, target)
end
end
end
return configfiles
end
-- get the builtin variables
function _get_builtinvars_target(target)
-- get version variables
local builtinvars = {}
local version, version_build = target:version()
if version then
builtinvars.VERSION = version
try {function ()
local v = semver.new(version)
if v then
builtinvars.VERSION_MAJOR = v:major()
builtinvars.VERSION_MINOR = v:minor()
builtinvars.VERSION_ALTER = v:patch()
end
end}
if version_build then
builtinvars.VERSION_BUILD = version_build
end
end
return builtinvars
end
-- get the git builtin variables
function _get_builtinvars_git(builtinvars)
local cmds =
{
GIT_TAG = {"describe", "--tags"},
GIT_TAG_LONG = {"describe", "--tags", "--long"},
GIT_BRANCH = {"rev-parse", "--abbrev-ref", "HEAD"},
GIT_COMMIT = {"rev-parse", "--short", "HEAD"},
GIT_COMMIT_LONG = {"rev-parse", "HEAD"},
GIT_COMMIT_DATE = {"log", "-1", "--date=format:%Y%m%d%H%M%S", "--format=%ad"}
}
for name, argv in pairs(cmds) do
builtinvars[name] = function ()
local result
local git = find_tool("git")
if git then
result = try {function ()
return os.iorunv(git.program, argv)
end}
end
if not result then
result = "none"
end
return result:trim()
end
end
end
-- get the global builtin variables
function _get_builtinvars_global()
local builtinvars = _g.builtinvars_global
if builtinvars == nil then
builtinvars =
{
arch = config.get("arch") or os.arch()
, plat = config.get("plat") or os.host()
, host = os.host()
, mode = config.get("mode") or "release"
, debug = is_mode("debug") and 1 or 0
, os = platform.os()
}
local builtinvars_upper = {}
for name, value in pairs(builtinvars) do
builtinvars_upper[name:upper()] = type(value) == "string" and value:upper() or value
end
table.join2(builtinvars, builtinvars_upper)
_get_builtinvars_git(builtinvars)
_g.builtinvars_global = builtinvars
end
return builtinvars
end
-- generate the configuration file
function _generate_configfile(srcfile, dstfile, fileinfo, targets)
-- trace
if option.get("verbose") then
cprint("${dim}generating %s to %s ..", srcfile, dstfile)
end
-- only copy it?
local generated = false
if fileinfo.onlycopy then
if os.mtime(srcfile) > os.mtime(dstfile) then
os.cp(srcfile, dstfile)
generated = true
end
else
-- generate to the temporary file first
local dstfile_tmp = path.join(os.tmpdir(), hash.uuid4(srcfile))
os.tryrm(dstfile_tmp)
os.cp(srcfile, dstfile_tmp)
-- get all variables
local variables = fileinfo.variables or {}
for _, target in ipairs(targets) do
-- get variables from the target
for name, value in pairs(target:get("configvar")) do
if variables[name] == nil then
value = table.unwrap(value)
variables[name] = value
variables["__extraconf_" .. name] = target:extraconf("configvar." .. name, value)
end
end
-- get variables from the target.options
for _, opt in ipairs(target:orderopts()) do
for name, value in pairs(opt:get("configvar")) do
if variables[name] == nil then
variables[name] = table.unwrap(value)
variables["__extraconf_" .. name] = opt:extraconf("configvar." .. name, value)
end
end
end
-- get the builtin variables from the target
for name, value in pairs(_get_builtinvars_target(target)) do
if type(value) == "function" then
value = value()
end
if variables[name] == nil then
variables[name] = value
end
end
end
-- get the global builtin variables
for name, value in pairs(_get_builtinvars_global()) do
if type(value) == "function" then
value = value()
end
if variables[name] == nil then
variables[name] = value
end
end
-- replace all variables
local pattern = fileinfo.pattern or "%${([^\n]-)}"
io.gsub(dstfile_tmp, "(" .. pattern .. ")", function(_, variable)
-- get variable name
variable = variable:trim()
-- is ${define variable}?
local isdefine = false
if variable:startswith("define ") then
variable = variable:split("%s")[2]
isdefine = true
end
-- is ${default variable xxx}?
local default = nil
local isdefault = false
if variable:startswith("default ") then
local varinfo = variable:split("%s")
variable = varinfo[2]
default = varinfo[3]
isdefault = true
assert(default ~= nil, "please set default value for variable(%s)", variable)
end
-- get variable value
local value = variables[variable]
local extraconf = variables["__extraconf_" .. variable]
if isdefine then
if value == nil then
value = ("/* #undef %s */"):format(variable)
elseif type(value) == "boolean" then
if value then
value = ("#define %s 1"):format(variable)
else
value = ("/* #define %s 0 */"):format(variable)
end
elseif type(value) == "number" then
value = ("#define %s %d"):format(variable, value)
elseif type(value) == "string" then
local quote = true
local escape = false
if extraconf then
-- disable to wrap quote, @see https://github.com/xmake-io/xmake/issues/1694
if extraconf.quote == false then
quote = false
end
-- escape path seperator when with quote, @see https://github.com/xmake-io/xmake/issues/1872
if quote and extraconf.escape then
escape = true
end
end
if quote then
if escape then
value = value:gsub("\\", "\\\\")
end
value = ("#define %s \"%s\""):format(variable, value)
else
value = ("#define %s %s"):format(variable, value)
end
else
raise("unknown variable(%s) type: %s", variable, type(value))
end
elseif isdefault then
if value == nil then
value = default
else
value = tostring(value)
end
else
assert(value ~= nil, "cannot get variable(%s) in %s.", variable, srcfile)
end
dprint(" > replace %s -> %s", variable, value)
if type(value) == "table" then
dprint("invalid variable value", value)
end
return value
end)
-- update file if the content is changed
if os.isfile(dstfile_tmp) then
if os.isfile(dstfile) then
if io.readfile(dstfile_tmp) ~= io.readfile(dstfile) then
os.cp(dstfile_tmp, dstfile)
generated = true
else
-- I forget why I added it here, but if we switch the option, mode,
-- this will cause the whole project to be rebuilt,
-- even if nothing in config.h has been changed.
--
--os.touch(dstfile, {mtime = os.time()})
end
else
os.cp(dstfile_tmp, dstfile)
generated = true
end
end
end
-- trace
cprint("generating %s ... %s", srcfile, generated and "${color.success}${text.success}" or "${color.success}cache")
end
-- the main entry function
function main(opt)
-- enter project directory
opt = opt or {}
local oldir = os.cd(project.directory())
-- generate all configuration files
local configfiles = _get_configfiles()
for dstfile, srcinfo in pairs(configfiles) do
depend.on_changed(function ()
_generate_configfile(srcinfo.srcfile, dstfile, srcinfo.fileinfo, srcinfo.targets)
end, {files = srcinfo.srcfile,
lastmtime = os.mtime(dstfile),
dependfile = srcinfo.dependfile,
changed = opt.force or srcinfo.always_update})
end
-- leave project directory
os.cd(oldir)
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/config/scangen.lua | --!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 scangen.lua
--
-- imports
import("core.project.config")
import("core.project.project")
import("core.language.language")
-- scan project and generate xmake.lua automaticlly if the project codes exist
function main()
-- trace
cprint("${color.warning}xmake.lua not found, scanning files ..")
-- scan source files for the current directory
local targetkinds = {}
local sourcefiles = {}
local sourcefiles_main = {}
for extension, sourcekind in pairs(language.extensions()) do
-- load language instance
local instance = language.load_sk(sourcekind)
-- get check main() script
local check_main = instance:get("check_main")
-- scan source files
local filecount = 0
for _, sourcefile in ipairs(os.files("*" .. extension)) do
if check_main and check_main(sourcefile) then
table.insert(sourcefiles_main, sourcefile)
else
table.insert(sourcefiles, sourcefile)
end
filecount = filecount + 1
end
-- add targetkinds
if filecount > 0 then
for targetkind, _ in pairs(instance:kinds()) do
targetkinds[targetkind] = true
end
end
end
sourcefiles = table.unique(sourcefiles)
sourcefiles_main = table.unique(sourcefiles_main)
-- project not found
if #sourcefiles == 0 and #sourcefiles_main == 0 then
raise("project not found!")
end
-- generate xmake.lua
local file = io.open("xmake.lua", "w")
if file then
-- get target name
local targetname = path.basename(os.curdir())
-- define static/binary target
if #sourcefiles > 0 then
-- get targetkind
local targetkind = nil
if targetkinds["static"] then
targetkind = "static"
elseif targetkinds["binary"] then
targetkind = "binary"
end
assert(targetkind, "unknown target kind!")
-- trace
cprint("target(${magenta}%s${clear}): %s", targetname, targetkind)
-- add rules
file:print("add_rules(\"mode.debug\", \"mode.release\")")
file:print("")
-- add target
file:print("target(\"%s\")", targetname)
file:print(" set_kind(\"%s\")", targetkind)
for _, sourcefile in ipairs(sourcefiles) do
cprint(" ${green}[+]: ${clear}%s", sourcefile)
file:print(" add_files(\"%s\")", sourcefile)
end
file:print("")
end
-- define binary targets
for _, sourcefile in ipairs(sourcefiles_main) do
-- trace
local name = path.basename(sourcefile)
if name == targetname then
name = name .. "1"
end
cprint("target(${magenta}%s${clear}): binary", name)
cprint(" ${green}[+]: ${clear}%s", sourcefile)
-- add target
file:print("target(\"%s\")", name)
file:print(" set_kind(\"binary\")")
file:print(" add_files(\"%s\")", sourcefile)
file:print("")
-- add deps
if #sourcefiles > 0 then
file:print(" add_deps(\"%s\")", targetname)
file:print("")
end
end
-- add FAQ
file:print(io.readfile(path.join(os.programdir(), "scripts", "faq.lua")))
-- exit file
file:close()
end
-- generate .gitignore if not exists
if not os.isfile(".gitignore") then
os.cp("$(programdir)/scripts/gitignore", ".gitignore")
end
-- trace
cprint("${color.success}xmake.lua generated, scan ok!")
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/config/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.global")
import("core.base.hashset")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("private.detect.find_platform")
import("core.cache.localcache")
import("scangen")
import("menuconf", {alias = "menuconf_show"})
import("configfiles", {alias = "generate_configfiles"})
import("private.action.require.register", {alias = "register_packages"})
import("private.action.require.install", {alias = "install_packages"})
import("private.service.remote_build.action", {alias = "remote_build_action"})
-- filter option
function _option_filter(name)
local options =
{
target = true
, file = true
, root = true
, yes = true
, quiet = true
, confirm = true
, project = true
, verbose = true
, diagnosis = true
, require = true
, export = true
, import = true
, check = true
, menu = true
}
return not options[name]
end
-- host changed?
function _host_changed()
return os.host() ~= config.read("host")
end
-- need check
function _need_check(changed)
-- clean?
if not changed then
changed = option.get("clean") or option.get("check")
end
-- check for all project files
local mtimes = project.mtimes()
if not changed then
local mtimes_prev = localcache.get("config", "mtimes")
if mtimes_prev then
for file, mtime in pairs(mtimes) do
-- modified? reconfig and rebuild it
local mtime_prev = mtimes_prev[file]
if not mtime_prev or mtime > mtime_prev then
changed = true
break
end
end
end
end
-- unfinished config/recheck
if not changed and localcache.get("config", "recheck") then
changed = true
end
-- Has xmake been updated? force to check config again
-- we need to clean the dirty config cache of the old version
if not changed then
if os.mtime(path.join(os.programdir(), "core", "main.lua")) > os.mtime(config.filepath()) then
changed = true
end
end
return changed
end
-- check target
function _check_target(target, checked_targets)
if not checked_targets[target:name()] then
checked_targets[target:name()] = target
for _, depname in ipairs(target:get("deps")) do
assert(depname ~= target:name(), "the target(%s) cannot depend self!", depname)
local deptarget = project.target(depname)
assert(deptarget, "unknown target(%s) for %s.deps!", depname, target:name())
_check_target(deptarget, checked_targets)
end
end
end
-- check targets
function _check_targets()
assert(not project.is_loaded(), "project and targets may have been loaded early!")
local checked_targets = {}
for _, target in pairs(project.targets()) do
_check_target(target, checked_targets)
end
end
-- check target toolchains
function _check_target_toolchains()
-- check toolchains configuration for all target in the current project
-- @note we must check targets after loading options
for _, target in pairs(project.targets()) do
if target:is_enabled() and (target:get("toolchains") or
not target:is_plat(config.get("plat")) or
not target:is_arch(config.get("arch"))) then
-- check platform toolchains first
-- `target/set_plat()` and target:toolchains() need it
target:platform():check()
-- check target toolchains next
local target_toolchains = target:get("toolchains")
if target_toolchains then
target_toolchains = hashset.from(table.wrap(target_toolchains))
for _, toolchain_inst in pairs(target:toolchains()) do
-- check toolchains for `target/set_toolchains()`
if not toolchain_inst:check() and target_toolchains:has(toolchain_inst:name()) then
raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
end
end
end
elseif not target:get("toolset") then
-- we only abort it when we know that toolchains of platform and target do not found
local toolchain_found
for _, toolchain_inst in pairs(target:toolchains()) do
if toolchain_inst:is_standalone() then
toolchain_found = true
end
end
assert(toolchain_found, "target(%s): toolchain not found!", target:name())
end
end
end
-- find default mode
function _find_default_mode()
local mode = config.mode()
if not mode then
mode = project.get("defaultmode")
if not mode then
mode = "release"
end
config.set("mode", mode)
end
return mode
end
-- check configs
function _check_configs()
-- check allowed modes
local mode = config.mode()
local allowed_modes = project.allowed_modes()
if allowed_modes then
if not allowed_modes:has(mode) then
local allowed_modes_str = table.concat(allowed_modes:to_array(), ", ")
raise("`%s` is not a valid complation mode for this project, please use one of %s", mode, allowed_modes_str)
end
end
-- check allowed plats
local plat = config.plat()
local allowed_plats = project.allowed_plats()
if allowed_plats then
if not allowed_plats:has(plat) then
local allowed_plats_str = table.concat(allowed_plats:to_array(), ", ")
raise("`%s` is not a valid platform for this project, please use one of %s", plat, allowed_plats_str)
end
end
-- check allowed archs
local arch = config.arch()
local allowed_archs = project.allowed_archs(config.plat())
if allowed_archs then
if not allowed_archs:has(arch) then
local allowed_archs_str = table.concat(allowed_archs:to_array(), ", ")
raise("`%s` is not a valid complation arch for this project, please use one of %s", arch, allowed_archs_str)
end
end
end
-- export configs
function _export_configs()
local exportfile = option.get("export")
if exportfile then
config.save(exportfile, {public = true})
end
end
function main(opt)
-- do action for remote?
if remote_build_action.enabled() then
return remote_build_action()
end
-- avoid running this task repeatly
opt = opt or {}
if _g.configured then return end
_g.configured = true
-- scan project and generate it if xmake.lua not exists
local autogen = false
local trybuild = option.get("trybuild")
if not os.isfile(project.rootfile()) and not trybuild then
autogen = utils.confirm({default = false, description = "xmake.lua not found, try generating it"})
if autogen then
scangen()
else
os.exit()
end
end
-- check the working directory
if not option.get("project") and not option.get("file") and -- no given project path
not localcache.get("project", "projectdir") and -- no cached project path
not localcache.get("project", "projectfile") and
os.isdir(os.projectdir()) then
if path.translate(os.projectdir()) ~= path.translate(os.workingdir()) then
wprint([[You are working in the project directory(%s) and you can also
force to build in current directory via run `xmake -P .`]], os.projectdir())
end
end
-- lock the whole project
project.lock()
-- enter menu config
local options_changed = false
if option.get("menu") then
options_changed = menuconf_show()
end
-- load the project configuration
--
-- priority: option > option_cache > global > option_default > config_check > project_check > config_cache
--
-- get the options
local options = nil
for name, value in pairs(option.options()) do
if _option_filter(name) then
options = options or {}
options[name] = value
end
end
-- merge options from the given import file
local importfile = option.get("import")
if importfile then
assert(os.isfile(importfile), "%s not found!", importfile)
-- we need to use readonly, @see https://github.com/xmake-io/xmake/issues/2278
local import_configs = io.load(importfile)
if import_configs then
for name, value in pairs(import_configs) do
options = options or {}
if options[name] == nil then
options[name] = value
end
end
end
end
-- override configuration from the options or cache
local options_history = {}
if not option.get("clean") and not autogen then
options_history = localcache.get("config", "options") or {}
options = options or options_history
end
for name, value in pairs(options) do
-- Is options changed by argument options?
options_changed = options_changed or options_history[name] ~= value
-- @note override it and mark as readonly (highest priority)
config.set(name, value, {readonly = true})
end
-- merge the cached configuration
--
-- @note we cannot load cache config when switching platform, arch ..
-- so we need known whether options have been changed
--
local configcache_loaded = false
if not options_changed and not option.get("clean") and not _host_changed() then
configcache_loaded = config.load()
end
-- merge the global configuration
for name, value in pairs(global.options()) do
if config.get(name) == nil then
config.set(name, value)
end
end
-- merge the default options
for name, value in pairs(option.defaults()) do
if _option_filter(name) and config.get(name) == nil then
config.set(name, value)
end
end
-- merge the project options after default options
for name, value in pairs(project.get("config")) do
value = table.unwrap(value)
assert(type(value) == "string" or type(value) == "boolean" or type(value) == "number", "set_config(%s): unsupported value type(%s)", name, type(value))
if not config.readonly(name) then
config.set(name, value)
end
end
-- find default mode
local mode = _find_default_mode()
assert(mode == config.mode())
-- find default platform and save to configuration
local plat, arch = find_platform({global = true})
assert(plat == config.plat())
assert(arch == config.arch())
-- load platform instance
local instance_plat = platform.load(plat, arch)
-- merge the checked configuration
local recheck = _need_check(options_changed or not configcache_loaded or autogen)
if recheck then
-- clear cached configuration
if option.get("clean") then
localcache.clear("config")
end
-- clear some local caches
localcache.clear("detect")
localcache.clear("option")
localcache.clear("package")
localcache.clear("toolchain")
localcache.clear("cxxmodules")
localcache.set("config", "recheck", true)
localcache.save()
-- check platform
instance_plat:check()
-- check project options
if not trybuild then
project.check_options()
end
end
-- translate the build directory
local buildir = config.get("buildir")
if buildir and path.is_absolute(buildir) then
config.set("buildir", path.relative(buildir, project.directory()), {readonly = true, force = true})
end
-- only config for building project using third-party buildsystem
if not trybuild then
-- check configs
_check_configs()
-- install and register packages
local require_enable = option.boolean(option.get("require"))
if (recheck or require_enable) then
if require_enable ~= false then
install_packages()
else
register_packages()
end
end
-- check target and ensure to load all targets, @note we must load targets after installing required packages,
-- otherwise has_package() will be invalid.
_check_targets()
-- check target toolchains
if recheck then
_check_target_toolchains()
end
-- load targets
project.load_targets({recheck = recheck})
-- update the config files
generate_configfiles({force = recheck})
end
-- dump config
if option.get("verbose") and not opt.disable_dump then
config.dump()
end
-- export configs
if option.get("export") then
_export_configs()
end
-- we need to save it and enable external working mode
-- if we configure the given project directory
--
-- @see https://github.com/xmake-io/xmake/issues/3342
--
local projectdir = option.get("project")
local projectfile = option.get("file")
if projectdir or projectfile then
localcache.set("project", "projectdir", projectdir)
localcache.set("project", "projectfile", projectfile)
localcache.save("project")
end
-- save options and config cache
localcache.set("config", "recheck", false)
localcache.set("config", "mtimes", project.mtimes())
config.save()
localcache.set("config", "options", options)
localcache.save("config")
-- unlock the whole project
project.unlock()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/config/menuconf.lua | --!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 menuconf.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.ui.log")
import("core.ui.rect")
import("core.ui.view")
import("core.ui.label")
import("core.ui.event")
import("core.ui.action")
import("core.ui.menuconf")
import("core.ui.mconfdialog")
import("core.ui.application")
import("private.detect.find_platform")
-- the app application
local app = application()
-- init app
function app:init()
-- init name
application.init(self, "app.config")
-- init background
self:background_set("blue")
-- insert menu config dialog
self:insert(self:mconfdialog())
-- load configs
self:load(not option.get("clean"))
end
-- get menu config dialog
function app:mconfdialog()
if not self._MCONFDIALOG then
local mconfdialog = mconfdialog:new("app.config.mconfdialog", rect{1, 1, self:width() - 1, self:height() - 1}, "menu config")
mconfdialog:action_set(action.ac_on_exit, function (v)
self:quit()
os.exit()
end)
mconfdialog:action_set(action.ac_on_save, function (v)
self:save()
self:quit()
end)
self._MCONFDIALOG = mconfdialog
end
return self._MCONFDIALOG
end
-- on resize
function app:on_resize()
self:mconfdialog():bounds_set(rect{1, 1, self:width() - 1, self:height() - 1})
application.on_resize(self)
end
-- filter option
function app:_filter_option(name)
local options =
{
target = true
, file = true
, root = true
, yes = true
, quiet = true
, confirm = true
, project = true
, verbose = true
, diagnosis = true
, require = true
, version = true
, help = true
, clean = true
, menu = true
, import = true
, export = true
, check = true
}
return not options[name] and not project.option(name)
end
-- get or make menu by category
function app:_menu_by_category(root, configs, menus, category)
-- is root?
if category == "." or category == "" then
return
end
-- attempt to get menu first
local menu = menus[category]
if not menu then
-- get config path
local parentdir = path.directory(category)
local config_path = path.join(root, parentdir == "." and "" or parentdir)
-- make a new menu
menu = menuconf.menu {name = category, path = config_path, description = path.basename(category), configs = {}}
menus[category] = menu
-- insert to the parent or root configs
local parent = self:_menu_by_category(root, configs, menus, parentdir)
table.insert(parent and parent.configs or configs, menu)
end
return menu
end
-- make configs by category
function app:_make_configs_by_category(root, options_by_category, cache, get_option_info)
-- make configs category
--
-- root category: "."
-- category path: "a", "a/b", "a/b/c" ...
--
local menus = {}
local configs = {}
local categories = table.orderkeys(options_by_category)
for _, category in ipairs(categories) do
-- get or make menu by category
local options = options_by_category[category]
local menu = self:_menu_by_category(root, configs, menus, category)
-- get sub-configs
local subconfigs = menu and menu.configs or configs
-- insert options to sub-configs
for _, opt in ipairs(options) do
-- get option info
local info = get_option_info(opt)
-- new value?
local newvalue = true
-- load value
local value = nil
if cache then
value = config.get(info.name)
if value ~= nil and info.kind == "choice" and info.values then
for idx, val in ipairs(info.values) do
if value == val then
value = idx
break
end
end
end
if value ~= nil then
newvalue = false
end
end
-- find the menu index in subconfigs
local menu_index = #subconfigs + 1
for idx, subconfig in ipairs(subconfigs) do
if subconfig.kind == "menu" then
menu_index = idx
break
end
end
-- get config path
local config_path = path.join(root, category == "." and "" or category)
-- insert config before all sub-menus
if info.kind == "string" then
table.insert(subconfigs, menu_index, menuconf.string {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, description = info.description, sourceinfo = info.sourceinfo})
elseif info.kind == "boolean" then
table.insert(subconfigs, menu_index, menuconf.boolean {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, description = info.description, sourceinfo = info.sourceinfo})
elseif info.kind == "choice" then
table.insert(subconfigs, menu_index, menuconf.choice {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, values = info.values, description = info.description, sourceinfo = info.sourceinfo})
end
end
end
-- done
return configs
end
-- get basic configs
function app:_basic_configs(cache)
-- get configs from the cache first
local configs = self._BASIC_CONFIGS
if configs then
return configs
end
-- get config menu
local menu = option.taskmenu("config")
-- merge options by category
local category = "."
local options = menu and menu.options or {}
local options_by_category = {}
local keys = table.orderkeys(options)
for _, key in ipairs(keys) do
local opt = options[key]
local name = opt[2] or opt[1]
if name and self:_filter_option(name) then
options_by_category[category] = options_by_category[category] or {}
table.insert(options_by_category[category], opt)
elseif opt.category then
category = opt.category
end
end
-- make configs by category
self._BASIC_CONFIGS = self:_make_configs_by_category("Basic Configuration", options_by_category, cache, function (opt)
-- get option
local name = opt[2] or opt[1]
local default = opt[4]
local kind = (opt[3] == "k" or type(default) == "boolean") and "boolean" or "string"
-- get default values
if name == "plat" then
default = find_platform()
elseif name == "arch" then
_, default = find_platform()
elseif name == "mode" then
default = project.get("defaultmode")
if not default then
default = "release"
end
end
-- choice option?
local values = opt.values
if values then
if type(values) == "function" then
values = values(false, {menuconf = true})
end
values = table.wrap(values)
for idx, value in ipairs(values) do
if default == value then
default = idx
break
end
end
end
if values then
kind = "choice"
end
-- get description
local description = {}
for i = 5, 64 do
local desc = opt[i]
if type(desc) == "function" then
desc = desc()
end
if type(desc) == "string" then
table.insert(description, desc)
elseif type(desc) == "table" then
table.join2(description, desc)
else
break
end
end
-- make option info
return {name = name, kind = kind, default = default, values = values, description = description}
end)
return self._BASIC_CONFIGS
end
-- get project configs
function app:_project_configs(cache)
-- get configs from the cache first
local configs = self._PROJECT_CONFIGS
if configs then
return configs
end
-- merge options by category
local options = project.options()
local options_by_category = {}
local keys = table.orderkeys(options)
for _, key in ipairs(keys) do
local opt = options[key]
if opt:showmenu() ~= false then
local category = "."
if opt:get("category") then category = table.unwrap(opt:get("category")) end
options_by_category[category] = options_by_category[category] or {}
table.insert(options_by_category[category], opt)
end
end
-- make configs by category
self._PROJECT_CONFIGS = self:_make_configs_by_category("Project Configuration", options_by_category, cache, function (opt)
-- the default value
local default = "auto"
if opt:get("default") ~= nil then
default = opt:get("default")
end
-- get kind
local kind = (type(default) == "string") and "string" or "boolean"
-- get description
local description = opt:description()
-- get source info
local sourceinfo = (opt:get("__sourceinfo_description") or {})[type(description) == "table" and description[1] or description]
-- choice option?
local values = opt:get("values")
if values then
kind = "choice"
values = table.wrap(values)
for idx, value in ipairs(values) do
if default == value then
default = idx
break
end
end
end
return {name = opt:name(), kind = kind, default = default, values = values, description = description, sourceinfo = sourceinfo}
end)
return self._PROJECT_CONFIGS
end
-- save the given configs
function app:_save_configs(configs)
local options = option.options()
for _, conf in pairs(configs) do
if conf.kind == "menu" then
self:_save_configs(conf.configs)
elseif not conf.new and (conf.kind == "boolean" or conf.kind == "string") then
options[conf.name] = conf.value
elseif not conf.new and (conf.kind == "choice") then
options[conf.name] = conf.values[conf.value]
end
end
end
-- Have configs been changed?
function app:_configs_changed()
return self._CONFIGS_CHANGED
end
-- load configs from options
function app:load(cache)
-- merge configuration from the given import file or cache
local loaded = false
local importfile = option.get("import")
if importfile and os.isfile(importfile) then
loaded = config.load(importfile)
elseif cache then
loaded = config.load()
end
-- clear configs first
self._BASIC_CONFIGS = nil
self._PROJECT_CONFIGS = nil
-- load configs
local configs = {}
table.insert(configs, menuconf.menu {description = "Basic Configuration", configs = self:_basic_configs(cache)})
table.insert(configs, menuconf.menu {description = "Project Configuration", configs = self:_project_configs(cache)})
self:mconfdialog():load(configs)
-- the previous config is only for loading menuconf, so clear config now
if loaded then
config.clear()
end
end
-- save configs to options
function app:save()
self:_save_configs(self:_basic_configs())
self:_save_configs(self:_project_configs())
self._CONFIGS_CHANGED = true
end
-- main entry
function main(...)
app:run(...)
return app:_configs_changed()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/config/xmake.lua | --!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 xmake.lua
--
function _plat_values(complete, opt)
import("core.platform.platform")
import("core.base.hashset")
import("core.project.project")
if not complete or not opt.arch then
local plats = try {function () return project.allowed_plats() end}
if plats then
return plats:to_array()
end
return platform.plats()
end
-- arch has given, find all supported platforms
local plats = {}
for _, plat in ipairs(platform.plats()) do
local archs = hashset.from(platform.archs(plat))
if archs:has(opt.arch) then
table.insert(plats, plat)
end
end
return plats
end
function _arch_values(complete, opt)
opt = opt or {}
if opt.helpmenu then
return
end
-- imports
import("core.project.project")
import("core.platform.platform")
import("core.base.hashset")
-- get all platforms
local plats = try {function () return project.allowed_plats() end}
if plats then
plats = plats:to_array()
end
plats = plats or platform.plats()
-- get all architectures
local archset = hashset.new()
for _, plat in ipairs(opt.plat and { opt.plat } or plats) do
local archs = try {function () return project.allowed_archs(plat) end}
if archs then
archs = archs:to_array()
end
if not archs then
archs = platform.archs(plat)
end
if archs then
for _, arch in ipairs(archs) do
archset:insert(arch)
end
end
end
return archset:to_array()
end
function _arch_description()
import("core.project.project")
import("core.platform.platform")
-- get all platforms
local plats = try {function () return project.allowed_plats() end}
if plats then
plats = plats:to_array()
end
plats = plats or platform.plats()
-- get all architectures
local description = {}
for i, plat in ipairs(plats) do
local archs = try {function () return project.allowed_archs(plat) end}
if archs then
archs = archs:to_array()
end
if not archs then
archs = platform.archs(plat)
end
if archs and #archs > 0 then
local desc = " - " .. plat .. ":"
for _, arch in ipairs(archs) do
desc = desc .. " " .. arch
end
table.insert(description, desc)
end
end
return description
end
function _mode_values(complete, opt)
import("core.project.project")
opt = opt or {}
local modes = try {function()
if opt.menuconf then
-- we cannot load target.mode in menuconf
local allowed_modes = project.allowed_modes()
if allowed_modes then
return allowed_modes:to_array()
end
else
return project.modes()
end
end}
if not modes then
modes = {"debug", "release"}
end
return modes
end
function _target_values(complete, opt)
return import("private.utils.complete_helper.targets")(complete, opt)
end
-- the toolchains is too much, so we just show all for menuconf and auto-complete mode.
-- @see https://github.com/xmake-io/xmake/issues/3436
--
function _toolchain_values(complete, opt)
opt = opt or {}
if complete or opt.menuconf then
import("core.tool.toolchain")
return toolchain.list()
end
end
function _project_menu_options()
import("core.project.menu")
return menu.options()
end
function _language_menu_options()
import("core.language.menu")
return menu.options("config")
end
function _platform_menu_options()
import("core.platform.menu")
return menu.options("config")
end
task("config")
set_category("action")
on_run("main")
set_menu {
usage = "xmake config|f [options] [target]",
description = "Configure the project.",
shortname = 'f',
options = {
{'c', "clean", "k", nil , "Clean the cached user configs and detection cache."},
{nil, "check", "k", nil , "Just ignore detection cache and force to check all, it will reserve the cached user configs."},
{nil, "export", "kv", nil , "Export the current configuration to the given file."
, " e.g."
, " - xmake f -m debug -xxx=y --export=build/config.txt"},
{nil, "import", "kv", nil , "Import configs from the given file."
, " e.g."
, " - xmake f -import=build/config.txt"},
{nil, "menu", "k", nil , "Configure project with a menu-driven user interface."},
{category = "."},
{'p', "plat", "kv", "auto" , "Compile for the given platform.", values = _plat_values},
{'a', "arch", "kv", "auto" , "Compile for the given architecture.", _arch_description, values = _arch_values},
{'m', "mode", "kv", "auto" , "Compile for the given mode.", values = _mode_values},
{'k', "kind", "kv", "static" , "Compile for the given target kind.", values = {"static", "shared", "binary"}},
{nil, "host", "kv", "$(host)" , "Set the current host environment."},
{nil, "policies", "kv", nil , "Set the project policies.",
" e.g.",
" - xmake f --policies=package.fetch_only",
" - xmake f --policies=package.precompiled:n,package.install_only"},
{category = "Package Configuration"},
{nil, "require", "kv", nil , "Require all dependent packages?", values = {"yes", "no"}},
{nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package."
, " e.g."
, " - xmake f --pkg_searchdirs=/dir1" .. path.envsep() .. "/dir2"},
{category = "Cross Complation Configuration"},
{nil, "cross", "kv", nil, "Set cross toolchains prefix"
, "e.g."
, " - i386-mingw32-"
, " - arm-linux-androideabi-"},
{nil, "target_os", "kv", nil, "Set target os only for cross-complation"},
{nil, "bin", "kv", nil, "Set cross toolchains bin directory"
, "e.g."
, " - sdk/bin (/arm-linux-gcc ..)"},
{nil, "sdk", "kv", nil, "Set cross SDK directory"
, "e.g."
, " - sdk/bin"
, " - sdk/lib"
, " - sdk/include"},
{nil, "toolchain", "kv", nil, "Set toolchain name"
, "e.g. "
, " - xmake f --toolchain=clang"
, " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx"
, " - run `xmake show -l toolchains` to get all toolchains"
, values = _toolchain_values},
{nil, "runtimes", "kv", nil, "Set the compiler runtime library."
, "e.g. "
, " - xmake f --runtimes=MTd"
, " - xmake f --runtimes=MT,c++_static"
, values = {"MT", "MTd", "MD", "MDd", -- only for msvc
"c++_static", "c++_shared", -- gcc/clang/android ndk
"stdc++_static", "stdc++_shared", -- gcc/clang
"gnustl_static", "gnustl_shared", -- only for old android ndk
"stlport_static", "stlport_shared"}}, -- only for old android ndk
_language_menu_options,
_platform_menu_options,
{category = "Other Configuration"},
{nil, "debugger", "kv", "auto" , "Set debugger"},
{nil, "ccache", "kv", true , "Enable or disable the c/c++ compiler cache."},
{nil, "ccachedir", "kv", nil , "Set the ccache directory."},
{nil, "trybuild", "kv", nil , "Enable try-build mode and set the third-party buildsystem tool.",
"e.g.",
" - xmake f --trybuild=auto; xmake",
" - xmake f --trybuild=autoconf -p android --ndk=xxx; xmake",
"",
"the third-party buildsystems:"
, values = {"auto", "make", "autoconf", "cmake", "scons", "meson", "bazel", "ninja", "msbuild", "xcodebuild", "ndkbuild", "xrepo"}},
{nil, "tryconfigs", "kv", nil , "Set the extra configurations of the third-party buildsystem for the try-build mode.",
"e.g.",
" - xmake f --trybuild=autoconf --tryconfigs='--enable-shared=no'"},
{'o', "buildir", "kv", "build" , "Set build directory."},
{},
{category = "Project Configuration"},
_project_menu_options}}
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/package/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
-- main entry
function main()
import(option.get("format") or "local")()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/package/xmake.lua | --!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 xmake.lua
--
task("package")
set_category("action")
on_run("main")
set_menu {
usage = "xmake package|p [options] [target]",
description = "Package target.",
shortname = 'p',
options = {
{'o', "outputdir", "kv", nil, "Set the output directory."},
{'a', "all", "k", nil, "Package all targets."},
{},
{'f', "format", "kv", "local", "Set the package format.",
values = {"oldpkg", "local", "remote"}},
{nil, "homepage", "kv", nil, "Set the homepage of package."},
{nil, "description","kv", nil, "Set the description of package."},
{nil, "url", "kv", nil, "Set the url of remote package."},
{nil, "version", "kv", nil, "Set the version of remote package."},
{nil, "shasum", "kv", nil, "Set the sha256 or commit of remote package."},
{},
{nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.",
values = function (complete, opt)
return import("private.utils.complete_helper.targets")(complete, opt)
end }
}
}
|
0 | repos/xmake/xmake/actions/package | repos/xmake/xmake/actions/package/remote/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.task")
import("core.project.rule")
import("core.project.config")
import("core.project.project")
import("core.base.bit")
-- get library deps
function _get_librarydeps(target)
local librarydeps = {}
for _, depname in ipairs(target:get("deps")) do
local dep = project.target(depname)
if not ((target:is_binary() or target:is_shared()) and dep:is_static()) then
table.insert(librarydeps, dep:name():lower())
end
end
return librarydeps
end
-- package remote
function _package_remote(target)
-- get the output directory
local packagedir = target:packagedir()
local packagename = target:name():lower()
-- generate xmake.lua
local file = io.open(path.join(packagedir, "xmake.lua"), "w")
if file then
local deps = _get_librarydeps(target)
file:print("package(\"%s\")", packagename)
if target:is_binary() then
file:print(" set_kind(\"binary\")")
elseif target:is_headeronly() then
file:print(" set_kind(\"library\", {headeronly = true})")
elseif target:is_moduleonly() then
file:print(" set_kind(\"library\", {moduleonly = true})")
end
local homepage = option.get("homepage")
if homepage then
file:print(" set_homepage(\"%s\")", homepage)
end
local description = option.get("description") or ("The " .. packagename .. " package")
file:print(" set_description(\"%s\")", description)
if target:license() then
file:print(" set_license(\"%s\")", target:license())
end
if #deps > 0 then
file:print(" add_deps(\"%s\")", table.concat(deps, "\", \""))
end
-- export packages as deps, @see https://github.com/xmake-io/xmake/issues/4202
local interface
if target:is_shared() then
interface = true
end
for _, pkg in ipairs(target:orderpkgs({interface = interface})) do
local requireconf_str
local requireconf = pkg:requireconf()
if requireconf then
local conf = table.clone(requireconf)
conf.alias = nil
requireconf_str = string.serialize(conf, {indent = false, strip = true})
end
if requireconf_str and requireconf_str ~= "{}" then
file:print(" add_deps(\"%s\", %s)", pkg:requirestr(), requireconf_str)
else
file:print(" add_deps(\"%s\")", pkg:requirestr())
end
end
file:print("")
local url = option.get("url") or "https://github.com/myrepo/foo.git"
local version = option.get("version") or target:version() and (target:version()) or "1.0"
local shasum = option.get("shasum") or "<shasum256 or gitcommit>"
file:print(" add_urls(\"%s\")", url)
file:print(" add_versions(\"%s\", \"%s\")", version, shasum)
file:print("")
file:print([[
on_install(function (package)
local configs = {}
if package:config("shared") then
configs.kind = "shared"
end
import("package.tools.xmake").install(package, configs)
end)
on_test(function (package)
-- TODO check includes and interfaces
-- assert(package:has_cfuncs("foo", {includes = "foo.h"})
end)]])
file:close()
end
-- show tips
print("package(%s): %s generated", packagename, packagedir)
end
-- package target
function _package_target(target)
if not target:is_phony() then
local scripts =
{
binary = _package_remote
, static = _package_remote
, shared = _package_remote
, headeronly = _package_remote
, moduleonly = _package_remote
}
local kind = target:kind()
local script = scripts[kind]
if script then
script(target)
end
end
end
-- package the given targets
function _package_targets(targets)
for _, target in ipairs(targets) do
_package_target(target)
end
end
-- main
function main()
-- lock the whole project
project.lock()
-- load config
config.load()
-- package the given target?
local targetname = option.get("target")
if targetname then
local target = project.target(targetname)
_package_targets(target:orderdeps())
_package_target(target)
else
-- package default or all targets
for _, target in ipairs(project.ordertargets()) do
if target:is_default() or option.get("all") then
_package_target(target)
end
end
end
-- unlock the whole project
project.unlock()
end
|
0 | repos/xmake/xmake/actions/package | repos/xmake/xmake/actions/package/oldpkg/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.task")
import("core.project.rule")
import("core.project.config")
import("core.project.project")
-- package library
function _package_library(target)
-- the output directory
local outputdir = option.get("outputdir") or config.buildir()
-- the target name
local targetname = target:name()
-- copy the library file to the output directory
if not target:is_headeronly() then
os.vcp(target:targetfile(), format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(target:targetfile())))
-- copy the symbol file to the output directory
local symbolfile = target:symbolfile()
if os.isfile(symbolfile) then
os.vcp(symbolfile, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(symbolfile)))
end
end
-- copy *.lib for shared/windows (*.dll) target
-- @see https://github.com/xmake-io/xmake/issues/787
if target:is_shared() and target:is_plat("windows", "mingw") then
local targetfile = target:targetfile()
local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib")
if os.isfile(targetfile_lib) then
os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname))
end
end
-- copy headers
local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/$(plat)/$(arch)/include", outputdir, targetname))
if srcheaders and dstheaders then
local i = 1
for _, srcheader in ipairs(srcheaders) do
local dstheader = dstheaders[i]
if dstheader then
os.vcp(srcheader, dstheader)
end
i = i + 1
end
end
-- make xmake.lua
local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w")
if file then
file:print("option(\"%s\")", targetname)
file:print(" set_showmenu(true)")
file:print(" set_category(\"package\")")
if not target:is_headeronly() then
file:print(" add_links(\"%s\")", target:basename())
file:write(" add_linkdirs(\"$(plat)/$(arch)/lib/$(mode)\")\n")
end
file:write(" add_includedirs(\"$(plat)/$(arch)/include\")\n")
local languages = target:get("languages")
if languages then
file:print(" set_languages(\"%s\")", table.concat(table.wrap(languages), "\", \""))
end
file:close()
end
end
-- do package target
function _do_package_target(target)
if not target:is_phony() then
local scripts =
{
binary = function (target) end
, static = _package_library
, shared = _package_library
, headeronly = _package_library
}
local kind = target:kind()
local script = scripts[kind]
if script then
script(target)
end
end
end
-- package target
function _on_package_target(target)
local done = false
for _, r in ipairs(target:orderules()) do
local on_package = r:script("package")
if on_package then
on_package(target)
done = true
end
end
if done then return end
_do_package_target(target)
end
-- package the given target
function _package_target(target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- enter project directory
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
{
target:script("package_before")
, function (target)
for _, r in ipairs(target:orderules()) do
local before_package = r:script("package_before")
if before_package then
before_package(target)
end
end
end
, target:script("package", _on_package_target)
, function (target)
for _, r in ipairs(target:orderules()) do
local after_package = r:script("package_after")
if after_package then
after_package(target)
end
end
end
, target:script("package_after")
}
-- package the target scripts
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
end
-- package the given targets
function _package_targets(targets)
for _, target in ipairs(targets) do
_package_target(target)
end
end
-- main
function main()
-- lock the whole project
project.lock()
-- get the target name
local targetname = option.get("target")
-- build it first
task.run("build", {target = targetname, all = option.get("all")})
-- package the given target?
if targetname then
local target = project.target(targetname)
_package_targets(target:orderdeps())
_package_target(target)
else
-- package default or all targets
for _, target in ipairs(project.ordertargets()) do
if target:is_default() or option.get("all") then
_package_target(target)
end
end
end
-- unlock the whole project
project.unlock()
end
|
0 | repos/xmake/xmake/actions/package | repos/xmake/xmake/actions/package/local/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.task")
import("core.project.rule")
import("core.project.config")
import("core.project.project")
import("core.base.bit")
import("rules.c++.modules.modules_support.compiler_support", {alias = "module_compiler_support", rootdir = os.programdir()})
import("rules.c++.modules.modules_support.builder", {alias = "module_builder", rootdir = os.programdir()})
-- get library deps
function _get_librarydeps(target)
local librarydeps = {}
for _, depname in ipairs(target:get("deps")) do
local dep = project.target(depname)
if not ((target:is_binary() or target:is_shared()) and dep:is_static()) then
table.insert(librarydeps, dep:name():lower())
end
end
return librarydeps
end
-- package binary
function _package_binary(target)
-- get the output directory
local packagedir = target:packagedir()
local packagename = target:name():lower()
local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin")
-- copy the binary file to the output directory
local targetfile = target:targetfile()
os.mkdir(binarydir)
os.vcp(targetfile, binarydir)
os.trycp(target:symbolfile(), binarydir)
-- generate xmake.lua
local file = io.open(path.join(packagedir, "xmake.lua"), "w")
if file then
local deps = _get_librarydeps(target)
file:print("package(\"%s\")", packagename)
local homepage = option.get("homepage")
if homepage then
file:print(" set_homepage(\"%s\")", homepage)
end
local description = option.get("description") or ("The " .. packagename .. " package")
file:print(" set_description(\"%s\")", description)
if target:license() then
file:print(" set_license(\"%s\")", target:license())
end
if #deps > 0 then
file:print(" add_deps(\"%s\")", table.concat(deps, "\", \""))
end
file:print("")
file:print([[
on_load(function (package)
package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode()))
end)
on_fetch(function (package)
return {program = path.join(package:installdir("bin"), "%s")}
end)]], #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "",
path.filename(targetfile))
file:close()
end
-- show tips
print("package(%s): %s generated", packagename, packagedir)
end
-- package library
function _package_library(target)
-- get the output directory
local packagedir = target:packagedir()
local packagename = target:name():lower()
local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin")
local librarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "lib")
local headerdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "include")
local modulesdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "modules")
-- copy the library file to the output directory
local targetfile = target:targetfile()
if target:is_shared() and target:is_plat("windows", "mingw") then
os.mkdir(binarydir)
os.vcp(targetfile, binarydir)
os.trycp(target:symbolfile(), binarydir)
local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib")
if os.isfile(targetfile_lib) then
os.mkdir(librarydir)
os.vcp(targetfile_lib, librarydir)
end
else
os.mkdir(librarydir)
if os.islink(targetfile) then
local targetfile_with_soname = os.readlink(targetfile)
if not path.is_absolute(targetfile_with_soname) then
targetfile_with_soname = path.join(target:targetdir(), targetfile_with_soname)
end
if os.islink(targetfile_with_soname) then
local targetfile_with_version = os.readlink(targetfile_with_soname)
if not path.is_absolute(targetfile_with_version) then
targetfile_with_version = path.join(target:targetdir(), targetfile_with_version)
end
os.vcp(targetfile_with_version, librarydir, {symlink = true, force = true})
end
os.vcp(targetfile_with_soname, librarydir, {symlink = true, force = true})
os.vcp(targetfile, librarydir, {symlink = true, force = true})
else
os.vcp(targetfile, librarydir)
end
os.trycp(target:symbolfile(), librarydir)
end
-- copy headers
local srcheaders, dstheaders = target:headerfiles(headerdir)
if srcheaders and dstheaders then
local i = 1
for _, srcheader in ipairs(srcheaders) do
local dstheader = dstheaders[i]
if dstheader then
os.vcp(srcheader, dstheader)
end
i = i + 1
end
end
-- copy modules
if target:data("cxx.has_modules") then
local modules = module_compiler_support.localcache():get2(target:name(), "c++.modules")
module_builder.generate_metadata(target, modules)
local sourcebatch = target:sourcebatches()["c++.build.modules.install"]
if sourcebatch and sourcebatch.sourcefiles then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local fileconfig = target:fileconfig(sourcefile)
local install = fileconfig and fileconfig.public or false
if install then
local modulehash = module_compiler_support.get_modulehash(target, sourcefile)
local prefixdir = path.join(modulesdir, modulehash)
os.vcp(sourcefile, path.join(prefixdir, path.filename(sourcefile)))
local metafile = module_compiler_support.get_metafile(target, sourcefile)
if os.exists(metafile) then
os.vcp(metafile, path.join(prefixdir, path.filename(metafile)))
end
end
end
end
end
-- generate xmake.lua
local file = io.open(path.join(packagedir, "xmake.lua"), "w")
if file then
local deps = _get_librarydeps(target)
file:print("package(\"%s\")", packagename)
local homepage = option.get("homepage")
if homepage then
file:print(" set_homepage(\"%s\")", homepage)
end
local description = option.get("description") or ("The " .. packagename .. " package")
file:print(" set_description(\"%s\")", description)
if target:license() then
file:print(" set_license(\"%s\")", target:license())
end
file:print("")
if #deps > 0 then
file:print(" add_deps(\"%s\")", table.concat(deps, "\", \""))
end
-- export packages as deps, @see https://github.com/xmake-io/xmake/issues/4202
local interface
if target:is_shared() then
interface = true
end
for _, pkg in ipairs(target:orderpkgs({interface = interface})) do
local requireconf_str
local requireconf = pkg:requireconf()
if requireconf then
local conf = table.clone(requireconf)
conf.alias = nil
requireconf_str = string.serialize(conf, {indent = false, strip = true})
end
if requireconf_str and requireconf_str ~= "{}" then
file:print(" add_deps(\"%s\", %s)", pkg:requirestr(), requireconf_str)
else
file:print(" add_deps(\"%s\")", pkg:requirestr())
end
end
file:print("")
file:print([[
add_configs("shared", {description = "Build shared library.", default = %s, type = "boolean", readonly = true})
on_load(function (package)
package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode()))
end)
on_fetch(function (package)
local result = {}
local libfiledir = (package:config("shared") and package:is_plat("windows", "mingw")) and "bin" or "lib"
result.links = "%s"
result.linkdirs = package:installdir("lib")
result.includedirs = package:installdir("include")
result.libfiles = path.join(package:installdir(libfiledir), "%s")
return result
end)]], target:is_shared() and "true" or "false",
target:linkname(),
path.filename(targetfile))
file:close()
end
-- show tips
print("package(%s): %s generated", packagename, packagedir)
end
-- package headeronly library
function _package_headeronly(target)
-- get the output directory
local packagedir = target:packagedir()
local packagename = target:name():lower()
local headerdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "include")
-- copy headers
local srcheaders, dstheaders = target:headerfiles(headerdir)
if srcheaders and dstheaders then
local i = 1
for _, srcheader in ipairs(srcheaders) do
local dstheader = dstheaders[i]
if dstheader then
os.vcp(srcheader, dstheader)
end
i = i + 1
end
end
-- generate xmake.lua
local file = io.open(path.join(packagedir, "xmake.lua"), "w")
if file then
local deps = _get_librarydeps(target)
file:print("package(\"%s\")", packagename)
local homepage = option.get("homepage")
if homepage then
file:print(" set_homepage(\"%s\")", homepage)
end
local description = option.get("description") or ("The " .. packagename .. " package")
file:print(" set_description(\"%s\")", description)
if target:license() then
file:print(" set_license(\"%s\")", target:license())
end
if #deps > 0 then
file:print(" add_deps(\"%s\")", table.concat(deps, "\", \""))
end
file:print("")
file:print([[
on_load(function (package)
package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode()))
end)
on_fetch(function (package)
local result = {}
result.includedirs = package:installdir("include")
return result
end)]])
file:close()
end
-- show tips
print("package(%s): %s generated", packagename, packagedir)
end
function _package_moduleonly(target)
-- get the output directory
local packagedir = target:packagedir()
local packagename = target:name():lower()
local headerdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "include")
local modulesdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "modules")
local modules = module_compiler_support.localcache():get2(target:name(), "c++.modules")
module_builder.generate_metadata(target, modules)
-- copy headers
local srcheaders, dstheaders = target:headerfiles(headerdir)
if srcheaders and dstheaders then
local i = 1
for _, srcheader in ipairs(srcheaders) do
local dstheader = dstheaders[i]
if dstheader then
os.vcp(srcheader, dstheader)
end
i = i + 1
end
end
-- copy modules
local sourcebatch = target:sourcebatches()["c++.build.modules.install"]
if sourcebatch and sourcebatch.sourcefiles then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local modulehash = module_compiler_support.get_modulehash(target, sourcefile)
local prefixdir = path.join(modulesdir, modulehash)
os.vcp(sourcefile, path.join(prefixdir, path.filename(sourcefile)))
local metafile = module_compiler_support.get_metafile(target, sourcefile)
if os.exists(metafile) then
os.vcp(metafile, path.join(prefixdir, path.filename(metafile)))
end
end
end
-- generate xmake.lua
local file = io.open(path.join(packagedir, "xmake.lua"), "w")
if file then
local deps = _get_librarydeps(target)
file:print("package(\"%s\")", packagename)
local homepage = option.get("homepage")
if homepage then
file:print(" set_homepage(\"%s\")", homepage)
end
local description = option.get("description") or ("The " .. packagename .. " package")
file:print(" set_description(\"%s\")", description)
if target:license() then
file:print(" set_license(\"%s\")", target:license())
end
if #deps > 0 then
file:print(" add_deps(\"%s\")", table.concat(deps, "\", \""))
end
file:print("")
file:print([[
on_load(function (package)
package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode()))
end)
on_fetch(function (package)
local result = {}
result.includedirs = package:installdir("include")
return result
end)]])
file:close()
end
-- show tips
print("package(%s): %s generated", packagename, packagedir)
end
-- do package target
function _do_package_target(target)
if not target:is_phony() then
local scripts =
{
binary = _package_binary
, static = _package_library
, shared = _package_library
, moduleonly = _package_moduleonly
, headeronly = _package_headeronly
}
local kind = target:kind()
local script = scripts[kind]
if script then
script(target)
end
end
end
-- package target
function _on_package_target(target)
local done = false
for _, r in ipairs(target:orderules()) do
local on_package = r:script("package")
if on_package then
on_package(target)
done = true
end
end
if done then return end
_do_package_target(target)
end
-- package the given target
function _package_target(target)
-- has been disabled?
if not target:is_enabled() then
return
end
-- enter project directory
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
{
target:script("package_before")
, function (target)
for _, r in ipairs(target:orderules()) do
local before_package = r:script("package_before")
if before_package then
before_package(target)
end
end
end
, target:script("package", _on_package_target)
, function (target)
for _, r in ipairs(target:orderules()) do
local after_package = r:script("package_after")
if after_package then
after_package(target)
end
end
end
, target:script("package_after")
}
-- package the target scripts
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
end
-- package the given targets
function _package_targets(targets)
for _, target in ipairs(targets) do
_package_target(target)
end
end
-- main
function main()
-- lock the whole project
project.lock()
-- get the target name
local targetname = option.get("target")
-- build it first
task.run("build", {target = targetname, all = option.get("all")})
-- package the given target?
if targetname then
local target = project.target(targetname)
_package_targets(target:orderdeps())
_package_target(target)
else
-- package default or all targets
for _, target in ipairs(project.ordertargets()) do
if target:is_default() or option.get("all") then
_package_target(target)
end
end
end
-- unlock the whole project
project.unlock()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/test/main.lua | --!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 main.lua
--
-- imports
import("core.base.option")
import("core.base.task")
import("core.project.config")
import("core.base.global")
import("core.project.project")
import("core.platform.platform")
import("core.theme.theme")
import("async.runjobs")
import("private.action.run.runenvs")
import("private.service.remote_build.action", {alias = "remote_build_action"})
import("actions.build.main", {rootdir = os.programdir(), alias = "build_action"})
import("utils.progress")
-- test target
function _do_test_target(target, opt)
opt = opt or {}
-- early out: results were computed during build
if opt.build_should_fail or opt.build_should_pass then
if opt.errors then
vprint(opt.errors)
end
return opt.passed
end
-- get run environments
local envs = opt.runenvs
if not envs then
local addenvs, setenvs = runenvs.make(target)
envs = runenvs.join(addenvs, setenvs)
end
-- run test
local outdata
local errors
local rundir = opt.rundir or target:rundir()
local targetfile = path.absolute(target:targetfile())
local runargs = table.wrap(opt.runargs or target:get("runargs"))
local autogendir = path.join(target:autogendir(), "tests")
local outfile = path.join(autogendir, opt.name .. ".out")
local errfile = path.join(autogendir, opt.name .. ".err")
os.tryrm(outfile)
os.tryrm(errfile)
os.mkdir(autogendir)
local run_timeout = opt.run_timeout
local ok, syserrors = os.execv(targetfile, runargs, {try = true, timeout = run_timeout,
curdir = rundir, envs = envs, stdout = outfile, stderr = errfile})
local outdata = os.isfile(outfile) and io.readfile(outfile) or ""
local errdata = os.isfile(errfile) and io.readfile(errfile) or ""
if outdata and #outdata > 0 then
opt.stdout = outdata
end
if errdata and #errdata > 0 then
opt.stderr = errdata
end
if opt.trim_output then
outdata = outdata:trim()
end
if ok ~= 0 then
if not errors or #errors == 0 then
if ok ~= nil then
if syserrors then
errors = string.format("run %s failed, exit code: %d, exit error: %s", opt.name, ok, syserrors)
else
errors = string.format("run %s failed, exit code: %d", opt.name, ok)
end
else
errors = string.format("run %s failed, exit error: %s", opt.name, syserrors and syserrors or "unknown reason")
end
end
end
os.tryrm(outfile)
os.tryrm(errfile)
if ok == 0 then
local passed
local pass_outputs = table.wrap(opt.pass_outputs)
local fail_outputs = table.wrap(opt.fail_outputs)
for _, pass_output in ipairs(pass_outputs) do
if opt.plain then
if pass_output == outdata then
passed = true
break
end
else
if outdata:match("^" .. pass_output .. "$") then
passed = true
break
end
end
end
for _, fail_output in ipairs(fail_outputs) do
if opt.plain then
if fail_output == outdata then
passed = false
if not errors or #errors == 0 then
errors = string.format("matched failed output: ${color.failure}%s${clear}", fail_output)
local actual_output = outdata
if not option.get("diagnosis") then
actual_output = outdata:sub(1, 64)
if #outdata > #actual_output then
actual_output = actual_output .. "..."
end
end
errors = errors .. ", actual output: ${color.failure}" .. actual_output
end
break
end
else
if outdata:match("^" .. fail_output .. "$") then
passed = false
if not errors or #errors == 0 then
errors = string.format("matched failed output: ${color.failure}%s${clear}", fail_output)
local actual_output = outdata
if not option.get("diagnosis") then
actual_output = outdata:sub(1, 64)
if #outdata > #actual_output then
actual_output = actual_output .. "..."
end
end
errors = errors .. ", actual output: ${color.failure}" .. actual_output
end
break
end
end
end
if passed == nil then
if #pass_outputs == 0 then
passed = true
else
passed = false
if not errors or #errors == 0 then
errors = string.format("not matched passed output: ${color.success}%s${clear}", table.concat(pass_outputs, ", "))
local actual_output = outdata
if not option.get("diagnosis") then
actual_output = outdata:sub(1, 64)
if #outdata > #actual_output then
actual_output = actual_output .. "..."
end
end
errors = errors .. ", actual output: ${color.failure}" .. actual_output
end
end
end
if errors and #errors > 0 then
opt.errors = errors
end
return passed
end
if errors and #errors > 0 then
opt.errors = errors
end
return false
end
-- test target
function _on_test_target(target, opt)
-- build target with rules
local passed
local done = false
for _, r in ipairs(target:orderules()) do
local on_test = r:script("test")
if on_test then
passed = on_test(target, opt)
done = true
end
end
if done then
return passed
end
-- do test
return _do_test_target(target, opt)
end
-- recursively add target envs
function _add_target_pkgenvs(target, targets_added)
if targets_added[target:name()] then
return
end
targets_added[target:name()] = true
os.addenvs(target:pkgenvs())
for _, dep in ipairs(target:orderdeps()) do
_add_target_pkgenvs(dep, targets_added)
end
end
-- run the given test
function _run_test(target, test)
-- enter the environments of the target packages
local oldenvs = os.getenvs()
_add_target_pkgenvs(target, {})
-- the target scripts
local scripts =
{
target:script("test_before")
, function (target, opt)
for _, r in ipairs(target:orderules()) do
local before_test = r:script("test_before")
if before_test then
before_test(target, opt)
end
end
end
, target:script("test", _on_test_target)
, function (target, opt)
for _, r in ipairs(target:orderules()) do
local after_test = r:script("test_after")
if after_test then
after_test(target, opt)
end
end
end
, target:script("test_after")
}
-- run the target scripts
local passed
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
local ok = script(target, test)
if i == 3 then
passed = ok
end
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
return passed
end
function _show_output(testinfo, kind)
local output = testinfo[kind]
if output then
if option.get("diagnosis") then
local target = testinfo.target
local autogendir = path.join(target:autogendir(), "tests")
local logfile = path.join(autogendir, testinfo.name .. "." .. kind .. ".log")
io.writefile(logfile, output)
print("%s: %s", kind, logfile)
elseif option.get("verbose") then
cprint("%s: %s", kind, output)
end
end
end
-- run tests
function _run_tests(tests)
local ordertests = {}
local maxwidth = 0
for name, testinfo in table.orderpairs(tests) do
table.insert(ordertests, testinfo)
if #testinfo.name > maxwidth then
maxwidth = #testinfo.name
end
end
if #ordertests == 0 then
print("nothing to test")
return
end
-- do test
local spent = os.mclock()
print("running tests ...")
local report = {passed = 0, total = #ordertests, tests = {}}
local jobs = tonumber(option.get("jobs")) or os.default_njob()
runjobs("run_tests", function (index, total, opt)
local testinfo = ordertests[index]
if testinfo then
progress.show(opt.progress, "running.test %s", testinfo.name)
local target = testinfo.target
testinfo.target = nil
local spent = os.mclock()
local passed = _run_test(target, testinfo)
spent = os.mclock() - spent
if passed then
report.passed = report.passed + 1
end
table.insert(report.tests, {
target = target,
name = testinfo.name,
passed = passed,
spent = spent,
stdout = testinfo.stdout,
stderr = testinfo.stderr,
errors = testinfo.errors})
-- stop it if be failed?
if not passed then
local stop = target:policy("test.stop_on_first_failure")
if stop == nil then
stop = project.policy("test.stop_on_first_failure")
end
if stop then
raise(errors)
end
end
end
end, {total = #ordertests,
comax = jobs,
isolate = true})
-- generate report
spent = os.mclock() - spent
local passed_rate = math.floor(report.passed * 100 / report.total)
print("")
print("report of tests:")
for idx, testinfo in ipairs(report.tests) do
local status_color = testinfo.passed and "${color.success}" or "${color.failure}"
local progress_format = status_color .. theme.get("text.build.progress_format") .. ":${clear} "
if option.get("verbose") or option.get("diagnosis") then
progress_format = progress_format .. "${dim}"
end
local padding = maxwidth - #testinfo.name
local progress_percent = math.floor(idx * 100 / #report.tests)
cprint(progress_format .. "%s%s .................................... " .. status_color .. "%s${clear} ${bright}%0.3fs",
progress_percent, testinfo.name, (" "):rep(padding), testinfo.passed and "passed" or "failed", testinfo.spent / 1000)
_show_output(testinfo, "stdout")
_show_output(testinfo, "stderr")
_show_output(testinfo, "errors")
end
cprint("${color.success}%d%%${clear} tests passed, ${color.failure}%d${clear} tests failed out of ${bright}%d${clear}, spent ${bright}%0.3fs",
passed_rate, report.total - report.passed, report.total, spent / 1000)
local return_zero = project.policy("test.return_zero_on_failure")
if not return_zero and report.passed < report.total then
raise()
end
end
-- try to build the given target
function _try_build_target(targetname)
local errors
local passed = try {
function ()
build_action.build_targets(targetname)
return true
end,
catch {
function (errs)
errors = tostring(errs)
end
}
}
return passed, errors
end
-- get tests, export this for the `project` plugin
function get_tests()
local tests = {}
local group_pattern = option.get("group")
if group_pattern then
group_pattern = "^" .. path.pattern(group_pattern) .. "$"
end
for _, target in ipairs(project.ordertargets()) do
for _, name in ipairs(target:get("tests")) do
local extra = target:extraconf("tests", name)
local testname = target:name() .. "/" .. name
local testinfo = {name = testname, target = target}
if extra then
table.join2(testinfo, extra)
if extra.files then
local target_new = target:clone()
local scriptdir = target:scriptdir()
target_new:name_set(target:name() .. "_" .. name)
for _, file in ipairs(extra.files) do
file = path.absolute(file, scriptdir)
file = path.relative(file, os.projectdir())
target_new:add("files", file, {defines = extra.defines,
cflags = extra.cflags,
cxflags = extra.cxflags,
cxxflags = extra.cxxflags,
undefines = extra.undefines,
languages = extra.languages})
project.target_add(target_new)
end
for _, file in ipairs(extra.remove_files) do
file = path.absolute(file, scriptdir)
file = path.relative(file, os.projectdir())
target_new:remove("files", file)
end
if extra.kind then
target_new:set("kind", kind)
end
if extra.frameworks then
target_new:add("frameworks", extra.frameworks)
end
if extra.links then
target_new:add("links", extra.links)
end
if extra.syslinks then
target_new:add("syslinks", extra.syslinks)
end
if extra.packages then
target_new:add("packages", extra.packages)
end
testinfo.target = target_new
end
end
if not testinfo.group then
testinfo.group = target:get("group")
end
local group = testinfo.group
if (not group_pattern) or (group_pattern and group and group:match(group_pattern)) then
tests[testname] = testinfo
end
end
end
return tests
end
function main()
-- do action for remote?
if remote_build_action.enabled() then
return remote_build_action()
end
-- load config first
task.run("config", {}, {disable_dump = true})
-- lock the whole project
project.lock()
-- get tests
local tests = get_tests()
local test_patterns = option.get("tests")
if test_patterns then
local tests_new = {}
for _, pattern in ipairs(test_patterns) do
pattern = "^" .. path.pattern(pattern) .. "$"
for name, testinfo in pairs(tests) do
if name:match(pattern) then
tests_new[name] = testinfo
end
end
end
tests = tests_new
end
-- enter project directory
local oldir = os.cd(project.directory())
-- build targets with the given tests first
local targetnames = {}
for _, testinfo in table.orderpairs(tests) do
local targetname = testinfo.target:name()
if testinfo.build_should_pass then
local passed, errors = _try_build_target(targetname)
testinfo.passed = passed
testinfo.errors = errors
elseif testinfo.build_should_fail then
local built, _ = _try_build_target(targetname)
testinfo.passed = not built
if built then
testinfo.errors = "Build succeeded when failure was expected"
end
else
table.insert(targetnames, targetname)
end
end
if #targetnames > 0 then
build_action.build_targets(targetnames)
end
-- run tests
_run_tests(tests)
-- leave project directory
os.cd(oldir)
-- unlock the whole project
project.unlock()
end
|
0 | repos/xmake/xmake/actions | repos/xmake/xmake/actions/test/xmake.lua | --!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 xmake.lua
--
task("test")
set_category("action")
on_run("main")
set_menu {
usage = "xmake test [options] [target] [arguments]",
description = "Run the project tests.",
options = {
{'g', "group", "kv", nil , "Run all tests of the given group. It support path pattern matching.",
"e.g.",
" xmake test -g test",
" xmake test -g test_*",
" xmake test --group=benchmark/*" },
{'w', "workdir", "kv", nil , "Work directory of running targets, default is folder of targetfile",
"e.g.",
" xmake test -w .",
" xmake test --workdir=`pwd`" },
{'j', "jobs", "kv", tostring(os.default_njob()), "Set the number of parallel compilation jobs." },
{'r', "rebuild", "k", nil , "Rebuild the target." },
{},
{nil, "tests", "vs", nil , "The test names. It support pattern matching.",
"e.g.",
" xmake test foo",
" xmake test */foo",
" xmake test targetname/*" }
}
}
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/masm32/xmake.lua | --!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 xmake.lua
--
toolchain("masm32")
set_kind("standalone")
set_homepage("https://www.masm32.com")
set_description("The MASM32 SDK")
set_toolset("as", "ml.exe")
set_toolset("mrc", "rc.exe")
set_toolset("ld", "link.exe")
set_toolset("sh", "link.exe")
set_toolset("ar", "link.exe")
on_check(function (toolchain)
import("lib.detect.find_tool")
import("detect.sdks.find_masm32")
local masm32 = find_masm32()
if masm32 and masm32.sdkdir and masm32.bindir and find_tool("ml.exe", {program = path.join(masm32.bindir, "ml.exe")}) then
toolchain:config_set("sdkdir", masm32.sdkdir)
toolchain:config_set("bindir", masm32.bindir)
toolchain:configs_save()
return true
end
end)
on_load(function (toolchain)
toolchain:arch_set("x86")
local sdkdir = toolchain:sdkdir()
if sdkdir then
toolchain:add("includedirs", path.join(sdkdir, "include"))
toolchain:add("linkdirs", path.join(sdkdir, "lib"))
end
toolchain:add("asflags", "/coff")
toolchain:add("syslinks", "user32", "kernel32")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/hdk/load.lua | --!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 load.lua
--
-- imports
import("core.base.hashset")
import("core.project.config")
-- get target
function _get_target(arch)
local targets = {
["armeabi-v7a"] = "armv7-linux-ohos"
, ["arm64-v8a"] = "aarch64-linux-ohos"
, ["x86_64"] = "x86_64-linux-ohos"
}
assert(targets[arch], "unknown arch(%s) for harmony!", arch)
return targets[arch]
end
-- load hdk toolchain
function main(toolchain)
-- get gcc toolchain bin directory
local gcc_toolchain_bin = nil
local gcc_toolchain = toolchain:config("gcc_toolchain")
if gcc_toolchain then
gcc_toolchain_bin = path.join(gcc_toolchain, "bin")
end
-- get sdk directory
local sdkdir = toolchain:sdkdir()
-- set toolset
toolchain:set("toolset", "cc", "clang")
toolchain:set("toolset", "cxx", "clang++")
toolchain:set("toolset", "cpp", "clang -E")
toolchain:set("toolset", "as", "clang")
toolchain:set("toolset", "ld", "clang++", "clang")
toolchain:set("toolset", "sh", "clang++", "clang")
toolchain:set("toolset", "ar", "llvm-ar")
toolchain:set("toolset", "ranlib", "llvm-ranlib")
toolchain:set("toolset", "strip", "llvm-strip")
-- add hdk target
local arch = toolchain:arch()
local target = _get_target(arch)
toolchain:add("cxflags", "--target=" .. target)
toolchain:add("asflags", "--target=" .. target)
toolchain:add("ldflags", "--target=" .. target)
toolchain:add("shflags", "--target=" .. target)
-- add sysroot
local sysroot = toolchain:config("sysroot")
if sysroot then
toolchain:add("cxflags", "--sysroot=" .. sysroot)
toolchain:add("asflags", "--sysroot=" .. sysroot)
toolchain:add("ldflags", "--sysroot=" .. sysroot)
toolchain:add("shflags", "--sysroot=" .. sysroot)
end
-- init cxflags for the target kind: binary
toolchain:add("binary.cxflags", "-fPIE", "-pie")
-- add "-fPIE -pie" to ldflags
toolchain:add("ldflags", "-fPIE")
toolchain:add("ldflags", "-pie")
-- add some builtin flags
toolchain:add("cxflags", "-D__MUSL__")
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/hdk/xmake.lua | --!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 xmake.lua
--
-- harmony sdk toolchain
toolchain("hdk")
set_kind("standalone")
set_homepage("https://developer.harmonyos.com/cn/develop/")
set_description("Harmony SDK")
set_runtimes("c++_static", "c++_shared")
on_check("check")
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/hdk/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_hdk")
-- check the hdk toolchain
function _check_hdk(toolchain)
local hdk
for _, package in ipairs(toolchain:packages()) do
local installdir = package:installdir()
if installdir and os.isdir(installdir) then
hdk = find_hdk(installdir, {force = true, verbose = option.get("verbose")})
if hdk then
break
end
end
end
if not hdk then
hdk = find_hdk(toolchain:config("hdk") or config.get("sdk"), {force = true, verbose = true})
end
if hdk then
toolchain:config_set("sdkdir", hdk.sdkdir)
toolchain:config_set("bindir", hdk.bindir)
toolchain:config_set("sysroot", hdk.sysroot)
toolchain:configs_save()
return true
else
--[[TODO we also need to add this tips when use remote hdk toolchain
-- failed
cprint("${bright color.error}please run:")
cprint(" - xmake config --hdk=xxx")
cprint("or - xmake global --hdk=xxx")
raise()]]
end
end
function main(toolchain)
return _check_hdk(toolchain)
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-18/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("18")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/dpcpp/load.lua | --!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 load.lua
--
-- imports
import("core.base.option")
import("core.project.config")
-- main entry
function main(toolchain)
-- set toolset
toolchain:set("toolset", "cc", "dpcpp")
toolchain:set("toolset", "cxx", "dpcpp")
toolchain:set("toolset", "ld", "dpcpp")
toolchain:set("toolset", "sh", "dpcpp")
toolchain:set("toolset", "ar", "ar")
toolchain:set("toolset", "strip", "strip")
toolchain:set("toolset", "as", "dpcpp")
-- add march flags
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/dpcpp/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("dpcpp")
-- set homepage
set_homepage("https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html")
set_description("Intel LLVM C++ Compiler for data parallel programming model based on Khronos SYCL")
-- mark as standalone toolchain
set_kind("standalone")
-- check toolchain
on_check("check")
-- on load
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/dpcpp/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_icxenv")
import("lib.detect.find_tool")
-- main entry
function main(toolchain)
local icxenv = toolchain:config("icxenv")
if icxenv then
return true
end
icxenv = find_icxenv()
if icxenv then
local tool = find_tool("dpcpp", {force = true, paths = icxenv.bindir})
if tool then
cprint("checking for Intel Data Parallel C++ (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("icxenv", icxenv)
toolchain:config_set("bindir", icxenv.bindir)
toolchain:configs_save()
return true
end
return true
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-20/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("20")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/nim/xmake.lua | --!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 xmake.lua
--
toolchain("nim")
set_homepage("https://nim-lang.org/")
set_description("Nim Programming Language Compiler")
on_check(function (toolchain)
import("lib.detect.find_tool")
local paths = {}
for _, package in ipairs(toolchain:packages()) do
local envs = package:envs()
if envs then
table.join2(paths, envs.PATH)
end
end
local nim = get_config("nc")
if not nim then
nim = find_tool("nim", {force = true, paths = paths})
if nim and nim.program then
nim = nim.program
end
end
if nim then
toolchain:config_set("nim", nim)
toolchain:configs_save()
return true
end
end)
on_load(function (toolchain)
local nim = toolchain:config("nim") or "nim"
toolchain:set("toolset", "nc", "$(env NC)", nim)
toolchain:set("toolset", "ncld", "$(env NC)", nim)
toolchain:set("toolset", "ncsh", "$(env NC)", nim)
toolchain:set("toolset", "ncar", "$(env NC)", nim)
if toolchain:is_plat("windows") then
toolchain:set("ncflags", "--cc:vcc")
local msvc = import("core.tool.toolchain", {anonymous = true}).load("msvc", {plat = toolchain:plat(), arch = toolchain:arch()})
for name, value in pairs(msvc:get("runenvs")) do
toolchain:add("runenvs", name, value)
end
end
toolchain:set("ncshflags", "")
toolchain:set("ncldflags", "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/tinycc/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("tinycc")
set_kind("standalone")
set_homepage("https://bellard.org/tcc/")
set_description("Tiny C Compiler")
on_check(function (toolchain)
import("core.project.config")
import("lib.detect.find_tool")
local paths = {toolchain:bindir()}
local sdkdir = toolchain:sdkdir()
if sdkdir then
table.insert(paths, path.join(sdkdir, "bin"))
end
for _, package in ipairs(toolchain:packages()) do
local installdir = package:installdir()
if installdir then
table.insert(paths, path.join(installdir, "bin"))
end
end
local tcc = find_tool("tcc", {paths = paths, force = true})
if tcc then
toolchain:config_set("tcc", tcc.program)
if os.isfile(tcc.program) then
toolchain:config_set("bindir", path.directory(tcc.program))
end
toolchain:configs_save()
return true
end
end)
on_load(function (toolchain)
import("core.project.config")
-- add march flags
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("mxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
-- add toolset
local tcc = toolchain:config("tcc") or "tcc"
toolchain:add("toolset", "cc", tcc)
toolchain:add("toolset", "ld", tcc)
toolchain:add("toolset", "sh", tcc)
toolchain:add("toolset", "ar", tcc)
-- add includedirs and linkdirs
for _, package in ipairs(toolchain:packages()) do
local installdir = package:installdir()
if installdir then
toolchain:add("sysincludedirs", path.join(installdir, "include"))
toolchain:add("linkdirs", path.join(installdir, "lib"))
end
end
local sdkdir = toolchain:sdkdir()
if sdkdir and os.isdir(sdkdir) then
local includedir = path.join(sdkdir, "include")
if os.isdir(includedir) then
toolchain:add("sysincludedirs", includedir)
end
local libdir = path.join(sdkdir, "lib")
if os.isdir(libdir) then
toolchain:add("linkdirs", libdir)
end
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/armcc/xmake.lua | --!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 xmake.lua
--
toolchain("armcc")
set_homepage("https://www2.keil.com/mdk5/compiler/5")
set_description("ARM Compiler Version 5 of Keil MDK")
set_kind("cross")
set_toolset("cc", "armcc")
set_toolset("cxx", "armcc")
set_toolset("ld", "armlink")
set_toolset("ar", "armar")
set_toolset("as", "armasm")
on_check(function (toolchain)
import("lib.detect.find_tool")
import("detect.sdks.find_mdk")
local mdk = find_mdk()
if mdk and mdk.sdkdir_armcc and find_tool("armcc") then
toolchain:config_set("sdkdir", mdk.sdkdir_armcc)
toolchain:configs_save()
return true
end
end)
on_load(function (toolchain)
local arch = toolchain:arch()
if arch then
toolchain:add("cxflags", "--cpu " .. arch)
toolchain:add("asflags", "--cpu " .. arch)
toolchain:add("ldflags", "--cpu " .. arch)
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/icc/load.lua | --!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 load.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("detect.sdks.find_vstudio")
-- add the given vs environment
function _add_vsenv(toolchain, name, curenvs)
-- get vcvars
local vcvars = toolchain:config("vcvars")
if not vcvars then
return
end
-- get the paths for the vs environment
local new = vcvars[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unpack(path.splitenv(new)))
end
end
-- add the given icl environment
function _add_iclenv(toolchain, name, curenvs)
-- get iclvarsall
local iclvarsall = toolchain:config("varsall")
if not iclvarsall then
return
end
-- get icl environment for the current arch
local arch = toolchain:arch()
local iclenv = iclvarsall[arch] or {}
-- get the paths for the icl environment
local new = iclenv[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unpack(path.splitenv(new)))
end
end
-- load intel on windows
function _load_intel_on_windows(toolchain)
-- set toolset
if toolchain:is_plat("windows") then
toolchain:set("toolset", "cc", "icl.exe")
toolchain:set("toolset", "cxx", "icl.exe")
toolchain:set("toolset", "mrc", "rc.exe")
if toolchain:is_arch("x64") then
toolchain:set("toolset", "as", "ml64.exe")
else
toolchain:set("toolset", "as", "ml.exe")
end
toolchain:set("toolset", "ld", "link.exe")
toolchain:set("toolset", "sh", "link.exe")
toolchain:set("toolset", "ar", "link.exe")
else
toolchain:set("toolset", "cc", "icc")
toolchain:set("toolset", "cxx", "icpc", "icc")
toolchain:set("toolset", "ld", "icpc", "icc")
toolchain:set("toolset", "sh", "icpc", "icc")
toolchain:set("toolset", "ar", "ar")
toolchain:set("toolset", "strip", "strip")
toolchain:set("toolset", "as", "icc")
end
-- add vs/icl environments
local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"}
local curenvs = os.getenvs()
for _, name in ipairs(expect_vars) do
_add_vsenv(toolchain, name, curenvs)
_add_iclenv(toolchain, name, curenvs)
end
for _, name in ipairs(find_vstudio.get_vcvars()) do
if not table.contains(expect_vars, name:upper()) then
_add_vsenv(toolchain, name, curenvs)
end
end
end
-- load intel on linux
function _load_intel_on_linux(toolchain)
-- set toolset
toolchain:set("toolset", "cc", "icc")
toolchain:set("toolset", "cxx", "icpc", "icc")
toolchain:set("toolset", "ld", "icpc", "icc")
toolchain:set("toolset", "sh", "icpc", "icc")
toolchain:set("toolset", "ar", "ar")
toolchain:set("toolset", "strip", "strip")
toolchain:set("toolset", "as", "icc")
-- add march flags
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
-- get icc environments
local iccenv = toolchain:config("iccenv")
if iccenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
toolchain:add("runenvs", ldname, iccenv.libdir)
end
end
-- main entry
function main(toolchain)
if is_host("windows") then
return _load_intel_on_windows(toolchain)
else
return _load_intel_on_linux(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/icc/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("icc")
-- set homepage
set_homepage("https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html")
set_description("Intel C/C++ Compiler")
-- mark as standalone toolchain
set_kind("standalone")
-- check toolchain
on_check("check")
-- on load
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/icc/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_iccenv")
import("detect.sdks.find_vstudio")
import("lib.detect.find_tool")
-- attempt to check vs environment
function _check_vsenv(toolchain)
-- has been checked?
local vs = toolchain:config("vs") or config.get("vs")
if vs then
vs = tostring(vs)
end
local vcvars = toolchain:config("vcvars")
if vs and vcvars then
return vs
end
-- find vstudio
local vs_toolset = toolchain:config("vs_toolset") or config.get("vs_toolset")
local vs_sdkver = toolchain:config("vs_sdkver") or config.get("vs_sdkver")
local vstudio = find_vstudio({vcvars_ver = vs_toolset, sdkver = vs_sdkver})
if vstudio then
-- make order vsver
local vsvers = {}
for vsver, _ in pairs(vstudio) do
if not vs or vs ~= vsver then
table.insert(vsvers, vsver)
end
end
table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end)
if vs then
table.insert(vsvers, 1, vs)
end
-- get vcvarsall
for _, vsver in ipairs(vsvers) do
local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {}
local vcvars = vcvarsall[toolchain:arch()]
if vcvars and vcvars.PATH and vcvars.INCLUDE and vcvars.LIB then
-- save vcvars
toolchain:config_set("vcvars", vcvars)
toolchain:config_set("vcarchs", table.orderkeys(vcvarsall))
toolchain:config_set("vs_toolset", vcvars.VCToolsVersion)
toolchain:config_set("vs_sdkver", vcvars.WindowsSDKVersion)
-- check compiler
local program
local paths
local pathenv = os.getenv("PATH")
if pathenv then
paths = path.splitenv(pathenv)
end
local tool = find_tool("cl.exe", {version = true, force = true, paths = paths, envs = vcvars})
if tool then
program = tool.program
end
if program then
return vsver, tool
end
end
end
end
end
-- check the visual studio
function _check_vstudio(toolchain)
local vs = _check_vsenv(toolchain)
if vs then
if toolchain:is_global() then
config.set("vs", vs, {force = true, readonly = true})
end
toolchain:config_set("vs", vs)
toolchain:configs_save()
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs)
else
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", toolchain:arch())
end
return vs
end
-- check intel on windows
function _check_intel_on_windows(toolchain)
-- have been checked?
local varsall = toolchain:config("varsall")
if varsall then
return true
end
-- find intel c/c++ compiler environment
local iccenv = find_iccenv()
if iccenv and iccenv.iclvars then
local iclvarsall = iccenv.iclvars
local iclenv = iclvarsall[toolchain:arch()]
if iclenv and iclenv.PATH and iclenv.INCLUDE and iclenv.LIB then
local tool = find_tool("icl.exe", {force = true, envs = iclenv, version = true})
if tool then
cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("varsall", iclvarsall)
toolchain:configs_save()
return _check_vstudio(toolchain)
end
end
end
end
-- check intel on linux
function _check_intel_on_linux(toolchain)
local iccenv = toolchain:config("iccenv")
if iccenv then
return true
end
iccenv = find_iccenv()
if iccenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
local tool = find_tool("icc", {force = true, envs = {[ldname] = iccenv.libdir}, paths = iccenv.bindir})
if tool then
cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("iccenv", iccenv)
toolchain:config_set("bindir", iccenv.bindir)
toolchain:configs_save()
return true
end
return true
end
end
-- main entry
function main(toolchain)
if is_host("windows") then
return _check_intel_on_windows(toolchain)
else
return _check_intel_on_linux(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-12/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("12")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/yasm/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("yasm")
-- set homepage
set_homepage("https://yasm.tortall.net/")
set_description("The Yasm Modular Assembler")
-- set toolset
set_toolset("as", "yasm")
-- on load
on_load(function (toolchain)
if toolchain:is_plat("macosx") then
toolchain:add("yasm.asflags", "-f", toolchain:is_arch("x86_64") and "macho64" or "macho32")
elseif toolchain:is_plat("linux", "bsd") then
toolchain:add("yasm.asflags", "-f", toolchain:is_arch("x86_64") and "elf64" or "elf32")
elseif toolchain:is_plat("windows", "mingw", "msys", "cygwin") then
toolchain:add("yasm.asflags", "-f", toolchain:is_arch("x86_64", "x64") and "win64" or "win32")
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/dmd/xmake.lua | --!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 xmake.lua
--
toolchain("dmd")
set_homepage("https://dlang.org/")
set_description("D Programming Language Compiler")
on_check(function (toolchain)
import("lib.detect.find_tool")
if find_tool("dmd") then
return true
end
end)
on_load(function (toolchain)
local cross = toolchain:cross() or ""
toolchain:add("toolset", "dc", "dmd")
toolchain:add("toolset", "dcld", "dmd")
toolchain:add("toolset", "dcsh", "dmd")
toolchain:add("toolset", "dcar", "dmd")
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
toolchain:add("dcflags", march or "")
toolchain:add("dcshflags", march or "")
toolchain:add("dcldflags", march or "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gfortran/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("gfortran")
-- set homepage
set_homepage("https://fortran.com/")
set_description("GNU Fortran Programming Language Compiler")
-- set toolset
set_toolset("fc", "$(env FC)", "gfortran")
set_toolset("fcld", "$(env FC)", "gfortran")
set_toolset("fcsh", "$(env FC)", "gfortran")
-- on load
on_load(function (toolchain)
local march = toolchain:is_arch("x86_64", "x64", "arm64") and "-m64" or "-m32"
toolchain:add("fcflags", march)
toolchain:add("fcshflags", march)
toolchain:add("fcldflags", march)
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ldc/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("ldc")
set_homepage("https://github.com/ldc-developers/ldc")
set_description("The LLVM-based D Compiler.")
on_check("check")
on_load(function (toolchain)
toolchain:add("toolset", "dc", "ldc2")
toolchain:add("toolset", "dcld", "ldc2")
toolchain:add("toolset", "dcsh", "ldc2")
toolchain:add("toolset", "dcar", "ldc2")
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
toolchain:add("dcflags", march or "")
toolchain:add("dcshflags", march or "")
toolchain:add("dcldflags", march or "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ldc/check.lua | --!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_tool")
import("detect.sdks.find_cross_toolchain")
function main(toolchain)
-- we attempt to find ldc2 in $PATH
if find_tool("ldc2") then
return true
end
-- we need to find ldc2 in the given toolchain sdk directory
local sdkdir = toolchain:sdkdir()
local bindir = toolchain:bindir()
local cross = toolchain:cross()
if not sdkdir and not bindir and not cross then
return
end
-- find cross toolchain
local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross})
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("cross toolchain not found!")
end
return cross_toolchain
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ifort/load.lua | --!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 load.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("detect.sdks.find_vstudio")
-- add the given vs environment
function _add_vsenv(toolchain, name, curenvs)
-- get vcvars
local vcvars = toolchain:config("vcvars")
if not vcvars then
return
end
-- get the paths for the vs environment
local new = vcvars[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unpack(path.splitenv(new)))
end
end
-- add the given ifort environment
function _add_ifortenv(toolchain, name, curenvs)
-- get ifortvarsall
local ifortvarsall = toolchain:config("varsall")
if not ifortvarsall then
return
end
-- get ifort environment for the current arch
local arch = toolchain:arch()
local ifortenv = ifortvarsall[arch] or {}
-- get the paths for the ifort environment
local new = ifortenv[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unpack(path.splitenv(new)))
end
end
-- load intel on windows
function _load_intel_on_windows(toolchain)
-- set toolset
toolchain:set("toolset", "fc", "ifort.exe")
toolchain:set("toolset", "mrc", "rc.exe")
if toolchain:is_arch("x64") then
toolchain:set("toolset", "as", "ml64.exe")
else
toolchain:set("toolset", "as", "ml.exe")
end
toolchain:set("toolset", "fcld", "ifort.exe")
toolchain:set("toolset", "fcsh", "ifort.exe")
toolchain:set("toolset", "ar", "link.exe")
-- add ifort and vs environments
local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"}
local curenvs = os.getenvs()
for _, name in ipairs(expect_vars) do
_add_vsenv(toolchain, name, curenvs)
_add_ifortenv(toolchain, name, curenvs)
end
for _, name in ipairs(find_vstudio.get_vcvars()) do
if not table.contains(expect_vars, name:upper()) then
_add_vsenv(toolchain, name, curenvs)
end
end
end
-- load intel on linux
function _load_intel_on_linux(toolchain)
-- set toolset
toolchain:set("toolset", "fc", "ifort")
toolchain:set("toolset", "fcld", "ifort")
toolchain:set("toolset", "fcsh", "ifort")
toolchain:set("toolset", "ar", "ar")
-- add march flags
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("fcflags", march)
toolchain:add("fcldflags", march)
toolchain:add("fcshflags", march)
end
-- get ifort environments
local ifortenv = toolchain:config("ifortenv")
if ifortenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
toolchain:add("runenvs", ldname, ifortenv.libdir)
end
end
-- main entry
function main(toolchain)
if is_host("windows") then
return _load_intel_on_windows(toolchain)
else
return _load_intel_on_linux(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ifort/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("ifort")
-- set homepage
set_homepage("https://software.intel.com/content/www/us/en/develop/tools/compilers/fortran-compilers.html")
set_description("Intel Fortran Compiler")
-- mark as standalone toolchain
set_kind("standalone")
-- check toolchain
on_check("check")
-- on load
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ifort/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_ifortenv")
import("detect.sdks.find_vstudio")
import("lib.detect.find_tool")
-- attempt to check vs environment
function _check_vsenv(toolchain)
-- has been checked?
local vs = toolchain:config("vs") or config.get("vs")
if vs then
vs = tostring(vs)
end
local vcvars = toolchain:config("vcvars")
if vs and vcvars then
return vs
end
-- find vstudio
local vs_toolset = toolchain:config("vs_toolset") or config.get("vs_toolset")
local vs_sdkver = toolchain:config("vs_sdkver") or config.get("vs_sdkver")
local vstudio = find_vstudio({vcvars_ver = vs_toolset, sdkver = vs_sdkver})
if vstudio then
-- make order vsver
local vsvers = {}
for vsver, _ in pairs(vstudio) do
if not vs or vs ~= vsver then
table.insert(vsvers, vsver)
end
end
table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end)
if vs then
table.insert(vsvers, 1, vs)
end
-- get vcvarsall
for _, vsver in ipairs(vsvers) do
local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {}
local vcvars = vcvarsall[toolchain:arch()]
if vcvars and vcvars.PATH and vcvars.INCLUDE and vcvars.LIB then
-- save vcvars
toolchain:config_set("vcvars", vcvars)
toolchain:config_set("vcarchs", table.orderkeys(vcvarsall))
toolchain:config_set("vs_toolset", vcvars.VCToolsVersion)
toolchain:config_set("vs_sdkver", vcvars.WindowsSDKVersion)
-- check compiler
local program
local paths
local pathenv = os.getenv("PATH")
if pathenv then
paths = path.splitenv(pathenv)
end
local tool = find_tool("cl.exe", {version = true, force = true, paths = paths, envs = vcvars})
if tool then
program = tool.program
end
if program then
return vsver, tool
end
end
end
end
end
-- check the visual studio
function _check_vstudio(toolchain)
local vs = _check_vsenv(toolchain)
if vs then
if toolchain:is_global() then
config.set("vs", vs, {force = true, readonly = true})
end
toolchain:config_set("vs", vs)
toolchain:configs_save()
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs)
else
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", toolchain:arch())
end
return vs
end
-- check intel on windows
function _check_intel_on_windows(toolchain)
-- have been checked?
local varsall = toolchain:config("varsall")
if varsall then
return true
end
-- find intel fortran compiler environment
local ifortenv = find_ifortenv()
if ifortenv and ifortenv.ifortvars then
local ifortvarsall = ifortenv.ifortvars
local ifortenv = ifortvarsall[toolchain:arch()]
if ifortenv and ifortenv.PATH and ifortenv.INCLUDE and ifortenv.LIB then
local tool = find_tool("ifort.exe", {force = true, envs = ifortenv, version = true})
if tool then
cprint("checking for Intel Fortran Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("varsall", ifortvarsall)
toolchain:configs_save()
return _check_vstudio(toolchain)
end
end
end
end
-- check intel on linux
function _check_intel_on_linux(toolchain)
local ifortenv = toolchain:config("ifortenv")
if ifortenv then
return true
end
ifortenv = find_ifortenv()
if ifortenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
local tool = find_tool("ifort", {force = true, envs = {[ldname] = ifortenv.libdir}, paths = ifortenv.bindir})
if tool then
cprint("checking for Intel Fortran Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("ifortenv", ifortenv)
toolchain:config_set("bindir", ifortenv.bindir)
toolchain:configs_save()
return true
end
return true
end
end
-- main entry
function main(toolchain)
if is_host("windows") then
return _check_intel_on_windows(toolchain)
else
return _check_intel_on_linux(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/muslcc/xmake.lua | --!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 xmake.lua
--
toolchain("muslcc")
set_homepage("https://musl.cc/")
set_description("The musl-based cross-compilation toolchains")
-- mark as cross-compilation toolchain
set_kind("cross")
on_load(function (toolchain)
-- load basic configuration of cross toolchain
toolchain:load_cross_toolchain()
-- add flags for arch
if toolchain:is_arch("arm") then
toolchain:add("cxflags", "-march=armv7-a", "-msoft-float", {force = true})
toolchain:add("ldflags", "-march=armv7-a", "-msoft-float", {force = true})
end
toolchain:add("syslinks", "gcc", "c")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/mingw/xmake.lua | --!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 xmake.lua
--
toolchain("mingw")
set_kind("standalone")
set_homepage("http://www.mingw.org/")
set_description("Minimalist GNU for Windows")
set_runtimes("stdc++_static", "stdc++_shared")
on_check("check")
on_load(function (toolchain)
import("core.project.config")
-- get cross
local cross
if toolchain:is_arch("x86_64", "x64") then
cross = "x86_64-w64-mingw32-"
elseif toolchain:is_arch("i386", "x86", "i686") then
cross = "i686-w64-mingw32-"
elseif toolchain:is_arch("arm64", "aarch64") then
cross = "aarch64-w64-mingw32-"
elseif toolchain:is_arch("armv7", "arm.*") then
cross = "armv7-w64-mingw32-"
else
cross = toolchain:cross() or ""
end
-- add bin search library for loading some dependent .dll files windows
local bindir = toolchain:bindir()
if bindir and is_host("windows") then
toolchain:add("runenvs", "PATH", bindir)
end
-- set toolset
if is_host("windows") and bindir then
-- @note we uses bin/ar.exe instead of bin/cross-gcc-ar.exe, @see https://github.com/xmake-io/xmake/issues/807#issuecomment-635779210
toolchain:add("toolset", "ar", path.join(bindir, "ar"))
toolchain:add("toolset", "strip", path.join(bindir, "strip"))
toolchain:add("toolset", "ranlib", path.join(bindir, "ranlib"))
toolchain:add("toolset", "objcopy", path.join(bindir, "objcopy"))
end
toolchain:add("toolset", "cc", cross .. "gcc")
toolchain:add("toolset", "cxx", cross .. "g++", cross .. "gcc")
toolchain:add("toolset", "cpp", cross .. "gcc -E")
toolchain:add("toolset", "as", cross .. "gcc")
toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc")
toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc")
toolchain:add("toolset", "ar", cross .. "ar")
toolchain:add("toolset", "strip", cross .. "strip")
toolchain:add("toolset", "ranlib", cross .. "ranlib")
toolchain:add("toolset", "objcopy", cross .. "objcopy")
toolchain:add("toolset", "mrc", cross .. "windres")
if is_host("windows") and bindir then
-- we use bin/gcc.exe if cross not found
-- @see https://github.com/xmake-io/xmake/issues/977#issuecomment-704863677
toolchain:add("toolset", "cc", path.join(bindir, "gcc"))
toolchain:add("toolset", "cxx", path.join(bindir, "g++"), path.join(bindir, "gcc"))
toolchain:add("toolset", "cpp", path.join(bindir, "gcc -E"))
toolchain:add("toolset", "as", path.join(bindir, "gcc"))
toolchain:add("toolset", "ld", path.join(bindir, "g++"), path.join(bindir, "gcc"))
toolchain:add("toolset", "sh", path.join(bindir, "g++"), path.join(bindir, "gcc"))
toolchain:add("toolset", "mrc", path.join(bindir, "windres"))
end
-- init flags for architecture
local archflags = nil
local arch = toolchain:arch()
if arch == "x86_64" then archflags = "-m64"
elseif arch == "i386" then archflags = "-m32"
end
if archflags then
toolchain:add("cxflags", archflags)
toolchain:add("asflags", archflags)
toolchain:add("ldflags", archflags)
toolchain:add("shflags", archflags)
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/mingw/check.lua | --!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("detect.sdks.find_mingw")
-- check the mingw toolchain
function main(toolchain)
local mingw
for _, package in ipairs(toolchain:packages()) do
local installdir = package:installdir()
if installdir and os.isdir(installdir) then
mingw = find_mingw(installdir, {verbose = true, cross = toolchain:cross()})
if mingw then
break
end
end
end
if not mingw then
mingw = find_mingw(toolchain:config("mingw") or config.get("mingw"), {verbose = true, bindir = toolchain:bindir(), cross = toolchain:cross()})
end
if mingw then
toolchain:config_set("mingw", mingw.sdkdir)
toolchain:config_set("cross", mingw.cross)
toolchain:config_set("bindir", mingw.bindir)
toolchain:configs_save()
return true
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-11/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("11")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc/xmake.lua | --!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 xmake.lua
--
-- define toolchain
function toolchain_gcc(version)
local suffix = ""
if version then
suffix = suffix .. "-" .. version
end
toolchain("gcc" .. suffix)
set_kind("standalone")
set_homepage("https://gcc.gnu.org/")
set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or ""))
set_runtimes("stdc++_static", "stdc++_shared")
set_toolset("cc", "gcc" .. suffix)
set_toolset("cxx", "gcc" .. suffix, "g++" .. suffix)
set_toolset("ld", "g++" .. suffix, "gcc" .. suffix)
set_toolset("sh", "g++" .. suffix, "gcc" .. suffix)
set_toolset("ar", "ar")
set_toolset("strip", "strip")
set_toolset("objcopy", "objcopy")
set_toolset("ranlib", "ranlib")
set_toolset("mm", "gcc" .. suffix)
set_toolset("mxx", "gcc" .. suffix, "g++" .. suffix)
set_toolset("as", "gcc" .. suffix)
on_check(function (toolchain)
return import("lib.detect.find_tool")("gcc" .. suffix)
end)
on_load(function (toolchain)
-- add march flags
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("mxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
end)
end
toolchain_gcc()
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/cuda/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("cuda")
-- set homepage
set_homepage("https://developer.nvidia.com/cuda-toolkit")
set_description("CUDA Toolkit (nvcc, nvc, nvc++, nvfortran)")
-- set toolset
set_toolset("cc", "nvc")
set_toolset("cxx", "nvc++")
set_toolset("fc", "nvfortran")
set_toolset("fcld", "nvfortran")
set_toolset("fcsh", "nvfortran")
set_toolset("ld", "nvc++", "nvc")
set_toolset("sh", "nvc++", "nvc")
set_toolset("cu", "nvcc", "clang")
set_toolset("culd", "nvcc")
set_toolset("cu-ccbin", "$(env CXX)", "$(env CC)")
-- bind msvc environments, because nvcc will call cl.exe
on_load(function (toolchain)
if toolchain:is_plat("windows") then
import("core.tool.toolchain", {alias = "core_toolchain"})
local msvc = core_toolchain.load("msvc", {plat = toolchain:plat(), arch = toolchain:arch()})
for name, values in pairs(msvc:runenvs()) do
toolchain:add("runenvs", name, values)
end
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-13/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("13")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-10/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("10")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/circle/xmake.lua | --!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 xmake.lua
--
toolchain("circle")
set_homepage("https://www.circle-lang.org/")
set_description("A new C++20 compiler. It's written from scratch and designed for easy extension.")
set_kind("standalone")
set_toolset("cc", "circle")
set_toolset("cxx", "circle")
set_toolset("ld", "circle")
set_toolset("sh", "circle")
set_toolset("ar", "ar")
set_toolset("strip", "strip")
on_check(function (toolchain)
return import("lib.detect.find_tool")("circle")
end)
on_load(function (toolchain)
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/cross/load.lua | --!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 load.lua
--
-- imports
import("core.project.config")
-- load the cross toolchain
function main(toolchain)
local cross = toolchain:cross() or ""
-- add toolset
--
-- @note we use add/toolset for cross toolchain, because user maybe use set_toolset to modify them
-- @see https://github.com/xmake-io/xmake/issues/1024
--
toolchain:add("toolset", "cc", cross .. "gcc", cross .. "clang")
toolchain:add("toolset", "cxx", cross .. "gcc", cross .. "clang", cross .. "g++", cross .. "clang++")
toolchain:add("toolset", "cpp", cross .. "gcc -E", cross .. "clang -E")
toolchain:add("toolset", "as", cross .. "gcc", cross .. "clang")
toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang")
toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang")
-- need gcc-ar for lto, @see https://github.com/xmake-io/xmake/issues/5015
toolchain:add("toolset", "ar", cross .. "gcc-ar", cross .. "ar")
toolchain:add("toolset", "ranlib", cross .. "gcc-ranlib", cross .. "ranlib")
toolchain:add("toolset", "strip", cross .. "strip")
-- add bin search library for loading some dependent .dll files windows
local bindir = toolchain:bindir()
if bindir and is_host("windows") then
toolchain:add("runenvs", "PATH", bindir)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/cross/xmake.lua | --!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 xmake.lua
--
toolchain("cross")
set_description("Common cross compilation toolchain")
set_kind("cross")
on_check("check")
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/cross/check.lua | --!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("detect.sdks.find_cross_toolchain")
-- check the cross toolchain
function main(toolchain)
-- is cross?
local sdkdir = toolchain:sdkdir()
local bindir = toolchain:bindir()
local cross = toolchain:cross()
if not sdkdir and not bindir and not cross and not toolchain:packages() then
return
end
-- find cross toolchain from external envirnoment
local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross})
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, {cross = cross})
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()
-- init default target os
if not config.get("target_os") then
config.set("target_os", "linux", {readonly = true, force = true})
end
else
raise("cross toolchain not found!")
end
return cross_toolchain
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-13/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("13")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-19/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("19")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/icx/load.lua | --!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 load.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("detect.sdks.find_vstudio")
-- add the given vs environment
function _add_vsenv(toolchain, name, curenvs)
-- get vcvars
local vcvars = toolchain:config("vcvars")
if not vcvars then
return
end
-- get the paths for the vs environment
local new = vcvars[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unpack(path.splitenv(new)))
end
end
-- add the given icx environment
function _add_icxenv(toolchain, name, curenvs)
-- get icxvarsall
local icxvarsall = toolchain:config("varsall")
if not icxvarsall then
return
end
-- get icx environment for the current arch
local arch = toolchain:arch()
local icxenv = icxvarsall[arch] or {}
-- get the paths for the icx environment
local new = icxenv[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unpack(path.splitenv(new)))
end
end
-- load intel on windows
function _load_intel_on_windows(toolchain)
-- set toolset
if toolchain:is_plat("windows") then
toolchain:set("toolset", "cc", "icx.exe")
toolchain:set("toolset", "cxx", "icx.exe")
toolchain:set("toolset", "mrc", "rc.exe")
if toolchain:is_arch("x64") then
toolchain:set("toolset", "as", "ml64.exe")
else
toolchain:set("toolset", "as", "ml.exe")
end
toolchain:set("toolset", "ld", "link.exe")
toolchain:set("toolset", "sh", "link.exe")
toolchain:set("toolset", "ar", "link.exe")
else
toolchain:set("toolset", "cc", "icx")
toolchain:set("toolset", "cxx", "icpx", "icx")
toolchain:set("toolset", "ld", "icpx", "icx")
toolchain:set("toolset", "sh", "icpx", "icx")
toolchain:set("toolset", "ar", "ar")
toolchain:set("toolset", "strip", "strip")
toolchain:set("toolset", "as", "icx")
end
-- add vs/icx environments
local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"}
local curenvs = os.getenvs()
for _, name in ipairs(expect_vars) do
_add_vsenv(toolchain, name, curenvs)
_add_icxenv(toolchain, name, curenvs)
end
for _, name in ipairs(find_vstudio.get_vcvars()) do
if not table.contains(expect_vars, name:upper()) then
_add_vsenv(toolchain, name, curenvs)
end
end
end
-- load intel on linux
function _load_intel_on_linux(toolchain)
-- set toolset
toolchain:set("toolset", "cc", "icx")
toolchain:set("toolset", "cxx", "icpx", "icx")
toolchain:set("toolset", "ld", "icpx", "icx")
toolchain:set("toolset", "sh", "icpx", "icx")
toolchain:set("toolset", "ar", "ar")
toolchain:set("toolset", "strip", "strip")
toolchain:set("toolset", "as", "icx")
-- add march flags
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
-- get icx environments
local icxenv = toolchain:config("icxenv")
if icxenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
toolchain:add("runenvs", ldname, icxenv.libdir)
end
end
-- main entry
function main(toolchain)
if is_host("windows") then
return _load_intel_on_windows(toolchain)
else
return _load_intel_on_linux(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/icx/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("icx")
-- set homepage
set_homepage("https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html")
set_description("Intel LLVM C/C++ Compiler")
-- mark as standalone toolchain
set_kind("standalone")
-- check toolchain
on_check("check")
-- on load
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/icx/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_icxenv")
import("detect.sdks.find_vstudio")
import("lib.detect.find_tool")
-- attempt to check vs environment
function _check_vsenv(toolchain)
-- has been checked?
local vs = toolchain:config("vs") or config.get("vs")
if vs then
vs = tostring(vs)
end
local vcvars = toolchain:config("vcvars")
if vs and vcvars then
return vs
end
-- find vstudio
local vs_toolset = toolchain:config("vs_toolset") or config.get("vs_toolset")
local vs_sdkver = toolchain:config("vs_sdkver") or config.get("vs_sdkver")
local vstudio = find_vstudio({vcvars_ver = vs_toolset, sdkver = vs_sdkver})
if vstudio then
-- make order vsver
local vsvers = {}
for vsver, _ in pairs(vstudio) do
if not vs or vs ~= vsver then
table.insert(vsvers, vsver)
end
end
table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end)
if vs then
table.insert(vsvers, 1, vs)
end
-- get vcvarsall
for _, vsver in ipairs(vsvers) do
local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {}
local vcvars = vcvarsall[toolchain:arch()]
if vcvars and vcvars.PATH and vcvars.INCLUDE and vcvars.LIB then
-- save vcvars
toolchain:config_set("vcvars", vcvars)
toolchain:config_set("vcarchs", table.orderkeys(vcvarsall))
toolchain:config_set("vs_toolset", vcvars.VCToolsVersion)
toolchain:config_set("vs_sdkver", vcvars.WindowsSDKVersion)
-- check compiler
local program
local paths
local pathenv = os.getenv("PATH")
if pathenv then
paths = path.splitenv(pathenv)
end
local tool = find_tool("cl.exe", {version = true, force = true, paths = paths, envs = vcvars})
if tool then
program = tool.program
end
if program then
return vsver, tool
end
end
end
end
end
-- check the visual studio
function _check_vstudio(toolchain)
local vs = _check_vsenv(toolchain)
if vs then
if toolchain:is_global() then
config.set("vs", vs, {force = true, readonly = true})
end
toolchain:config_set("vs", vs)
toolchain:configs_save()
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs)
else
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", toolchain:arch())
end
return vs
end
-- check intel on windows
function _check_intel_on_windows(toolchain)
-- have been checked?
local varsall = toolchain:config("varsall")
if varsall then
return true
end
-- find intel llvm c/c++ compiler environment
local icxenv = find_icxenv()
if icxenv and icxenv.icxvars then
local icxvarsall = icxenv.icxvars
local icxenv = icxvarsall[toolchain:arch()]
if icxenv and icxenv.PATH and icxenv.INCLUDE and icxenv.LIB then
local tool = find_tool("icx.exe", {force = true, envs = icxenv, version = true})
if tool then
cprint("checking for Intel LLVM C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("varsall", icxvarsall)
toolchain:configs_save()
return _check_vstudio(toolchain)
end
end
end
end
-- check intel on linux
function _check_intel_on_linux(toolchain)
local icxenv = toolchain:config("icxenv")
if icxenv then
return true
end
icxenv = find_icxenv()
if icxenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
local tool = find_tool("icx", {force = true, envs = {[ldname] = icxenv.libdir}, paths = icxenv.bindir})
if tool then
cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("icxenv", icxenv)
toolchain:config_set("bindir", icxenv.bindir)
toolchain:configs_save()
return true
end
return true
end
end
-- main entry
function main(toolchain)
if is_host("windows") then
return _check_intel_on_windows(toolchain)
else
return _check_intel_on_linux(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/envs/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("envs")
-- set description
set_description("Environment variables toolchain")
-- set toolset
set_toolset("cc", "$(env CC)")
set_toolset("cxx", "$(env CXX)")
set_toolset("ld", "$(env LD)", "$(env CXX)")
set_toolset("sh", "$(env SH)", "$(env LD)", "$(env CXX)")
set_toolset("ar", "$(env AR)")
set_toolset("strip", "$(env STRIP)")
set_toolset("ranlib","$(env RANLIB)")
set_toolset("mm", "$(env MM)")
set_toolset("mxx", "$(env MXX)")
set_toolset("as", "$(env AS)")
set_toolset("sc", "$(env SC)")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/llvm/xmake.lua | --!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 xmake.lua
--
toolchain("llvm")
set_kind("standalone")
set_homepage("https://llvm.org/")
set_description("A collection of modular and reusable compiler and toolchain technologies")
set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared")
set_toolset("cc", "clang")
set_toolset("cxx", "clang", "clang++")
set_toolset("mxx", "clang", "clang++")
set_toolset("mm", "clang")
set_toolset("cpp", "clang -E")
set_toolset("as", "clang")
set_toolset("ld", "clang++", "clang")
set_toolset("sh", "clang++", "clang")
set_toolset("ar", "llvm-ar")
set_toolset("strip", "llvm-strip")
set_toolset("ranlib", "llvm-ranlib")
set_toolset("objcopy","llvm-objcopy")
set_toolset("mrc", "llvm-rc")
on_check("check")
on_load(function (toolchain)
-- add runtimes
if toolchain:is_plat("windows") then
toolchain:add("runtimes", "MT", "MTd", "MD", "MDd")
end
-- add march flags
local march
if toolchain:is_plat("windows") and not is_host("windows") then
-- cross-compilation for windows
if toolchain:is_arch("i386", "x86") then
march = "-target i386-pc-windows-msvc"
else
march = "-target x86_64-pc-windows-msvc"
end
toolchain:add("ldflags", "-fuse-ld=lld")
toolchain:add("shflags", "-fuse-ld=lld")
elseif toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("mxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
-- init flags for macOS
if toolchain:is_plat("macosx") then
local xcode_dir = get_config("xcode")
local xcode_sdkver = toolchain:config("xcode_sdkver")
local xcode_sdkdir = nil
if xcode_dir and xcode_sdkver then
xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
toolchain:add("cxflags", {"-isysroot", xcode_sdkdir})
toolchain:add("mxflags", {"-isysroot", xcode_sdkdir})
toolchain:add("ldflags", {"-isysroot", xcode_sdkdir})
toolchain:add("shflags", {"-isysroot", xcode_sdkdir})
else
-- @see https://github.com/xmake-io/xmake/issues/1179
local macsdk = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
if os.exists(macsdk) then
toolchain:add("cxflags", {"-isysroot", macsdk})
toolchain:add("mxflags", {"-isysroot", macsdk})
toolchain:add("ldflags", {"-isysroot", macsdk})
toolchain:add("shflags", {"-isysroot", macsdk})
end
end
toolchain:add("mxflags", "-fobjc-arc")
end
-- add bin search library for loading some dependent .dll files windows
local bindir = toolchain:bindir()
if bindir and is_host("windows") then
toolchain:add("runenvs", "PATH", bindir)
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/llvm/check.lua | --!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_xcode")
import("detect.sdks.find_cross_toolchain")
-- find xcode on macos
function _find_xcode(toolchain)
-- find xcode
local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver")
local xcode = find_xcode(toolchain:config("xcode") or config.get("xcode"), {force = true, verbose = true,
find_codesign = false,
sdkver = xcode_sdkver,
plat = toolchain:plat(),
arch = toolchain:arch()})
if not xcode then
cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}")
return
end
-- xcode found
xcode_sdkver = xcode.sdkver
if toolchain:is_global() then
config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir)
end
toolchain:config_set("xcode", xcode.sdkdir)
toolchain:config_set("xcode_sdkver", xcode_sdkver)
toolchain:configs_save()
cprint("checking for SDK version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), xcode_sdkver)
end
-- check the cross toolchain
function main(toolchain)
-- get sdk directory
local sdkdir = toolchain:sdkdir()
local bindir = toolchain:bindir()
if not sdkdir and not bindir then
bindir = try {function () return os.iorunv("llvm-config", {"--bindir"}) end}
if bindir then
sdkdir = path.directory(bindir)
elseif is_host("linux") and os.isfile("/usr/bin/llvm-ar") then
sdkdir = "/usr"
elseif is_host("macosx") then
if os.arch() == "arm64" then
bindir = find_path("llvm-ar", "/opt/homebrew/opt/llvm/bin")
else
bindir = find_path("llvm-ar", "/usr/local/Cellar/llvm/*/bin")
end
if bindir then
sdkdir = path.directory(bindir)
end
elseif is_host("windows") then
local llvm_ar = find_tool("llvm-ar", {force = true, envs = {PATH = os.getenv("PATH")}})
if llvm_ar and llvm_ar.program and path.is_absolute(llvm_ar.program) then
bindir = path.directory(llvm_ar.program)
sdkdir = path.directory(bindir)
end
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("llvm toolchain not found!")
end
-- attempt to find xcode to pass `-isysroot` on macos
if toolchain:is_plat("macosx") then
_find_xcode(toolchain)
end
return cross_toolchain
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gnu-rm/xmake.lua | --!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 xmake.lua
--
toolchain("gnu-rm")
set_homepage("https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm")
set_description("GNU Arm Embedded Toolchain")
set_kind("cross")
on_load(function (toolchain)
toolchain:load_cross_toolchain()
toolchain:add("ldflags", "--specs=nosys.specs", "--specs=nano.specs", {force = true})
toolchain:add("shflags", "--specs=nosys.specs", "--specs=nano.specs", {force = true})
toolchain:add("syslinks", "c", "m")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/swift/xmake.lua | --!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 Sousce Group.
--
-- @author ruki
-- @file xmake.lua
--
-- define toolchain
toolchain("swift")
-- set homepage
set_homepage("https://swift.org/")
set_description("Swift Programming Language Compiler")
-- set toolset
set_toolset("sc", "$(env SC)", "swift-frontend", "swiftc")
set_toolset("scld", "$(env SC)", "swiftc")
set_toolset("scsh", "$(env SC)", "swiftc")
-- on load
on_load(function (toolchain)
toolchain:set("scshflags", "")
toolchain:set("scldflags", "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/verilator/xmake.lua | --!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 xmake.lua
--
toolchain("verilator")
set_homepage("https://verilator.org/")
set_description("Verilator open-source SystemVerilog simulator and lint system")
on_check(function (toolchain)
import("lib.detect.find_tool")
local paths = {}
for _, package in ipairs(toolchain:packages()) do
local envs = package:envs()
if envs then
table.join2(paths, envs.PATH)
end
end
local verilator = find_tool("verilator", {paths = paths})
if verilator and verilator.program then
toolchain:config_set("verilator", verilator.program)
cprint("${dim}checking for verilator ... ${color.success}%s", path.filename(verilator.program))
else
cprint("${dim}checking for verilator ... ${color.nothing}${text.nothing}")
raise("verilator not found!")
end
toolchain:configs_save()
return true
end)
on_load(function (toolchain)
if is_host("windows") then
for _, package in ipairs(toolchain:packages()) do
local envs = package:envs()
if envs then
local verilator_root = envs.VERILATOR_ROOT
if verilator_root then
toolchain:add("runenvs", "VERILATOR_ROOT", table.unwrap(verilator_root))
break
end
end
end
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/nasm/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("nasm")
-- set homepage
set_homepage("https://www.nasm.us/")
set_description("NASM Assembler")
-- set toolset
set_toolset("as", "nasm")
-- on load
on_load(function (toolchain)
local asflags = "" -- maybe 16bits if no flags
if toolchain:is_plat("macosx") then
if toolchain:is_arch("x86_64") then
asflags = "-f macho64"
elseif toolchain:is_arch("i386") then
asflags = "-f macho32"
end
elseif toolchain:is_plat("linux", "android", "bsd") then
if toolchain:is_arch("x86_64") then
asflags = "-f elf64"
elseif toolchain:is_arch("i386") then
asflags = "-f elf32"
end
elseif toolchain:is_plat("windows", "mingw", "msys", "cygwin") then
if toolchain:is_arch("x64", "x86_64") then
asflags = "-f win64"
elseif toolchain:is_arch("x86", "i386") then
asflags = "-f win32"
end
end
toolchain:add("nasm.asflags", asflags)
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/dlang/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("dlang")
set_homepage("https://dlang.org/")
set_description("D Programming Language Compiler (Auto)")
on_check("check")
on_load(function (toolchain)
local cross = toolchain:cross() or ""
toolchain:add("toolset", "dc", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
toolchain:add("toolset", "dcld", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
toolchain:add("toolset", "dcsh", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
toolchain:add("toolset", "dcar", "$(env DC)", "dmd", "ldc2", cross .. "gcc-ar")
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
toolchain:add("dcflags", march or "")
toolchain:add("dcshflags", march or "")
toolchain:add("dcldflags", march or "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/dlang/check.lua | --!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_tool")
import("detect.sdks.find_cross_toolchain")
function main(toolchain)
-- we attempt to find dmd, ldc2, gdc in $PATH
if find_tool("dmd") or find_tool("ldc2") or find_tool("gdc") then
return true
end
-- we need to find ldc2 and gdc in the given toolchain sdk directory
local sdkdir = toolchain:sdkdir()
local bindir = toolchain:bindir()
local cross = toolchain:cross()
if not sdkdir and not bindir and not cross then
return
end
-- find cross toolchain
local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross})
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("cross toolchain not found!")
end
return cross_toolchain
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-8/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("8")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/load_applexros.lua | --!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 load_applexros.lua
--
function main(toolchain)
local arch = toolchain:arch()
local xcode_sdkver = toolchain:config("xcode_sdkver")
local xcode_sysroot = toolchain:config("xcode_sysroot")
local target_minver = toolchain:config("target_minver")
-- init target flags
if target_minver then
local simulator = toolchain:config("appledev") == "simulator"
local target = (simulator and "%s-apple-xrsimulator%s" or "%s-apple-xros%s"):format(arch, target_minver)
toolchain:add("cxflags", "-target", target)
toolchain:add("mxflags", "-target", target)
toolchain:add("asflags", "-target", target)
toolchain:add("ldflags", "-target", target)
toolchain:add("shflags", "-target", target)
toolchain:add("scflags", "-target", target)
toolchain:add("scldflags", "-target", target)
toolchain:add("scshflags", "-target", target)
end
-- init flags for c/c++
toolchain:add("cxflags", "-isysroot", xcode_sysroot)
toolchain:add("ldflags", "-fobjc-link-runtime", "-isysroot", xcode_sysroot)
toolchain:add("shflags", "-fobjc-link-runtime", "-isysroot", xcode_sysroot)
-- init flags for objc/c++
toolchain:add("mxflags", "-isysroot", xcode_sysroot)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
toolchain:add("mxflags", "-fobjc-arc")
-- init flags for asm
toolchain:add("asflags", "-isysroot", xcode_sysroot)
-- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
toolchain:add("scflags", "-sdk " .. xcode_sysroot)
toolchain:add("scshflags", "-sdk " .. xcode_sysroot)
toolchain:add("scldflags", "-sdk " .. xcode_sysroot)
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/load_iphoneos.lua | --!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 load_iphoneos.lua
--
function main(toolchain)
-- init architecture
local arch = toolchain:arch()
local xcode_sdkver = toolchain:config("xcode_sdkver")
local xcode_sysroot = toolchain:config("xcode_sysroot")
-- is simulator?
local simulator = toolchain:config("appledev") == "simulator"
-- init target minimal version
local target_minver = toolchain:config("target_minver")
if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then
target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets
end
local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver
-- init flags for c/c++
toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
-- init flags for objc/c++
toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
toolchain:add("mxflags", "-fobjc-arc")
-- init flags for asm
toolchain:add("asflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/load_appletvos.lua | --!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 load_appletvos.lua
--
function main(toolchain)
-- init architecture
local arch = toolchain:arch()
local xcode_sdkver = toolchain:config("xcode_sdkver")
local xcode_sysroot = toolchain:config("xcode_sysroot")
-- is simulator?
local simulator = toolchain:config("appledev") == "simulator"
-- init target minimal version
local target_minver = toolchain:config("target_minver")
local target_minver_flags = (simulator and "-mappletvsimulator-version-min=" or "-mappletvos-version-min=") .. target_minver
-- init flags for c/c++
toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
-- init flags for objc/c++
toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
toolchain:add("mxflags", "-fobjc-arc")
-- init flags for asm
toolchain:add("asflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
toolchain:add("scflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
toolchain:add("scshflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
toolchain:add("scldflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/load_macosx.lua | --!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 load_macosx.lua
--
function main(toolchain)
local arch = toolchain:arch()
local target_minver = toolchain:config("target_minver")
local xcode_sysroot = toolchain:config("xcode_sysroot")
-- init target flags
local appledev = toolchain:config("appledev")
if target_minver then
local target = ("%s-apple-macos%s"):format(arch, target_minver)
if appledev == "catalyst" then
target = ("%s-apple-ios%s-macabi"):format(arch, target_minver)
end
toolchain:add("cxflags", "-target", target)
toolchain:add("mxflags", "-target", target)
toolchain:add("asflags", "-target", target)
toolchain:add("ldflags", "-target", target)
toolchain:add("shflags", "-target", target)
toolchain:add("scflags", "-target", target)
toolchain:add("scldflags", "-target", target)
toolchain:add("scshflags", "-target", target)
end
-- add sysroot flags
if xcode_sysroot then
toolchain:add("cxflags", "-isysroot", xcode_sysroot)
toolchain:add("asflags", "-isysroot", xcode_sysroot)
toolchain:add("ldflags", "-isysroot", xcode_sysroot)
toolchain:add("shflags", "-isysroot", xcode_sysroot)
toolchain:add("mxflags", "-isysroot", xcode_sysroot)
toolchain:add("scflags", "-sdk " .. xcode_sysroot)
toolchain:add("scshflags", "-sdk " .. xcode_sysroot)
toolchain:add("scldflags", "-sdk " .. xcode_sysroot)
if appledev == "catalyst" then
toolchain:add("cxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("asflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("mxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("ldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("shflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("scldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("scshflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("cxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("asflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("ldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("shflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("mxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scshflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
end
end
-- init flags for c/c++
toolchain:add("ldflags", "-lz")
toolchain:add("shflags", "-lz")
-- init flags for objc/c++ (with ldflags and shflags)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
toolchain:add("mxflags", "-fobjc-arc")
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/xmake.lua | --!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 xmake.lua
--
toolchain("xcode")
set_kind("standalone")
set_homepage("https://developer.apple.com/xcode/")
set_description("Xcode IDE")
set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared")
on_check("check")
on_load(function (toolchain)
-- set toolset
local arch = toolchain:arch()
local bindir = toolchain:bindir()
local appledev = toolchain:config("appledev")
local xc_clang = bindir and path.join(bindir, "clang") or "clang"
local xc_clangxx = bindir and path.join(bindir, "clang++") or "clang++"
local xc_ar = bindir and path.join(bindir, "ar") or "ar"
local xc_strip = bindir and path.join(bindir, "strip") or "strip"
local xc_swift_frontend = bindir and path.join(bindir, "swift-frontend") or "swift-frontend"
local xc_swiftc = bindir and path.join(bindir, "swiftc") or "swiftc"
local xc_dsymutil = bindir and path.join(bindir, "dsymutil") or "dsymutil"
toolchain:set("toolset", "cc", xc_clang)
toolchain:set("toolset", "cxx", xc_clang, xc_clangxx)
toolchain:set("toolset", "ld", xc_clangxx, xc_clang)
toolchain:set("toolset", "sh", xc_clangxx, xc_clang)
toolchain:set("toolset", "ar", xc_ar)
toolchain:set("toolset", "strip", xc_strip)
toolchain:set("toolset", "dsymutil", xc_dsymutil, "dsymutil")
toolchain:set("toolset", "mm", xc_clang)
toolchain:set("toolset", "mxx", xc_clang, xc_clangxx)
toolchain:set("toolset", "sc", xc_swift_frontend, "swift_frontend", xc_swiftc, "swiftc")
toolchain:set("toolset", "scld", xc_swiftc, "swiftc")
toolchain:set("toolset", "scsh", xc_swiftc, "swiftc")
if arch then
toolchain:set("toolset", "cpp", xc_clang .. " -arch " .. arch .. " -E")
end
if toolchain:is_plat("macosx") then
toolchain:set("toolset", "as", xc_clang)
elseif appledev == "simulator" or appledev == "catalyst" then
toolchain:set("toolset", "as", xc_clang)
else
toolchain:set("toolset", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. xc_clang))
end
-- load configurations
import("load_" .. toolchain:plat())(toolchain)
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/load_watchos.lua | --!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 load_watchos.lua
--
function main(toolchain)
-- init architecture
local arch = toolchain:arch()
local xcode_sdkver = toolchain:config("xcode_sdkver")
local xcode_sysroot = toolchain:config("xcode_sysroot")
-- is simulator?
local simulator = toolchain:config("appledev") == "simulator"
-- init target minimal version
local target_minver = toolchain:config("target_minver")
local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver
-- init flags for c/c++
toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
-- init flags for objc/c++
toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
toolchain:add("mxflags", "-fobjc-arc")
-- init flags for asm
toolchain:add("asflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/xcode/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_xcode")
import("private.utils.executable_path")
-- main entry
function main(toolchain)
-- get apple device
local simulator
local appledev = toolchain:config("appledev") or config.get("appledev")
if appledev and appledev == "simulator" then
simulator = true
appledev = "simulator"
elseif not toolchain:is_plat("macosx") and toolchain:is_arch("i386", "x86_64") then
simulator = true
appledev = "simulator"
end
-- find xcode
local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver")
local xcode = find_xcode(config.get("xcode"), {force = true, verbose = true,
find_codesign = toolchain:is_global(),
sdkver = xcode_sdkver,
appledev = appledev,
plat = toolchain:plat(),
arch = toolchain:arch()})
if not xcode then
cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}")
return false
end
-- xcode found
xcode_sdkver = xcode.sdkver
if toolchain:is_global() then
config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true})
config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true})
cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir)
if xcode.codesign_identity then
cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity)
else
cprint("checking for Codesign Identity of Xcode ... ${color.nothing}${text.nothing}")
end
if toolchain:is_plat("iphoneos") then
if xcode.mobile_provision then
cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision)
else
cprint("checking for Mobile Provision of Xcode ... ${color.nothing}${text.nothing}")
end
end
end
-- get xcode bin directory
local cross
if xcode.sdkdir and os.isdir(xcode.sdkdir) then
local bindir = path.join(xcode.sdkdir, "Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin")
toolchain:config_set("bindir", bindir)
else
if toolchain:is_plat("macosx") then
cross = "xcrun -sdk macosx "
elseif toolchain:is_plat("iphoneos") then
cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos "
elseif toolchain:is_plat("watchos") then
cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos "
elseif toolchain:is_plat("appletvos") then
cross = simulator and "xcrun -sdk appletvsimulator " or "xcrun -sdk appletvos "
elseif toolchain:is_plat("applexros") then
cross = simulator and "xcrun -sdk xrsimulator " or "xcrun -sdk xros "
else
raise("unknown platform for xcode!")
end
local xc_clang = executable_path(cross .. "clang")
if xc_clang then
toolchain:config_set("bindir", path.directory(xc_clang))
end
end
-- save xcode sysroot directory
local xcode_sysroot
if xcode.sdkdir and xcode_sdkver then
if toolchain:is_plat("macosx") then
xcode_sysroot = xcode.sdkdir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
elseif toolchain:is_plat("iphoneos") then
local platname = simulator and "iPhoneSimulator" or "iPhoneOS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
elseif toolchain:is_plat("watchos") then
local platname = simulator and "WatchSimulator" or "WatchOS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
elseif toolchain:is_plat("appletvos") then
local platname = simulator and "AppleTVSimulator" or "AppleTVOS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
elseif toolchain:is_plat("applexros") then
local platname = simulator and "XRSimulator" or "XROS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
end
else
-- maybe it is from CommandLineTools, e.g. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
-- @see https://github.com/xmake-io/xmake/issues/3686
local sdkpath = try { function () return os.iorun(cross .. "--show-sdk-path") end }
if sdkpath then
xcode_sysroot = sdkpath:trim()
end
end
if xcode_sysroot then
toolchain:config_set("xcode_sysroot", xcode_sysroot)
end
toolchain:config_set("simulator", simulator)
-- save target minver
--
-- @note we need to differentiate the version for the system,
-- because the xcode toolchain of iphoneos/macosx may need to be used at the same time.
--
-- e.g.
--
-- target("test")
-- set_toolchains("xcode", {plat = os.host(), arch = os.arch()})
--
local target_minver = toolchain:config("target_minver") or config.get("target_minver")
if xcode_sdkver and not target_minver then
target_minver = xcode.target_minver
end
toolchain:config_set("xcode", xcode.sdkdir)
toolchain:config_set("xcode_sdkver", xcode_sdkver)
toolchain:config_set("target_minver", target_minver)
toolchain:config_set("appledev", appledev)
toolchain:configs_save()
if xcode_sdkver then
cprint("checking for SDK version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), xcode_sdkver)
end
if target_minver then
cprint("checking for Minimal target version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), target_minver)
end
return true
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/cosmocc/xmake.lua | --!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 xmake.lua
--
toolchain("cosmocc")
set_kind("standalone")
set_homepage("https://github.com/jart/cosmopolitan")
set_description("build-once run-anywhere c library")
set_formats("static", "lib$(name).a")
set_formats("object", "$(name).o")
set_formats("symbol", "$(name).sym")
set_toolset("cc", "cosmocc")
set_toolset("cxx", "cosmoc++", "cosmocc")
set_toolset("cpp", "cosmocc -E")
set_toolset("as", "cosmocc")
set_toolset("ld", "cosmoc++", "cosmocc")
set_toolset("sh", "cosmoc++", "cosmocc")
set_toolset("ar", "cosmoar")
on_check("check")
on_load(function (toolchain)
if toolchain:is_arch("x86_64", "x64") then
toolchain:set("toolset", "ranlib", "x86_64-linux-cosmo-ranlib")
toolchain:set("toolset", "strip", "x86_64-linux-cosmo-strip")
else
toolchain:set("toolset", "ranlib", "aarch64-linux-cosmo-ranlib")
toolchain:set("toolset", "strip", "aarch64-linux-cosmo-strip")
end
-- @see https://github.com/xmake-io/xmake/issues/5552
local envs = toolchain:config("envs")
if envs then
for k, v in pairs(envs) do
toolchain:add("runenvs", k, v)
end
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/cosmocc/check.lua | --!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 cross toolchain from external envirnoment
local envs
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
local bindir = path.directory(cosmocc.program)
local sdkdir = path.directory(bindir)
cross_toolchain = {bindir = bindir, sdkdir = sdkdir}
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)
if envs then
toolchain:config_set("envs", envs)
end
toolchain:configs_save()
else
raise("cosmocc toolchain not found!")
end
return cross_toolchain
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-12/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("12")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-14/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("14")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/zig/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("zig")
-- set homepage
set_homepage("https://ziglang.org/")
set_description("Zig Programming Language Compiler")
-- on check
on_check(function (toolchain)
import("lib.detect.find_tool")
local paths = {}
for _, package in ipairs(toolchain:packages()) do
local envs = package:envs()
if envs then
table.join2(paths, envs.PATH)
end
end
local zig = get_config("zc")
if not zig then
zig = find_tool("zig", {force = true, paths = paths})
if zig and zig.program then
zig = zig.program
end
end
if zig then
toolchain:config_set("zig", zig)
toolchain:configs_save()
return true
end
end)
-- on load
on_load(function (toolchain)
-- set toolset
-- we patch target to `zig cc` to fix has_flags. see https://github.com/xmake-io/xmake/issues/955#issuecomment-766929692
local zig = toolchain:config("zig") or "zig"
if toolchain:config("zigcc") ~= false then
-- we can use `set_toolchains("zig", {zigcc = false})` to disable zigcc
-- @see https://github.com/xmake-io/xmake/issues/3251
toolchain:set("toolset", "cc", zig .. " cc")
toolchain:set("toolset", "cxx", zig .. " c++")
toolchain:set("toolset", "ld", zig .. " c++")
toolchain:set("toolset", "sh", zig .. " c++")
end
toolchain:set("toolset", "ar", "$(env ZC)", zig)
toolchain:set("toolset", "zc", "$(env ZC)", zig)
toolchain:set("toolset", "zcar", "$(env ZC)", zig)
toolchain:set("toolset", "zcld", "$(env ZC)", zig)
toolchain:set("toolset", "zcsh", "$(env ZC)", zig)
-- init arch
if toolchain:is_arch("arm64", "arm64-v8a") then
arch = "aarch64"
elseif toolchain:is_arch("arm", "armv7") then
arch = "arm"
elseif toolchain:is_arch("i386", "x86") then
arch = "i386"
elseif toolchain:is_arch("riscv64") then
arch = "riscv64"
elseif toolchain:is_arch("loong64") then
arch = "loong64"
elseif toolchain:is_arch("mips.*") then
arch = toolchain:arch()
elseif toolchain:is_arch("ppc64") then
arch = "powerpc64"
elseif toolchain:is_arch("ppc") then
arch = "powerpc"
elseif toolchain:is_arch("s390x") then
arch = "s390x"
else
arch = "x86_64"
end
-- init target
local target
if toolchain:is_plat("cross") then
-- xmake f -p cross --toolchain=zig --cross=mips64el-linux-gnuabi64
target = toolchain:cross()
elseif toolchain:is_plat("macosx") then
--@see https://github.com/ziglang/zig/issues/14226
target = arch .. "-macos-none"
elseif toolchain:is_plat("linux") then
if arch == "arm" then
target = "arm-linux-gnueabi"
elseif arch == "mips64" or arch == "mips64el" then
target = arch .. "-linux-gnuabi64"
else
target = arch .. "-linux-gnu"
end
elseif toolchain:is_plat("windows") then
target = arch .. "-windows-msvc"
elseif toolchain:is_plat("mingw") then
target = arch .. "-windows-gnu"
end
if target then
toolchain:add("zig_cc.cxflags", "-target", target)
toolchain:add("zig_cc.shflags", "-target", target)
toolchain:add("zig_cc.ldflags", "-target", target)
toolchain:add("zig_cxx.cxflags", "-target", target)
toolchain:add("zig_cxx.shflags", "-target", target)
toolchain:add("zig_cxx.ldflags", "-target", target)
toolchain:add("zcflags", "-target", target)
toolchain:add("zcldflags", "-target", target)
toolchain:add("zcshflags", "-target", target)
end
-- @see https://github.com/ziglang/zig/issues/5825
if toolchain:is_plat("windows") then
toolchain:add("zcldflags", "--subsystem console")
toolchain:add("zcldflags", "-lkernel32", "-lntdll")
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-17/xmake.lua | includes(path.join(os.scriptdir(), "../clang/xmake.lua"))
toolchain_clang("17")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/fpc/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("fpc")
-- set homepage
set_homepage("https://www.freepascal.org/")
set_description("Free Pascal Programming Language Compiler")
-- set toolset
set_toolset("pc", "$(env PC)", "fpc")
set_toolset("pcld", "$(env PC)", "fpc")
set_toolset("pcsh", "$(env PC)", "fpc")
-- on load
on_load(function (toolchain)
if toolchain:is_plat("linux") then
toolchain:set("pcldflags", "-k-lc")
toolchain:set("pcshflags", "-k-lc")
else
toolchain:set("pcldflags", "")
toolchain:set("pcshflags", "")
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/iverilog/xmake.lua | --!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 xmake.lua
--
toolchain("iverilog")
set_homepage("https://steveicarus.github.io/iverilog/")
set_description("Icarus Verilog")
set_kind("standalone")
on_check(function (toolchain)
import("lib.detect.find_tool")
local paths = {}
for _, package in ipairs(toolchain:packages()) do
local envs = package:envs()
if envs then
table.join2(paths, envs.PATH)
end
end
local iverilog = find_tool("iverilog", {paths = paths})
if iverilog and iverilog.program then
toolchain:config_set("iverilog", iverilog.program)
cprint("${dim}checking for iverilog ... ${color.success}%s", path.filename(iverilog.program))
else
cprint("${dim}checking for iverilog ... ${color.nothing}${text.nothing}")
raise("iverilog not found!")
end
local vvp = find_tool("vvp", {paths = paths})
if vvp and vvp.program then
toolchain:config_set("vvp", vvp.program)
cprint("${dim}checking for vvp ... ${color.success}%s", path.filename(vvp.program))
else
cprint("${dim}checking for vvp ... ${color.nothing}${text.nothing}")
raise("iverilog not found!")
end
toolchain:configs_save()
return true
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/rust/xmake.lua | --!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 xmake.lua
--
toolchain("rust")
set_homepage("https://www.rust-lang.org/")
set_description("Rust Programming Language Compiler")
set_toolset("rc", "$(env RC)", "rustc")
set_toolset("rcld", "$(env RC)", "rustc")
set_toolset("rcsh", "$(env RC)", "rustc")
set_toolset("rcar", "$(env RC)", "rustc")
on_load(function (toolchain)
-- e.g. x86_64-pc-windows-msvc, aarch64-unknown-none
local arch = toolchain:arch()
if toolchain:is_plat("android") then
local targets = {
["armv5te"] = "arm-linux-androideabi" -- deprecated
, ["armv7-a"] = "arm-linux-androideabi" -- deprecated
, ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17
, ["armeabi-v7a"] = "arm-linux-androideabi"
, ["arm64-v8a"] = "aarch64-linux-android"
}
if targets[arch] then
arch = targets[arch]
end
end
if arch and #arch:split("%-") > 1 then
toolchain:add("rcflags", "--target=" .. arch)
else
toolchain:set("rcshflags", "")
toolchain:set("rcldflags", "")
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-4.9/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("4.9")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/fasm/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("fasm")
-- set homepage
set_homepage("https://flatassembler.net/")
set_description("Flat Assembler")
-- set toolset
set_toolset("as", "fasm")
-- on load
on_load(function (toolchain)
-- reset asflags for fasm
toolchain:add("fasm.asflags", "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ndk/load.lua | --!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 load.lua
--
-- imports
import("core.base.hashset")
import("core.project.config")
-- get triple
function _get_triple(arch)
local triples =
{
["armv5te"] = "arm-linux-androideabi" -- deprecated
, ["armv7-a"] = "arm-linux-androideabi" -- deprecated
, ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17
, ["armeabi-v7a"] = "arm-linux-androideabi"
, ["arm64-v8a"] = "aarch64-linux-android"
, i386 = "i686-linux-android" -- deprecated
, x86 = "i686-linux-android"
, x86_64 = "x86_64-linux-android"
, mips = "mips-linux-android" -- removed in ndk r17
, mips64 = "mips64-linux-android" -- removed in ndk r17
}
return triples[arch]
end
-- get target
function _get_target(arch, ndk_sdkver)
local targets =
{
["armv5te"] = "armv5te-none-linux-androideabi" -- deprecated
, ["armeabi"] = "armv5te-none-linux-androideabi" -- removed in ndk r17
, ["armv7-a"] = "armv7-none-linux-androideabi" -- deprecated
, ["armeabi-v7a"] = "armv7-none-linux-androideabi"
, ["arm64-v8a"] = "aarch64-none-linux-android"
, ["i386"] = "i686-none-linux-android" -- deprecated
, ["x86"] = "i686-none-linux-android"
, ["x86_64"] = "x86_64-none-linux-android"
, ["mips"] = "mipsel-none-linux-android" -- removed in ndk r17
, ["mips64"] = "mips64el-none-linux-android" -- removed in ndk r17
}
assert(targets[arch], "unknown arch(%s) for android!", arch)
return targets[arch] .. (ndk_sdkver or "")
end
-- load ndk toolchain
--
-- some extra configuration for target
-- e.g.
-- set_values("ndk.arm_mode", "arm") -- or thumb
--
function main(toolchain)
-- get cross
local cross = toolchain:cross() or ""
-- get gcc toolchain bin directory
local gcc_toolchain_bin = nil
local gcc_toolchain = toolchain:config("gcc_toolchain")
if gcc_toolchain then
gcc_toolchain_bin = path.join(gcc_toolchain, "bin")
end
-- get ndk and version
local ndk = toolchain:config("ndk")
local ndkver = toolchain:config("ndkver")
local ndk_sdkver = toolchain:config("ndk_sdkver")
-- set toolset
toolchain:set("toolset", "cc", "clang", cross .. "gcc")
toolchain:set("toolset", "cxx", "clang++", cross .. "g++")
toolchain:set("toolset", "cpp", "clang -E", cross .. "gcc -E")
toolchain:set("toolset", "as", "clang", cross .. "gcc")
toolchain:set("toolset", "ld", "clang++", "clang", cross .. "g++", cross .. "gcc")
toolchain:set("toolset", "sh", "clang++", "clang", cross .. "g++", cross .. "gcc")
toolchain:set("toolset", "ar", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar")
toolchain:set("toolset", "ranlib", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ranlib") or (cross .. "ranlib"))
toolchain:set("toolset", "strip", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "strip") or (cross .. "strip"), "llvm-strip")
-- gnustl and stlport have been removed in ndk r18 (deprecated in ndk r17)
-- https://github.com/android/ndk/wiki/Changelog-r18
local old_runtimes = {"gnustl_static", "gnustl_shared", "stlport_static", "stlport_shared"}
if ndkver and ndkver < 18 then
toolchain:add("runtimes", table.unpack(old_runtimes))
end
-- init flags
local arm32 = false
local arch = toolchain:arch()
toolchain:add("ldflags", "-llog")
toolchain:add("shflags", "-llog")
if arch and (arch == "armeabi" or arch == "armeabi-v7a" or arch == "armv5te" or arch == "armv7-a") then -- armv5te/armv7-a are deprecated
arm32 = true
end
-- use llvm directory? e.g. android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin
local isllvm = false
local bindir = toolchain:bindir()
if bindir and bindir:find("llvm", 1, true) then
isllvm = true
end
-- init architecture
if isllvm then
-- add ndk target
local ndk_target = _get_target(arch, ndk_sdkver)
toolchain:add("cxflags", "-target " .. ndk_target)
toolchain:add("asflags", "-target " .. ndk_target)
toolchain:add("ldflags", "-target " .. ndk_target)
toolchain:add("shflags", "-target " .. ndk_target)
-- add gcc toolchain
local gcc_toolchain = toolchain:config("gcc_toolchain")
if gcc_toolchain then
toolchain:add("cxflags", "-gcc-toolchain " .. gcc_toolchain)
toolchain:add("asflags", "-gcc-toolchain " .. gcc_toolchain)
toolchain:add("ldflags", "-gcc-toolchain " .. gcc_toolchain)
toolchain:add("shflags", "-gcc-toolchain " .. gcc_toolchain)
end
else
local march = arch
if arch == "arm64-v8a" then
march = "armv8-a"
else
march = "armv5te"
end
-- old version ndk
toolchain:add("cxflags", "-march=" .. march)
toolchain:add("asflags", "-march=" .. march)
toolchain:add("ldflags", "-march=" .. march)
toolchain:add("shflags", "-march=" .. march)
end
-- init cxflags for the target kind: binary
toolchain:add("binary.cxflags", "-fPIE", "-pie")
-- add flags for the sdk directory of ndk
if ndk and ndk_sdkver then
-- the sysroot archs
local sysroot_archs =
{
["armv5te"] = "arch-arm" -- deprecated
, ["armv7-a"] = "arch-arm" -- deprecated
, ["armeabi"] = "arch-arm" -- removed in ndk r17
, ["armeabi-v7a"] = "arch-arm"
, ["arm64-v8a"] = "arch-arm64"
, i386 = "arch-x86" -- deprecated
, x86 = "arch-x86"
, x86_64 = "arch-x86_64"
, mips = "arch-mips" -- removed in ndk r17
, mips64 = "arch-mips64" -- removed in ndk r17
}
local sysroot_arch = sysroot_archs[arch]
-- add sysroot flags
local ndk_sysroot = toolchain:config("ndk_sysroot")
if ndk_sysroot and os.isdir(ndk_sysroot) then
local triple = _get_triple(arch)
if ndkver and tonumber(ndkver) < 22 then
toolchain:add("cxflags", "-D__ANDROID_API__=" .. ndk_sdkver)
toolchain:add("asflags", "-D__ANDROID_API__=" .. ndk_sdkver)
end
local flag_sysroot = "--sysroot=" .. os.args(ndk_sysroot)
local flag_isystem = "-isystem " .. os.args(path.join(ndk_sysroot, "usr", "include", triple))
toolchain:add("cflags", flag_sysroot)
toolchain:add("cxxflags", flag_sysroot)
toolchain:add("asflags", flag_sysroot)
toolchain:add("cflags", flag_isystem)
toolchain:add("cxxflags", flag_isystem)
toolchain:add("asflags", flag_isystem)
else
local ndk_sdkdir = path.translate(format("%s/platforms/android-%d", ndk, ndk_sdkver))
if os.isdir(ndk_sdkdir) then
if sysroot_arch then
local flag_sysroot = "--sysroot=" .. os.args(path.join(ndk_sdkdir, sysroot_arch))
toolchain:add("cflags", flag_sysroot)
toolchain:add("cxxflags", flag_sysroot)
toolchain:add("asflags", flag_sysroot)
toolchain:add("ldflags", flag_sysroot)
toolchain:add("shflags", flag_sysroot)
end
end
end
-- add "-fPIE -pie" to ldflags
toolchain:add("ldflags", "-fPIE")
toolchain:add("ldflags", "-pie")
-- get llvm c++ stl sdk directory
local cxxstl_sdkdir_llvmstl = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk))
-- get gnu c++ stl sdk directory
local cxxstl_sdkdir_gnustl = nil
if toolchain:config("ndk_toolchains_ver") then
cxxstl_sdkdir_gnustl = path.translate(format("%s/sources/cxx-stl/gnu-libstdc++/%s", ndk, toolchain:config("ndk_toolchains_ver")))
end
-- get stlport c++ sdk directory
local cxxstl_sdkdir_stlport = path.translate(format("%s/sources/cxx-stl/stlport", ndk))
-- get c++ stl sdk directory
local cxxstl_sdkdir = nil
local ndk_cxxstl = config.get("runtimes") or config.get("ndk_cxxstl")
if ndk_cxxstl then
if (ndkver and ndkver >= 18) and table.contains(old_runtimes, ndk_cxxstl) then
utils.warning("%s is was removed in ndk v%s", ndk_cxxstl, ndk_sdkver)
end
if ndk_cxxstl:find(",", 1, true) then
local runtimes_supported = hashset.from(toolchain:get("runtimes"))
for _, item in ipairs(ndk_cxxstl:split(",")) do
if runtimes_supported:has(item) then
ndk_cxxstl = item
break
end
end
end
-- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared
if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then
cxxstl_sdkdir = cxxstl_sdkdir_llvmstl
elseif ndk_cxxstl:startswith("gnustl") then
cxxstl_sdkdir = cxxstl_sdkdir_gnustl
elseif ndk_cxxstl:startswith("stlport") then
cxxstl_sdkdir = cxxstl_sdkdir_stlport
end
else
if isllvm then
ndk_cxxstl = "c++_static"
cxxstl_sdkdir = cxxstl_sdkdir_llvmstl
end
if (cxxstl_sdkdir == nil or not os.isdir(cxxstl_sdkdir)) and cxxstl_sdkdir_gnustl then -- <= ndk r16
ndk_cxxstl = "gnustl_static"
cxxstl_sdkdir = cxxstl_sdkdir_gnustl
end
end
-- only for c++ stl
if config.get("ndk_stdcxx") then
if cxxstl_sdkdir and os.isdir(cxxstl_sdkdir) then
-- the toolchains archs
local toolchains_archs =
{
["armv5te"] = "armeabi" -- deprecated
, ["armv7-a"] = "armeabi-v7a" -- deprecated
, ["armeabi"] = "armeabi" -- removed in ndk r17
, ["armeabi-v7a"] = "armeabi-v7a"
, ["arm64-v8a"] = "arm64-v8a"
, i386 = "x86" -- deprecated
, x86 = "x86"
, x86_64 = "x86_64"
, mips = "mips" -- removed in ndk r17
, mips64 = "mips64" -- removed in ndk r17
}
local toolchains_arch = toolchains_archs[arch]
-- add c++ stl include and link directories
if toolchains_arch then
toolchain:add("linkdirs", format("%s/libs/%s", cxxstl_sdkdir, toolchains_arch))
end
if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then
toolchain:add("cxxflags", "-nostdinc++")
toolchain:add("sysincludedirs", format("%s/include", cxxstl_sdkdir))
if toolchains_arch then
toolchain:add("sysincludedirs", format("%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch))
end
local abi_path = path.join(ndk, "sources", "cxx-stl", "llvm-libc++abi")
local before_r13 = path.join(abi_path, "libcxxabi")
local after_r13 = path.join(abi_path, "include")
if os.isdir(before_r13) then
toolchain:add("sysincludedirs", before_r13)
elseif os.isdir(after_r13) then
toolchain:add("sysincludedirs", after_r13)
end
elseif ndk_cxxstl:startswith("gnustl") then
toolchain:add("cxxflags", "-nostdinc++")
toolchain:add("sysincludedirs", format("%s/include", cxxstl_sdkdir))
if toolchains_arch then
toolchain:add("sysincludedirs", format("%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch))
end
elseif ndk_cxxstl:startswith("stlport") then
toolchain:add("cxxflags", "-nostdinc++")
toolchain:add("sysincludedirs", format("%s/stlport", cxxstl_sdkdir))
end
-- add c++ stl links
if ndk_cxxstl == "c++_static" or ndk_cxxstl == "llvmstl_static" then
toolchain:add("syslinks", "c++_static", "c++abi")
if arm32 then
toolchain:add("syslinks", "unwind", "atomic")
end
elseif ndk_cxxstl == "c++_shared" or ndk_cxxstl == "llvmstl_shared" then
toolchain:add("syslinks", "c++_shared", "c++abi")
if arm32 then
toolchain:add("syslinks", "unwind", "atomic")
end
elseif ndk_cxxstl == "gnustl_static" then
toolchain:add("syslinks", "gnustl_static")
elseif ndk_cxxstl == "gnustl_shared" then
toolchain:add("syslinks", "gnustl_shared")
elseif ndk_cxxstl == "stlport_static" then
toolchain:add("syslinks", "stlport_static")
elseif ndk_cxxstl == "stlport_shared" then
toolchain:add("syslinks", "stlport_shared")
end
-- fix 'ld: error: cannot find -lc++' for clang++.exe on r20/windows
-- @see https://github.com/xmake-io/xmake/issues/684
if ndkver and ndkver >= 20 and (ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl")) then
toolchain:add("ldflags", "-nostdlib++")
toolchain:add("shflags", "-nostdlib++")
end
elseif ndkver and ndkver >= 26 then
-- The NDK's libc++ now comes directly from our LLVM toolchain above 26b
-- https://github.com/xmake-io/xmake/issues/4614
if ndk_cxxstl == "c++_static" then
toolchain:add("ldflags", "-static-libstdc++", "-lc++abi")
toolchain:add("shflags", "-static-libstdc++", "-lc++abi")
if arm32 then
toolchain:add("syslinks", "unwind", "atomic")
end
elseif ndk_cxxstl == "c++_shared" then
if arm32 then
toolchain:add("syslinks", "unwind", "atomic")
end
end
end
end
end
-- init flags for target
local target_on_xxflags = function (target)
if arm32 then
-- @see https://github.com/xmake-io/xmake/issues/927
if target:values("ndk.arm_mode") == "arm" then
return "-marm"
else
return "-mthumb"
end
end
end
toolchain:add("target.on_cxflags", target_on_xxflags)
toolchain:add("target.on_asflags", target_on_xxflags)
toolchain:add("target.on_ldflags", target_on_xxflags)
toolchain:add("target.on_shflags", target_on_xxflags)
local rcshflags = table.copy(toolchain:get("shflags"))
local rcldflags = table.copy(toolchain:get("ldflags"))
for _, link in ipairs(toolchain:get("syslinks")) do
table.insert(rcshflags, "-l" .. link)
table.insert(rcldflags, "-l" .. link)
end
toolchain:add("rcshflags", "-C link-args=\"" .. (table.concat(rcshflags, " "):gsub("%-march=.-%s", "") .. "\""))
toolchain:add("rcldflags", "-C link-args=\"" .. (table.concat(rcldflags, " "):gsub("%-march=.-%s", "") .. "\""))
local sh = toolchain:tool("sh") -- @note we cannot use `config.get("sh")`, because we need to check sh first
if sh then
toolchain:add("rcshflags", "-C linker=" .. sh)
end
local ld = toolchain:tool("ld")
if ld then
toolchain:add("rcldflags", "-C linker=" .. ld)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ndk/xmake.lua | --!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 xmake.lua
--
-- android ndk toolchain
--
-- @param sdkver the platform sdk version
--
-- @code
-- target("test")
-- ...
-- set_toolchains("ndk")
-- set_toolchains("ndk", {sdkver = "23"})
-- @endcode
--
toolchain("ndk")
set_kind("standalone")
set_homepage("https://developer.android.com/ndk")
set_description("Android NDK")
set_runtimes("c++_static", "c++_shared")
on_check("check")
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/ndk/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_ndk")
import("detect.sdks.find_android_sdk")
-- check the ndk toolchain
function _check_ndk(toolchain)
local ndk
for _, package in ipairs(toolchain:packages()) do
local installdir = package:installdir()
if installdir and os.isdir(installdir) then
ndk = find_ndk(installdir, {force = true, verbose = option.get("verbose"),
plat = toolchain:plat(),
arch = toolchain:arch(),
sdkver = toolchain:config("sdkver")})
if ndk then
break
end
end
end
if not ndk then
ndk = find_ndk(toolchain:config("ndk") or config.get("ndk"), {force = true, verbose = true,
plat = toolchain:plat(),
arch = toolchain:arch(),
sdkver = toolchain:config("sdkver")})
end
if ndk then
toolchain:config_set("ndk", ndk.sdkdir)
toolchain:config_set("bindir", ndk.bindir)
toolchain:config_set("cross", ndk.cross)
toolchain:config_set("llvm_toolchain", ndk.llvm_toolchain)
toolchain:config_set("gcc_toolchain", ndk.gcc_toolchain)
toolchain:config_set("ndkver", ndk.ndkver)
toolchain:config_set("ndk_sdkver", ndk.sdkver)
toolchain:config_set("ndk_toolchains_ver", ndk.toolchains_ver)
toolchain:config_set("ndk_sysroot", ndk.sysroot)
toolchain:configs_save()
return true
else
--[[TODO we also need to add this tips when use remote ndk toolchain
-- failed
cprint("${bright color.error}please run:")
cprint(" - xmake config --ndk=xxx")
cprint("or - xmake global --ndk=xxx")
raise()]]
end
end
-- check the android sdk
function _check_android_sdk(toolchain)
local sdk = find_android_sdk(toolchain:config("android_sdk") or config.get("android_sdk"), {force = true, verbose = toolchain:is_global()})
if sdk then
toolchain:config_set("android_sdk", sdk.sdkdir)
toolchain:config_set("build_toolver", sdk.build_toolver)
toolchain:configs_save()
end
end
-- main entry
function main(toolchain)
_check_android_sdk(toolchain)
return _check_ndk(toolchain)
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/go/xmake.lua | --!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 xmake.lua
--
-- define toolchain
toolchain("go")
-- set homepage
set_homepage("https://golang.org/")
set_description("Go Programming Language Compiler")
-- set toolset
set_toolset("gc", "$(env GC)", "go", "gccgo")
set_toolset("gcld", "$(env GC)", "go", "gccgo")
set_toolset("gcar", "$(env GC)", "go", "gccgo")
-- on load
on_load(function (toolchain)
if not toolchain:is_plat(os.host()) or not toolchain:is_arch(os.arch()) then
import("private.tools.go.goenv")
local goos = goenv.GOOS(toolchain:plat())
if goos then
toolchain:add("runenvs", "GOOS", goos)
end
local goarch = goenv.GOARCH(toolchain:arch())
if goarch then
toolchain:add("runenvs", "GOARCH", goarch)
end
end
toolchain:set("gcldflags", "")
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-cl/load.lua | --!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 load.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("detect.sdks.find_vstudio")
-- add the given vs environment
function _add_vsenv(toolchain, name, curenvs)
-- get vcvars
local vcvars = toolchain:config("vcvars")
if not vcvars then
return
end
-- get the paths for the vs environment
local new = vcvars[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unwrap(path.splitenv(new)))
end
end
-- main entry
function main(toolchain)
-- set toolset
toolchain:set("toolset", "cc", "clang-cl.exe")
toolchain:set("toolset", "cxx", "clang-cl.exe")
toolchain:set("toolset", "mrc", "rc.exe")
if toolchain:is_arch("x64") then
toolchain:set("toolset", "as", "ml64.exe")
else
toolchain:set("toolset", "as", "ml.exe")
end
toolchain:set("toolset", "ld", "link.exe")
toolchain:set("toolset", "sh", "link.exe")
toolchain:set("toolset", "ar", "link.exe")
-- add vs environments
local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"}
local curenvs = os.getenvs()
for _, name in ipairs(expect_vars) do
_add_vsenv(toolchain, name, curenvs)
end
for _, name in ipairs(find_vstudio.get_vcvars()) do
if not table.contains(expect_vars, name:upper()) then
_add_vsenv(toolchain, name, curenvs)
end
end
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("mxflags", march)
toolchain:add("asflags", march)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-cl/xmake.lua | --!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 xmake.lua
--
-- clang-cl toolchain
--
-- @param vs the vs version
--
-- @code
-- target("test")
-- ...
-- set_toolchains("clang-cl")
-- set_toolchains("clang-cl", {vs = "2019"})
-- @endcode
--
toolchain("clang-cl")
set_kind("standalone")
set_homepage("https://visualstudio.microsoft.com")
set_description("LLVM Clang C/C++ Compiler compatible with msvc")
set_runtimes("MT", "MTd", "MD", "MDd")
on_check("check")
on_load("load")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/clang-cl/check.lua | --!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.base.option")
import("core.project.config")
import("detect.sdks.find_vstudio")
import("lib.detect.find_tool")
-- attempt to check vs environment
function _check_vsenv(toolchain)
-- has been checked?
local vs = toolchain:config("vs") or config.get("vs")
if vs then
vs = tostring(vs)
end
local vcvars = toolchain:config("vcvars")
if vs and vcvars then
return vs
end
-- find vstudio
local vs_toolset = toolchain:config("vs_toolset") or config.get("vs_toolset")
local vs_sdkver = toolchain:config("vs_sdkver") or config.get("vs_sdkver")
local vstudio = find_vstudio({vcvars_ver = vs_toolset, sdkver = vs_sdkver})
if vstudio then
-- make order vsver
local vsvers = {}
for vsver, _ in pairs(vstudio) do
if not vs or vs ~= vsver then
table.insert(vsvers, vsver)
end
end
table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end)
if vs then
table.insert(vsvers, 1, vs)
end
-- get vcvarsall
for _, vsver in ipairs(vsvers) do
local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {}
local vcvars = vcvarsall[toolchain:arch()]
if vcvars and vcvars.PATH and vcvars.INCLUDE and vcvars.LIB then
-- save vcvars
toolchain:config_set("vcvars", vcvars)
toolchain:config_set("vcarchs", table.orderkeys(vcvarsall))
toolchain:config_set("vs_toolset", vcvars.VCToolsVersion)
toolchain:config_set("vs_sdkver", vcvars.WindowsSDKVersion)
-- check compiler
local program
local paths
local pathenv = os.getenv("PATH")
if pathenv then
paths = path.splitenv(pathenv)
end
local tool = find_tool("clang-cl.exe", {version = true, force = true, paths = paths, envs = vcvars})
if tool then
program = tool.program
end
if program then
return vsver, tool
end
end
end
end
end
-- check the visual studio
function _check_vstudio(toolchain)
local vs, clang_cl = _check_vsenv(toolchain)
if vs then
if toolchain:is_global() then
config.set("vs", vs, {force = true, readonly = true})
end
toolchain:config_set("vs", vs)
toolchain:configs_save()
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs)
if clang_cl and clang_cl.version then
cprint("checking for LLVM Clang C/C++ Compiler (%s) version ... ${color.success}%s", toolchain:arch(), clang_cl.version)
end
else
cprint("checking for Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", toolchain:arch())
end
return vs
end
-- main entry
function main(toolchain)
-- only for windows
if not is_host("windows") then
return
end
-- @see https://github.com/xmake-io/xmake/pull/679
local cc = path.basename(config.get("cc") or "clang-cl"):lower()
local cxx = path.basename(config.get("cxx") or "clang-cl"):lower()
local mrc = path.basename(config.get("mrc") or "rc"):lower()
if cc == "clang-cl" or cxx == "clang-cl" or mrc == "rc" then
return _check_vstudio(toolchain)
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/emcc/xmake.lua | --!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 xmake.lua
--
toolchain("emcc")
set_homepage("http://emscripten.org")
set_description("A toolchain for compiling to asm.js and WebAssembly")
set_kind("standalone")
local suffix = is_host("windows") and ".bat" or ""
set_toolset("cc", "emcc" .. suffix)
set_toolset("cxx", "emcc" .. suffix, "em++" .. suffix)
set_toolset("ld", "em++" .. suffix, "emcc" .. suffix)
set_toolset("sh", "em++" .. suffix, "emcc" .. suffix)
set_toolset("ar", "emar" .. suffix)
set_toolset("as", "emcc" .. suffix)
set_toolset("ranlib", "emranlib" .. suffix)
on_check(function (toolchain)
import("lib.detect.find_tool")
import("detect.sdks.find_emsdk")
for _, package in ipairs(toolchain:packages()) do
local installdir = package:installdir()
if installdir and os.isdir(installdir) then
local emsdk = find_emsdk(installdir)
if emsdk then
toolchain:config_set("bindir", emsdk.emscripten)
toolchain:config_set("sdkdir", emsdk.sdkdir)
toolchain:configs_save()
return emsdk
end
end
end
return find_tool("emcc")
end)
on_load(function (toolchain)
toolchain:add("cxflags", "")
toolchain:add("asflags", "")
toolchain:add("ldflags", "")
toolchain:add("shflags", "")
for _, package in ipairs(toolchain:packages()) do
local envs = package:envs()
if envs then
for _, name in ipairs({"EMSDK", "EMSDK_NODE", "EMSDK_PYTHON", "JAVA_HOME"}) do
local values = envs[name]
if values then
toolchain:add("runenvs", name, table.unwrap(values))
end
end
end
end
end)
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-14/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("14")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/gcc-9/xmake.lua | includes(path.join(os.scriptdir(), "../gcc/xmake.lua"))
toolchain_gcc("9")
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/msvc/load.lua | --!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 load.lua
--
-- imports
import("core.base.option")
import("core.base.semver")
import("core.project.config")
import("detect.sdks.find_vstudio")
-- add the given vs environment
function _add_vsenv(toolchain, name, curenvs)
-- get vcvars
local vcvars = toolchain:config("vcvars")
if not vcvars then
return
end
-- get the paths for the vs environment
local new = vcvars[name]
if new then
-- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
-- @see https://github.com/xmake-io/xmake/issues/4751
for k, c in pairs(curenvs) do
if name:lower() == k:lower() and name ~= k then
name = k
break
end
end
toolchain:add("runenvs", name, table.unwrap(path.splitenv(new)))
end
end
-- main entry
function main(toolchain)
-- set toolset
toolchain:set("toolset", "cc", "cl.exe")
toolchain:set("toolset", "cxx", "cl.exe")
toolchain:set("toolset", "mrc", "rc.exe")
if toolchain:is_arch("x86") then
toolchain:set("toolset", "as", "ml.exe")
elseif toolchain:is_arch("arm64", "arm64ec") then
toolchain:set("toolset", "as", "[email protected]")
elseif toolchain:is_arch("arm.*") then
toolchain:set("toolset", "as", "[email protected]")
else
toolchain:set("toolset", "as", "ml64.exe")
end
toolchain:set("toolset", "ld", "link.exe")
toolchain:set("toolset", "sh", "link.exe")
toolchain:set("toolset", "ar", "link.exe")
-- init flags
if toolchain:is_arch("arm64ec") then
toolchain:add("cxflags", "/arm64EC")
end
-- add vs environments
local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"}
local curenvs = os.getenvs()
for _, name in ipairs(expect_vars) do
_add_vsenv(toolchain, name, curenvs)
end
for _, name in ipairs(find_vstudio.get_vcvars()) do
if not table.contains(expect_vars, name:upper()) then
_add_vsenv(toolchain, name, curenvs)
end
end
-- check and add vs_binary_output env
local vs = toolchain:config("vs")
if vs and semver.is_valid(vs) and semver.compare(vs, "2005") < 0 then
toolchain:add("runenvs", "VS_BINARY_OUTPUT", "1")
end
end
|
0 | repos/xmake/xmake/toolchains | repos/xmake/xmake/toolchains/msvc/xmake.lua | --!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 xmake.lua
--
-- msvc toolchain
--
-- @param vs the vs version
--
-- @code
-- target("test")
-- ...
-- set_toolchains("msvc")
-- set_toolchains("msvc", {vs = "2019"})
-- @endcode
--
toolchain("msvc")
set_kind("standalone")
set_homepage("https://visualstudio.microsoft.com")
set_description("Microsoft Visual C/C++ Compiler")
set_runtimes("MT", "MTd", "MD", "MDd")
on_check("check")
on_load("load")
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.