summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-17 10:59:28 +0800
committerGitHub <[email protected]>2020-12-17 10:59:28 +0800
commite95f99d7d99daf3c065dd04d457b2a8a81545380 (patch)
tree72816b1c749dd12e31da06b9b9d97ffc8d057866 /xmake/modules
parent37521d4aa857d57773b0f6cb9311856d3787c6f5 (diff)
parent98a044d2947d070d035fe76c651fdbf9f0c3b135 (diff)
Merge pull request #1141 from xmake-io/toolchain
Improve toolchain
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/detect/sdks/find_dotnet.lua17
-rw-r--r--xmake/modules/detect/sdks/find_wdk.lua22
-rw-r--r--xmake/modules/detect/sdks/find_xcode.lua120
-rw-r--r--xmake/modules/detect/tools/find_devenv.lua12
-rw-r--r--xmake/modules/detect/tools/find_lib.lua4
-rw-r--r--xmake/modules/detect/tools/find_rc.lua16
-rw-r--r--xmake/modules/package/manager/conan/install_package.lua7
-rw-r--r--xmake/modules/private/detect/find_platform.lua146
8 files changed, 227 insertions, 117 deletions
diff --git a/xmake/modules/detect/sdks/find_dotnet.lua b/xmake/modules/detect/sdks/find_dotnet.lua
index bb8180f57..284925f04 100644
--- a/xmake/modules/detect/sdks/find_dotnet.lua
+++ b/xmake/modules/detect/sdks/find_dotnet.lua
@@ -21,6 +21,7 @@
-- imports
import("lib.detect.cache")
import("lib.detect.find_file")
+import("core.tool.toolchain")
import("core.base.option")
import("core.base.global")
import("core.project.config")
@@ -28,14 +29,16 @@ import("core.project.config")
-- find dotnet directory
function _find_sdkdir(sdkdir)
- -- get sdk directory from vsvars
+ -- get sdk directory from vcvars
if not sdkdir then
- local arch = config.arch()
- local vcvarsall = config.get("__vcvarsall")
- if vcvarsall then
- sdkdir = (vcvarsall[arch] or {}).WindowsSdkDir
- if sdkdir then
- sdkdir = path.join(path.directory(path.translate(sdkdir)), "NETFXSDK")
+ local msvc = toolchain.load("msvc")
+ if msvc and msvc:check() then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ sdkdir = vcvars.WindowsSdkDir
+ if sdkdir then
+ sdkdir = path.join(path.directory(path.translate(sdkdir)), "NETFXSDK")
+ end
end
end
end
diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua
index f91e9a1b7..d9844146a 100644
--- a/xmake/modules/detect/sdks/find_wdk.lua
+++ b/xmake/modules/detect/sdks/find_wdk.lua
@@ -24,6 +24,7 @@ import("lib.detect.find_file")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.tool.toolchain")
import("detect.sdks.find_vstudio")
-- find WDK directory
@@ -34,24 +35,15 @@ function _find_sdkdir(sdkdir)
sdkdir = os.getenv("WindowsSdkDir")
end
- -- get sdk directory from vsvars
+ -- get sdk directory from vcvars
if not sdkdir then
- local arch = config.arch() or os.arch()
- local vcvarsall = config.get("__vcvarsall")
- if not vcvarsall then
- local vstudio = find_vstudio()
- if vstudio then
- for _, vsinfo in pairs(vstudio) do
- if vsinfo.vcvarsall then
- vcvarsall = vsinfo.vcvarsall
- break
- end
- end
+ local msvc = toolchain.load("msvc")
+ if msvc and msvc:check() then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ sdkdir = vcvars.WindowsSdkDir
end
end
- if vcvarsall then
- sdkdir = (vcvarsall[arch] or {}).WindowsSdkDir
- end
end
return sdkdir
end
diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua
index 1177685a5..4e7a1f677 100644
--- a/xmake/modules/detect/sdks/find_xcode.lua
+++ b/xmake/modules/detect/sdks/find_xcode.lua
@@ -27,7 +27,7 @@ import("lib.detect.find_directory")
import("private.tools.codesign")
-- find xcode directory
-function _find_sdkdir(sdkdir)
+function _find_sdkdir(sdkdir, opt)
if sdkdir and os.isdir(sdkdir) then
return sdkdir
end
@@ -35,9 +35,11 @@ function _find_sdkdir(sdkdir)
end
-- find the sdk version of xcode
-function _find_xcode_sdkver(sdkdir, plat, arch)
+function _find_xcode_sdkver(sdkdir, opt)
-- select platform sdkdir
+ local plat = opt.plat
+ local arch = opt.arch
local platsdkdir = nil
if plat == "iphoneos" then
if arch == "i386" or arch == "x86_64" then
@@ -65,52 +67,56 @@ function _find_xcode_sdkver(sdkdir, plat, arch)
end
-- find the xcode toolchain
-function _find_xcode(sdkdir, xcode_sdkver, plat, arch)
+function _find_xcode(sdkdir, opt)
-- find xcode root directory
- sdkdir = _find_sdkdir(sdkdir)
+ sdkdir = _find_sdkdir(sdkdir, opt)
if not sdkdir then
return {}
end
-- find the sdk version
- local sdkver = xcode_sdkver or _find_xcode_sdkver(sdkdir, plat, arch)
+ local sdkver = opt.sdkver or _find_xcode_sdkver(sdkdir, opt)
if not sdkver then
return {}
end
- -- find codesign identity
- local codesign_identity = config.get("xcode_codesign_identity")
- if codesign_identity == nil then -- we will disable codesign_identity if be false
- codesign_identity = global.get("xcode_codesign_identity")
- end
- if codesign_identity == nil then
- local codesign_identities = codesign.codesign_identities()
- if codesign_identities then
- for identity, _ in pairs(codesign_identities) do
- codesign_identity = identity
- break
+ -- find codesign
+ if opt.find_codesign then
+
+ -- find codesign identity
+ local codesign_identity = config.get("xcode_codesign_identity")
+ if codesign_identity == nil then -- we will disable codesign_identity if be false
+ codesign_identity = global.get("xcode_codesign_identity")
+ end
+ if codesign_identity == nil then
+ local codesign_identities = codesign.codesign_identities()
+ if codesign_identities then
+ for identity, _ in pairs(codesign_identities) do
+ codesign_identity = identity
+ break
+ end
end
end
- end
- -- find mobile provision only for iphoneos
- local mobile_provision
- if is_plat("iphoneos") then
- local mobile_provisions = codesign.mobile_provisions()
- if mobile_provisions then
- mobile_provision = config.get("xcode_mobile_provision")
- if mobile_provision == nil then -- we will disable mobile_provision if be false
- mobile_provision = global.get("xcode_mobile_provision")
- end
- if mobile_provision == nil then
- for provision, _ in pairs(mobile_provisions) do
- mobile_provision = provision
- break
+ -- find mobile provision only for iphoneos
+ local mobile_provision
+ if opt.plat == "iphoneos" then
+ local mobile_provisions = codesign.mobile_provisions()
+ if mobile_provisions then
+ mobile_provision = config.get("xcode_mobile_provision")
+ if mobile_provision == nil then -- we will disable mobile_provision if be false
+ mobile_provision = global.get("xcode_mobile_provision")
+ end
+ if mobile_provision == nil then
+ for provision, _ in pairs(mobile_provisions) do
+ mobile_provision = provision
+ break
+ end
+ -- valid mobile provision not found? reset it
+ elseif not mobile_provisions[mobile_provision] then
+ mobile_provision = nil
end
- -- valid mobile provision not found? reset it
- elseif not mobile_provisions[mobile_provision] then
- mobile_provision = nil
end
end
end
@@ -121,7 +127,7 @@ end
--
-- @param sdkdir the xcode directory
-- @param opt the argument options
--- e.g. {verbose = true, force = false, sdkver = 19, toolchains_ver = "4.9"}
+-- e.g. {verbose = true, force = false, sdkver = 19, find_codesign = true}
--
-- @return the xcode toolchain. e.g. {bindir = .., cross = ..}
--
@@ -144,54 +150,14 @@ function main(sdkdir, opt)
end
-- get plat and arch
- local plat = opt.plat or config.get("plat") or "macosx"
- local arch = opt.arch or config.get("arch") or "x86_64"
-
- -- get xcode sdk version
- local xcode_sdkver = (plat == config.plat()) and config.get("xcode_sdkver")
- if not xcode_sdkver then
- xcode_sdkver = config.get("xcode_sdkver_" .. plat)
- end
+ local plat = opt.plat or config.get("plat") or os.host()
+ local arch = opt.arch or config.get("arch") or os.arch()
-- find xcode
- local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver or xcode_sdkver, plat, arch)
- if xcode and xcode.sdkdir then
-
- -- save to config
- config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
- config.set("xcode_sdkver_" .. plat, xcode.sdkver, {force = true, readonly = true})
- config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true})
- config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true})
-
- -- trace
- if opt.verbose or option.get("verbose") then
- cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir)
- cprint("checking for SDK version of Xcode ... ${color.success}%s", xcode.sdkver)
- 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 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
- else
-
- -- trace
- if opt.verbose or option.get("verbose") then
- cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}")
- end
- end
+ local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt)
-- save to cache
cacheinfo.xcode = xcode or false
cache.save(key, cacheinfo)
-
- -- ok?
return xcode
end
diff --git a/xmake/modules/detect/tools/find_devenv.lua b/xmake/modules/detect/tools/find_devenv.lua
index 745c26099..1111c92a3 100644
--- a/xmake/modules/detect/tools/find_devenv.lua
+++ b/xmake/modules/detect/tools/find_devenv.lua
@@ -20,6 +20,7 @@
-- imports
import("core.project.config")
+import("core.tool.toolchain")
-- find devenv
--
@@ -48,11 +49,12 @@ function main(opt)
-- e.g. C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
--
local program = nil
- local vcvarsall = config.get("__vcvarsall")
- if vcvarsall then
- for _, vsvars in pairs(vcvarsall) do
- if vsvars.DevEnvdir and os.isexec(path.join(vsvars.DevEnvdir, "devenv.exe")) then
- program = path.join(vsvars.DevEnvdir, "devenv.exe")
+ local msvc = toolchain.load("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ if vcvars.DevEnvdir and os.isexec(path.join(vcvars.DevEnvdir, "devenv.exe")) then
+ program = path.join(vcvars.DevEnvdir, "devenv.exe")
end
end
end
diff --git a/xmake/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua
index f3c5806ee..b01960e25 100644
--- a/xmake/modules/detect/tools/find_lib.lua
+++ b/xmake/modules/detect/tools/find_lib.lua
@@ -51,8 +51,8 @@ function main(opt)
io.writefile(sourcefile, "int test(void)\n{return 0;}")
-- check it
- local cl = assert(find_tool("cl"))
- local link = assert(find_tool("link"))
+ local cl = assert(find_tool("cl", {envs = opt.envs}))
+ local link = assert(find_tool("link", {envs = opt.envs}))
os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs})
os.runv(link.program, {"-lib", "-out:" .. libraryfile, objectfile}, {envs = opt.envs})
verinfo = os.iorunv(program, {"-list", libraryfile}, {envs = opt.envs})
diff --git a/xmake/modules/detect/tools/find_rc.lua b/xmake/modules/detect/tools/find_rc.lua
index 5edd8d69c..a36cd25bb 100644
--- a/xmake/modules/detect/tools/find_rc.lua
+++ b/xmake/modules/detect/tools/find_rc.lua
@@ -57,16 +57,12 @@ function main(opt)
--
-- e.g. C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64
--
- local arch = opt.arch or config.arch() or os.arch()
- local vcvarsall = config.get("__vcvarsall")
- if vcvarsall then
- local vcvars = vcvarsall[arch]
- if vcvars and vcvars.WindowsSdkDir and vcvars.WindowsSDKVersion then
- local bindir = path.join(vcvars.WindowsSdkDir, "bin", vcvars.WindowsSDKVersion, arch)
- if os.isdir(bindir) then
- opt.paths = opt.paths or {}
- table.insert(opt.paths, bindir)
- end
+ local envs = opt.envs
+ if envs and envs.WindowsSdkDir and envs.WindowsSDKVersion then
+ local bindir = path.join(envs.WindowsSdkDir, "bin", envs.WindowsSDKVersion, arch)
+ if os.isdir(bindir) then
+ opt.paths = opt.paths or {}
+ table.insert(opt.paths, bindir)
end
end
diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua
index 8e7561826..cc7721527 100644
--- a/xmake/modules/package/manager/conan/install_package.lua
+++ b/xmake/modules/package/manager/conan/install_package.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.option")
import("core.project.config")
+import("core.tool.toolchain")
import("core.platform.platform")
import("lib.detect.find_tool")
import("devel.git")
@@ -219,7 +220,11 @@ function main(name, opt)
table.insert(argv, "compiler.runtime=" .. opt.vs_runtime)
end
elseif opt.plat == "iphoneos" then
- local target_minver = config.get("target_minver_iphoneos")
+ local target_minver = nil
+ local toolchain_xcode = toolchain.load("xcode", {plat = opt.plat, arch = opt.arch})
+ if toolchain_xcode then
+ target_minver = toolchain_xcode:config("target_minver")
+ end
if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "x86") then
target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets
end
diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua
new file mode 100644
index 000000000..d366260b6
--- /dev/null
+++ b/xmake/modules/private/detect/find_platform.lua
@@ -0,0 +1,146 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_platform.lua
+--
+
+-- imports
+import("core.project.config")
+import("detect.sdks.find_cross_toolchain")
+
+-- find platform
+function _find_plat(plat)
+ plat = plat or config.get("plat")
+ if not plat then
+ plat = os.subhost()
+ if plat == "msys" then
+ local msystem = os.getenv("MSYSTEM")
+ if msystem and msystem:lower():find("mingw", 1, true) then
+ plat = "mingw"
+ end
+ end
+ end
+ return plat
+end
+
+-- find architecture for cross platform
+function _find_arch_from_cross()
+ local cross = config.get("cross")
+ if not cross then
+ local cross_toolchain = find_cross_toolchain(config.get("sdk"), {bindir = config.get("bin")})
+ if cross_toolchain then
+ cross = cross_toolchain.cross
+ end
+ end
+ local arch = "none"
+ if cross then
+ if cross:find("aarch64", 1, true) then
+ arch = "arm64"
+ elseif cross:find("arm", 1, true) then
+ arch = "arm"
+ elseif cross:find("mips64", 1, true) then
+ arch = "mips64"
+ elseif cross:find("mips", 1, true) then
+ arch = "mips"
+ elseif cross:find("riscv64", 1, true) then
+ arch = "riscv64"
+ elseif cross:find("riscv", 1, true) then
+ arch = "riscv"
+ elseif cross:find("s390x", 1, true) then
+ arch = "s390x"
+ elseif cross:find("powerpc64", 1, true) then
+ arch = "ppc64"
+ elseif cross:find("powerpc", 1, true) then
+ arch = "ppc"
+ elseif cross:find("sh4", 1, true) then
+ arch = "sh4"
+ elseif cross:find("x86_64", 1, true) then
+ arch = "x86_64"
+ elseif cross:find("i386", 1, true) or cross:find("i686", 1, true) then
+ arch = "i386"
+ end
+ end
+ return arch
+end
+
+-- find architecture
+function _find_arch(plat, arch)
+ arch = arch or config.get("arch")
+ if not arch then
+ if plat == "android" then
+ arch = "armeabi-v7a"
+ elseif plat == "iphoneos" then
+ arch = "arm64"
+ elseif plat == "watchos" then
+ arch = "armv7k"
+ elseif plat == "wasm" then
+ arch = "wasm32"
+ elseif plat == "mingw" then
+ local mingw_chost = nil
+ if is_subhost("msys") then
+ mingw_chost = os.getenv("MINGW_CHOST")
+ end
+ if mingw_chost == "i686-w64-mingw32" then
+ arch = "i386"
+ else
+ arch = "x86_64"
+ end
+ elseif plat == "cross" then
+ arch = _find_arch_from_cross()
+ else
+ arch = os.subarch()
+ end
+ end
+ return arch
+end
+
+-- find default platform and architecture
+--
+-- @param opt the argument options, e.g. {plat = "", arch = "", global = true}
+--
+-- @return plat, arch
+--
+-- @code
+--
+-- find the default platform:
+-- local result = find_platform()
+--
+-- find the default architecture from the given platform:
+-- local result = find_platform({plat = "iphoneos"})
+--
+-- @endcode
+--
+function main(opt)
+
+ -- find plat and arch
+ opt = opt or {}
+ local plat = _find_plat(opt.plat)
+ local arch = _find_arch(plat, opt.arch)
+
+ -- save the local configuration if be global
+ if opt.global then
+ if not opt.plat and not config.get("plat") then
+ config.set("plat", plat)
+ cprint("checking for platform ... ${color.success}%s", plat)
+ end
+ if not opt.arch and not config.get("arch") then
+ config.set("arch", arch)
+ cprint("checking for architecture ... ${color.success}%s", arch)
+ end
+ end
+ return plat, arch
+end