diff options
| author | ruki <[email protected]> | 2020-06-23 22:37:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-06-23 22:37:44 +0800 |
| commit | c18d15eb89116a0f3ce96bd56f3ccf861849f6ec (patch) | |
| tree | 52b63db3274349f9a41872414208c7c30058cfd7 /xmake/toolchains | |
| parent | 53df324acd9c7432336a5894ceef578daa1ce38d (diff) | |
| parent | 18bded45c229f5580c13fc8b4afc5edb6f18819a (diff) | |
Merge pull request #857 from xmake-io/toolchain
Improve toolchain to support host and cross toolchains at same time
Diffstat (limited to 'xmake/toolchains')
| -rw-r--r-- | xmake/toolchains/clang/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/dlang/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/gcc/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/check.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/toolchains/mingw/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/check.lua (renamed from xmake/toolchains/vs/check.lua) | 28 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/load.lua (renamed from xmake/toolchains/vs/load.lua) | 10 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/xmake.lua (renamed from xmake/toolchains/vs/xmake.lua) | 4 | ||||
| -rw-r--r-- | xmake/toolchains/nasm/xmake.lua | 12 | ||||
| -rw-r--r-- | xmake/toolchains/ndk/load.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/sdcc/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/check.lua | 25 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_watchos.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/toolchains/yasm/xmake.lua | 12 |
18 files changed, 78 insertions, 75 deletions
diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 1319d9899..c616a4023 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -50,9 +50,9 @@ toolchain("clang") -- add march flags local march - if is_arch("x86_64", "x64") then + if toolchain:is_arch("x86_64", "x64") then march = "-m64" - elseif is_arch("i386", "x86") then + elseif toolchain:is_arch("i386", "x86") then march = "-m32" end if march then @@ -64,7 +64,7 @@ toolchain("clang") end -- add includedirs and linkdirs - if not is_plat("windows") and os.isdir("/usr") then + if not toolchain:is_plat("windows") and os.isdir("/usr") then for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do if os.isdir(includedir) then toolchain:add("includedirs", includedir) diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua index 0c87d8505..e258e9af8 100644 --- a/xmake/toolchains/dlang/xmake.lua +++ b/xmake/toolchains/dlang/xmake.lua @@ -33,7 +33,7 @@ toolchain("dlang") -- on load on_load(function (toolchain) - local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + local march = toolchain:is_arch("x86_64", "x64") and "-m64" or "-m32" toolchain:add("dcflags", march) toolchain:add("dcshflags", march) toolchain:add("dcldflags", march) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index ab12fd13a..8a4a53bb5 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -50,9 +50,9 @@ toolchain("gcc") -- add march flags local march - if is_arch("x86_64", "x64") then + if toolchain:is_arch("x86_64", "x64") then march = "-m64" - elseif is_arch("i386", "x86") then + elseif toolchain:is_arch("i386", "x86") then march = "-m32" end if march then @@ -64,7 +64,7 @@ toolchain("gcc") end -- add includedirs and linkdirs - if not is_plat("windows") and os.isdir("/usr") then + if not toolchain:is_plat("windows") and os.isdir("/usr") then for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do if os.isdir(includedir) then toolchain:add("includedirs", includedir) diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua index 04d4d6dec..d590b4381 100644 --- a/xmake/toolchains/llvm/check.lua +++ b/xmake/toolchains/llvm/check.lua @@ -29,7 +29,7 @@ function main(toolchain) local sdkdir = config.get("sdk") local bindir = config.get("bin") if not sdkdir and not bindir then - if is_plat("linux") and os.isfile("/usr/bin/llvm-ar") then + if toolchain:is_plat("linux") and os.isfile("/usr/bin/llvm-ar") then sdkdir = "/usr" end end diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index d4371682c..3912ab8d7 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -48,9 +48,9 @@ toolchain("llvm") -- add march flags local march - if is_arch("x86_64", "x64") then + if toolchain:is_arch("x86_64", "x64") then march = "-m64" - elseif is_arch("i386", "x86") then + elseif toolchain:is_arch("i386", "x86") then march = "-m32" end if march then diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua index 2d246553a..e5603527f 100644 --- a/xmake/toolchains/mingw/xmake.lua +++ b/xmake/toolchains/mingw/xmake.lua @@ -39,9 +39,9 @@ toolchain("mingw") -- get cross local cross - if is_arch("x86_64") then + if toolchain:is_arch("x86_64") then cross = "x86_64-w64-mingw32-" - elseif is_arch("i386") then + elseif toolchain:is_arch("i386") then cross = "i686-w64-mingw32-" else cross = config.get("cross") or "" @@ -75,7 +75,7 @@ toolchain("mingw") -- init flags for architecture local archflags = nil - local arch = config.get("arch") + local arch = toolchain:arch() if arch then if arch == "x86_64" then archflags = "-m64" elseif arch == "i386" then archflags = "-m32" diff --git a/xmake/toolchains/vs/check.lua b/xmake/toolchains/msvc/check.lua index 12fac2aa0..d4861e16d 100644 --- a/xmake/toolchains/vs/check.lua +++ b/xmake/toolchains/msvc/check.lua @@ -25,7 +25,7 @@ import("detect.sdks.find_vstudio") import("lib.detect.find_tool") -- attempt to check vs environment -function _check_vsenv() +function _check_vsenv(toolchain) -- have been checked? local vs = config.get("vs") @@ -52,28 +52,18 @@ function _check_vsenv() -- get vcvarsall for _, vsver in ipairs(vsvers) do local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {} - local vsenv = vcvarsall[config.get("arch") or ""] + local vsenv = vcvarsall[toolchain:arch()] if vsenv and vsenv.path and vsenv.include and vsenv.lib then -- save vsenv config.set("__vcvarsall", vcvarsall) -- check compiler - local oldenvs = {} - oldenvs.PATH = os.getenv("PATH") - oldenvs.LIB = os.getenv("LIB") - os.setenv("PATH", vsenv.path .. ';' .. (oldenvs.PATH or "")) - os.setenv("LIB", vsenv.lib .. ';' .. (oldenvs.LIB or "")) local program = nil - local tool = find_tool("cl.exe", {force = true}) + local tool = find_tool("cl.exe", {force = true, envs = vsenv}) if tool then program = tool.program end - for name, values in pairs(oldenvs) do - os.setenv(name, values) - end - - -- ok? if program then return vsver end @@ -83,13 +73,13 @@ function _check_vsenv() end -- check the visual studio -function _check_vstudio() - local vs = _check_vsenv() +function _check_vstudio(toolchain) + local vs = _check_vsenv(toolchain) if vs then config.set("vs", vs, {readonly = true, force = true}) - cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.success}%s", config.get("arch"), vs) + cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs) else - cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", config.get("arch")) + cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", toolchain:arch()) if not (opt and opt.try) then print("please run:") print(" - xmake config --vs=xxx [--vs_toolset=xxx]") @@ -101,13 +91,13 @@ function _check_vstudio() end -- main entry -function main() +function main(toolchain) -- @see https://github.com/xmake-io/xmake/pull/679 local cc = path.basename(config.get("cc") or "cl"):lower() local cxx = path.basename(config.get("cxx") or "cl"):lower() local mrc = path.basename(config.get("mrc") or "rc"):lower() if cc == "cl" or cxx == "cl" or mrc == "rc" then - return _check_vstudio(config) + return _check_vstudio(toolchain) end end diff --git a/xmake/toolchains/vs/load.lua b/xmake/toolchains/msvc/load.lua index af32ca092..3b25a298f 100644 --- a/xmake/toolchains/vs/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -32,10 +32,8 @@ function _add_vsenv(toolchain, name) return end - -- get arch - local arch = config.get("arch") or "" - -- get vs environment for the current arch + local arch = toolchain:arch() local vsenv = vcvarsall[arch] or {} -- switch vstudio environment if vs_sdkver has been changed @@ -71,14 +69,14 @@ function main(toolchain) toolchain:set("toolset", "cc", "cl.exe") toolchain:set("toolset", "cxx", "cl.exe") toolchain:set("toolset", "mrc", "rc.exe") - if is_arch("x64") then + 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 -dll") - toolchain:set("toolset", "ar", "link.exe -lib") + toolchain:set("toolset", "sh", "link.exe") + toolchain:set("toolset", "ar", "link.exe") toolchain:set("toolset", "ex", "lib.exe") -- add vs environments diff --git a/xmake/toolchains/vs/xmake.lua b/xmake/toolchains/msvc/xmake.lua index 4bbc5798c..b9f80cdc1 100644 --- a/xmake/toolchains/vs/xmake.lua +++ b/xmake/toolchains/msvc/xmake.lua @@ -19,11 +19,11 @@ -- -- define toolchain -toolchain("vs") +toolchain("msvc") -- set homepage set_homepage("https://visualstudio.microsoft.com") - set_description("VisualStudio IDE") + set_description("Microsoft Visual C/C++ Compiler") -- mark as standalone toolchain set_kind("standalone") diff --git a/xmake/toolchains/nasm/xmake.lua b/xmake/toolchains/nasm/xmake.lua index 164eaedd8..3d31a1e93 100644 --- a/xmake/toolchains/nasm/xmake.lua +++ b/xmake/toolchains/nasm/xmake.lua @@ -30,11 +30,11 @@ toolchain("nasm") -- on load on_load(function (toolchain) - if is_plat("macosx") then - toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") - elseif is_plat("linux", "bsd") then - toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") - elseif is_plat("windows", "mingw", "msys", "cygwin") then - toolchain:add("nasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + if toolchain:is_plat("macosx") then + toolchain:add("nasm.asflags", "-f", toolchain:is_arch("x86_64") and "macho64" or "macho32") + elseif toolchain:is_plat("linux", "bsd") then + toolchain:add("nasm.asflags", "-f", toolchain:is_arch("x86_64") and "elf64" or "elf32") + elseif toolchain:is_plat("windows", "mingw", "msys", "cygwin") then + toolchain:add("nasm.asflags", "-f", toolchain:is_arch("x64") and "win64" or "win32") end end) diff --git a/xmake/toolchains/ndk/load.lua b/xmake/toolchains/ndk/load.lua index 153a93f9b..cbc2ab4a2 100644 --- a/xmake/toolchains/ndk/load.lua +++ b/xmake/toolchains/ndk/load.lua @@ -48,7 +48,7 @@ function main(toolchain) -- init flags local arm32 = false - local arch = config.get("arch") + 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 diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua index ce4862822..c76723c2a 100644 --- a/xmake/toolchains/sdcc/xmake.lua +++ b/xmake/toolchains/sdcc/xmake.lua @@ -67,7 +67,7 @@ toolchain("sdcc") end -- add port flags for arch - local arch = get_config("arch") + local arch = toolchain:arch() if arch then toolchain:add("cxflags", "-m" .. arch) toolchain:add("ldflags", "-m" .. arch) diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 925db3870..e49957b17 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -27,7 +27,7 @@ import("detect.sdks.find_xcode") function main(toolchain) -- find xcode - local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = toolchain:plat(), arch = toolchain:arch()}) if xcode then config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) else @@ -35,17 +35,32 @@ function main(toolchain) end -- save target minver - local xcode_sdkver = config.get("xcode_sdkver") - local target_minver = config.get("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 xcode_sdkver = toolchain:is_plat(config.plat()) and config.get("xcode_sdkver") + if not xcode_sdkver then + xcode_sdkver = config.get("xcode_sdkver_" .. toolchain:plat()) + end + local target_minver = toolchain:is_plat(config.plat()) and config.get("target_minver") + if not target_minver then + target_minver = config.get("target_minver_" .. toolchain:plat()) + end if xcode_sdkver and not target_minver then target_minver = xcode_sdkver - if is_plat("macosx") then + if toolchain:is_plat("macosx") then local macos_ver = macos.version() if macos_ver then target_minver = macos_ver:major() .. "." .. macos_ver:minor() end end - config.set("target_minver", target_minver) + config.set("target_minver_" .. toolchain:plat(), target_minver) end return true end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index 3aeb78672..1d495a5cb 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -25,14 +25,14 @@ import("core.project.config") function main(toolchain) -- init architecture - local arch = config.get("arch") or "arm64" + local arch = toolchain:arch() local simulator = (arch == "i386" or arch == "x86_64") -- init platform name local platname = simulator and "iPhoneSimulator" or "iPhoneOS" -- init target minimal version - local target_minver = config.get("target_minver") + local target_minver = config.get("target_minver_iphoneos") 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 @@ -40,7 +40,7 @@ function main(toolchain) -- init the xcode sdk directory local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkver = config.get("xcode_sdkver_iphoneos") local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index de7dddb1e..c16fd6665 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -25,12 +25,12 @@ import("core.project.config") function main(toolchain) -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") + local arch = toolchain:arch() + local target_minver = config.get("target_minver_macosx") -- init flags for the xcode sdk directory local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkver = config.get("xcode_sdkver_macosx") 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" diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index 5048f4bb7..cae0b40d4 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -25,19 +25,19 @@ import("core.project.config") function main(toolchain) -- init architecture - local arch = config.get("arch") + local arch = toolchain:arch() local simulator = arch == "i386" -- init platform name local platname = simulator and "WatchSimulator" or "WatchOS" -- init target minimal version - local target_minver = config.get("target_minver") + local target_minver = config.get("target_minver_watchos") local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver -- init the xcode sdk directory local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkver = config.get("xcode_sdkver_watchos") local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 776c142af..7394c8a13 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -36,14 +36,14 @@ toolchain("xcode") -- get cross local cross, arch, simulator - if is_plat("macosx") then + if toolchain:is_plat("macosx") then cross = "xcrun -sdk macosx " - elseif is_plat("iphoneos") then - arch = get_config("arch") or os.arch() + elseif toolchain:is_plat("iphoneos") then + arch = toolchain:arch() simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - elseif is_plat("watchos") then - arch = get_config("arch") or os.arch() + elseif toolchain:is_plat("watchos") then + arch = toolchain:arch() simulator = (arch == "i386") cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else @@ -67,7 +67,7 @@ toolchain("xcode") if arch then toolchain:set("toolset", "cpp", cross .. "clang -arch " .. arch .. " -E") end - if is_plat("macosx") then + if toolchain:is_plat("macosx") then toolchain:set("toolset", "as", cross .. "clang") elseif simulator then toolchain:set("toolset", "as", cross .. "clang") @@ -76,5 +76,5 @@ toolchain("xcode") end -- load configurations - import("load_" .. get_config("plat"))(toolchain) + import("load_" .. toolchain:plat())(toolchain) end) diff --git a/xmake/toolchains/yasm/xmake.lua b/xmake/toolchains/yasm/xmake.lua index 7811219b5..b28fe7cc0 100644 --- a/xmake/toolchains/yasm/xmake.lua +++ b/xmake/toolchains/yasm/xmake.lua @@ -30,11 +30,11 @@ toolchain("yasm") -- on load on_load(function (toolchain) - if is_plat("macosx") then - toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") - elseif is_plat("linux", "bsd") then - toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") - elseif is_plat("windows", "mingw", "msys", "cygwin") then - toolchain:add("yasm.asflags", "-f", is_arch("x86_64", "x64") and "win64" or "win32") + 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) |
