From c6c71612e034c2e741add2b9deb69be4c93a8388 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 00:03:19 +0800 Subject: add xcode toolchain --- xmake/toolchains/xcode/xmake.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 xmake/toolchains/xcode/xmake.lua (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua new file mode 100644 index 000000000..633f5a45d --- /dev/null +++ b/xmake/toolchains/xcode/xmake.lua @@ -0,0 +1,23 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("xcode") + -- cgit v1.3.1 From ed247a74689d45a4cf9a8a8e4aee64dba741df43 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 21:28:07 +0800 Subject: check tool for toolchain --- xmake/core/platform/platform.lua | 1 - xmake/core/tool/toolchain.lua | 99 ++++++++++++++++++++++++++++++++++++++-- xmake/toolchains/xcode/xmake.lua | 16 +++++++ 3 files changed, 110 insertions(+), 6 deletions(-) (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 9a3aff93a..51cbcf33f 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -32,7 +32,6 @@ local toolchain = require("tool/toolchain") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") -local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, rootdir) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 6cfaf5802..6ebae5152 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -28,10 +28,12 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local global = require("base/global") +local option = require("base/option") local interpreter = require("base/interpreter") local config = require("project/config") local language = require("language/language") local sandbox = require("sandbox/sandbox") +local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, rootdir) @@ -84,6 +86,15 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) + local toolpathes = self:get("toolsets." .. toolkind) + if toolpathes then + for _, toolpath in ipairs(toolpathes) do + local program, toolname = self:_checktool(toolkind, toolpath) + if program then + return program, toolname + end + end + end end -- get the toolchain script @@ -91,6 +102,83 @@ function _instance:script(name) return self._INFO:get(name) end +-- get the bin directory +function _instance:bindir() + return config.get("bin") or self:get("bindir") +end + +-- get the tool description from the tool kind +function _instance:_description(toolkind) + local descriptions = self._DESCRIPTIONS + if not descriptions then + descriptions = + { + cc = "the c compiler", + cxx = "the c++ compiler", + ld = "the linker", + sh = "the shared library linker", + ar = "the static library archiver", + ex = "the static library extractor", + strip = "the symbols stripper", + dsymutil = "the symbols generator", + mm = "the objc compiler", + mxx = "the objc++ compiler", + as = "the assember", + sc = "the swift compiler", + scld = "the swift linker", + scsh = "the swift shared library linker", + gc = "the golang compiler", + gcld = "the golang linker", + gcar = "the golang static library archiver", + dc = "the dlang compiler", + dcld = "the dlang linker", + dcsh = "the dlang shared library linker", + dcar = "the dlang static library archiver", + rc = "the rust compiler", + rcld = "the rust linker", + rcsh = "the rust shared library linker", + rcar = "the rust static library archiver", + cu = "the cuda compiler", + culd = "the cuda linker", + cuccbin = "the cuda host c++ compiler", + } + self._DESCRIPTIONS = descriptions + end + return descriptions +end + +-- check the given tool path +function _instance:_checktool(toolkind, toolpath) + + -- get find_tool + local find_tool = self._find_tool + if not find_tool then + find_tool = sandbox_module.import("lib.detect.find_tool", {anonymous = true}) + self._find_tool = find_tool + end + + -- find tool program + local program, toolname + local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()}) + if tool then + program = tool.program + toolname = tool.name + end + + -- get tool description from the tool kind + local description = self:_description(toolkind) or ("unknown toolkind " .. toolkind) + + -- trace + if option.get("verbose") then + if program then + utils.cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) + else + utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) + end + end + return program, toolname +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -137,13 +225,14 @@ end function toolchain._apis() return { - values = + values = + { + "toolchain.set_bindir" + } + , keyvalues = { -- toolchain.set_xxx - "toolchain.set_cc" - , "toolchain.set_cxx" - , "toolchain.set_ld" - , "toolchain.set_sh" + "toolchain.set_toolsets" } , script = { diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 633f5a45d..1c39a6453 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,3 +21,19 @@ -- define toolchain toolchain("xcode") + -- set toolsets + set_toolsets("cc", "xcrun -sdk macosx clang") + set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") + set_toolsets("as", "xcrun -sdk macosx clang") + set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") + set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") + set_toolsets("ar", "xcrun -sdk macosx ar") + set_toolsets("ex", "xcrun -sdk macosx ar") + set_toolsets("strip", "xcrun -sdk macosx strip") + set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") + set_toolsets("mm", "xcrun -sdk macosx clang") + set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") + set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") + set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") + set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") + -- cgit v1.3.1 From c0afaacde90abf081bab19279c3ea6d4dbeae86d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 17 May 2020 21:57:39 +0800 Subject: add toolchain check --- xmake/core/tool/toolchain.lua | 57 +++++++++++++++--------- xmake/platforms/macosx/config.lua | 3 +- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/xcode/check.lua | 28 ++++++++++++ xmake/toolchains/xcode/load.lua | 94 +++++++++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 5 +++ 6 files changed, 167 insertions(+), 22 deletions(-) create mode 100644 xmake/toolchains/xcode/check.lua create mode 100644 xmake/toolchains/xcode/load.lua (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 8a62afd8d..246d46a99 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -61,26 +61,6 @@ end -- get the toolchain configuration function _instance:get(name) - - -- attempt to get the static configure value - local value = self._INFO:get(name) - if value ~= nil then - return value - end - - -- lazy loading toolchain if get other configuration - if not self._LOADED and not self:_is_builtin_conf(name) then - local on_load = self._INFO:get("load") - if on_load then - local ok, errors = sandbox.load(on_load, self) - if not ok then - os.raise(errors) - end - end - self._LOADED = true - end - - -- get other toolchain info return self._INFO:get(name) end @@ -107,6 +87,34 @@ function _instance:bindir() return config.get("bin") or self:get("bindir") end +-- do load +function _instance:_load() + if not self._LOADED then + local on_load = self._INFO:get("load") + if on_load then + local ok, errors = sandbox.load(on_load, self) + if not ok then + os.raise(errors) + end + end + self._LOADED = true + end +end + +-- do check +function _instance:_check() + if not self._CHECKED then + local on_check = self._INFO:get("check") + if on_check then + local ok, errors = sandbox.load(on_check, self) + if not ok then + os.raise(errors) + end + end + self._CHECKED = true + end +end + -- get the tool description from the tool kind function _instance:_description(toolkind) local descriptions = self._DESCRIPTIONS @@ -150,6 +158,9 @@ end -- check the given tool path function _instance:_checktool(toolkind, toolpath) + -- ensure to check this toolchain first + self:_check() + -- get find_tool local find_tool = self._find_tool if not find_tool then @@ -176,6 +187,11 @@ function _instance:_checktool(toolkind, toolpath) utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) end end + + -- we only load it when checking the given tool successfully + if program then + self:_load() + end return program, toolname end @@ -238,6 +254,7 @@ function toolchain._apis() { -- toolchain.on_xxx "toolchain.on_load" + , "toolchain.on_check" } , dictionary = { diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua index a5c0893fc..a1713a657 100644 --- a/xmake/platforms/macosx/config.lua +++ b/xmake/platforms/macosx/config.lua @@ -146,6 +146,7 @@ end -- check it function main(platform, name) + --[[ -- only check the given config name? if name then local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] @@ -159,6 +160,6 @@ function main(platform, name) -- check xcode check_xcode(config, true) - end + end]] end diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index b7abea032..fc390d953 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -37,7 +37,7 @@ platform("macosx") set_installdir("/usr/local") -- on check project configuration - on_config_check("config") +-- on_config_check("config") -- on check global configuration on_global_check("global") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua new file mode 100644 index 000000000..c10fe48d9 --- /dev/null +++ b/xmake/toolchains/xcode/check.lua @@ -0,0 +1,28 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("private.platform.check_xcode") + +-- main entry +function main(toolchain) + check_xcode(config, true) +end diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua new file mode 100644 index 000000000..96d459414 --- /dev/null +++ b/xmake/toolchains/xcode/load.lua @@ -0,0 +1,94 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/toolchains/MacOSX.toolchain/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm +-- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") +-- toolchain:set("fasm.asflags", "") + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end + + --[[ + -- init flags for golang + toolchain:set("gcldflags", "") + + -- init flags for dlang + local dc_archs = { i386 = "-m32", x86_64 = "-m64" } + toolchain:add("dcflags", dc_archs[arch] or "") + toolchain:add("dcshflags", dc_archs[arch] or "") + toolchain:add("dcldflags", dc_archs[arch] or "" ) + + -- init flags for rust + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "")]] +end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 1c39a6453..d9b1d9944 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -37,3 +37,8 @@ toolchain("xcode") set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") -- cgit v1.3.1 From 9aaf4d1f861acb3167ce101ddbf12a5f57b0392a Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:56:42 +0800 Subject: support iphoneos for xcode toolchain --- xmake/platforms/iphoneos/check.lua | 27 +++++---- xmake/platforms/iphoneos/load.lua | 62 --------------------- xmake/platforms/iphoneos/xmake.lua | 4 +- xmake/platforms/macosx/check.lua | 21 ++----- xmake/platforms/macosx/load.lua | 94 -------------------------------- xmake/platforms/macosx/xmake.lua | 3 - xmake/toolchains/xcode/load.lua | 94 -------------------------------- xmake/toolchains/xcode/load_iphoneos.lua | 62 +++++++++++++++++++++ xmake/toolchains/xcode/load_macosx.lua | 94 ++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 50 +++++++++++------ 10 files changed, 208 insertions(+), 303 deletions(-) delete mode 100644 xmake/platforms/iphoneos/load.lua delete mode 100644 xmake/platforms/macosx/load.lua delete mode 100644 xmake/toolchains/xcode/load.lua create mode 100644 xmake/toolchains/xcode/load_iphoneos.lua create mode 100644 xmake/toolchains/xcode/load_macosx.lua (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua index 94a3a9ae9..1a7fbd4e3 100644 --- a/xmake/platforms/iphoneos/check.lua +++ b/xmake/platforms/iphoneos/check.lua @@ -20,9 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") + +--[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -105,24 +107,21 @@ function _toolchains() sc_sh:add({name = "swiftc", cross = cross}) return toolchains -end +end]] -- check it function main(platform, name) - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, "arm64") - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/iphoneos/load.lua b/xmake/platforms/iphoneos/load.lua deleted file mode 100644 index 7d54e24be..000000000 --- a/xmake/platforms/iphoneos/load.lua +++ /dev/null @@ -1,62 +0,0 @@ ---!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 load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init architecture - local arch = config.get("arch") or "arm64" - 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") - 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 the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - 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++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 6d2af82ae..ff5ba2204 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,8 +36,8 @@ platform("iphoneos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 2158dc25a..1166c3205 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -20,11 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") --[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -148,6 +148,9 @@ end]] -- check it function main(platform) + -- check arch + check_arch(config) + -- check toolchains local toolchains = platform:toolchains() for idx, toolchain in irpairs(toolchains) do @@ -156,21 +159,5 @@ function main(platform) end end assert(#toolchains > 0, "toolchains not found!") - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua deleted file mode 100644 index 6d2547a75..000000000 --- a/xmake/platforms/macosx/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!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 load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("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" - end - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch) - platform:add("ldflags", "-arch " .. arch) - if target_minver then - platform:add("cxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("mxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - platform:add("cxflags", "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - platform:add("cxflags", "-I/usr/local/include") - platform:add("cxflags", "-I/usr/include") - platform:add("ldflags", "-L/usr/local/lib") - platform:add("ldflags", "-L/usr/lib") - end - platform:add("ldflags", "-stdlib=libc++") - platform:add("ldflags", "-lz") - platform:add("shflags", platform:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm - platform:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") - platform:set("fasm.asflags", "") - platform:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - platform:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - -- init flags for golang - platform:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dcshflags", dc_archs[arch] or "") - platform:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - platform:set("rcshflags", "") - platform:set("rcldflags", "") -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 512499c7c..9fd14a82f 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -39,9 +39,6 @@ platform("macosx") -- on check on_check("check") - -- on load - on_load("load") - -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") set_toolchains("xcode") diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua deleted file mode 100644 index 4d4165a7e..000000000 --- a/xmake/toolchains/xcode/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- main entry -function main(toolchain) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("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" - end - - -- init flags for c/c++ - toolchain:add("cxflags", "-arch " .. arch) - toolchain:add("ldflags", "-arch " .. arch) - if target_minver then - toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) - toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) - toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) - toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - toolchain:add("cxflags", "-I/usr/local/include") - toolchain:add("cxflags", "-I/usr/include") - toolchain:add("ldflags", "-L/usr/local/lib") - toolchain:add("ldflags", "-L/usr/lib") - end - toolchain:add("ldflags", "-stdlib=libc++") - toolchain:add("ldflags", "-lz") - toolchain:add("shflags", toolchain:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - toolchain:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm --- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") --- toolchain:set("fasm.asflags", "") - toolchain:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - --[[ - -- init flags for golang - toolchain:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - toolchain:add("dcflags", dc_archs[arch] or "") - toolchain:add("dcshflags", dc_archs[arch] or "") - toolchain:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - toolchain:set("rcshflags", "") - toolchain:set("rcldflags", "")]] -end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua new file mode 100644 index 000000000..3aeb78672 --- /dev/null +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -0,0 +1,62 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_iphoneos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") or "arm64" + 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") + 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 the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + 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++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- 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_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua new file mode 100644 index 000000000..b735b8d77 --- /dev/null +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -0,0 +1,94 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_macosx.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("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" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm +-- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") +-- toolchain:set("fasm.asflags", "") + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end + + --[[ + -- init flags for golang + toolchain:set("gcldflags", "") + + -- init flags for dlang + local dc_archs = { i386 = "-m32", x86_64 = "-m64" } + toolchain:add("dcflags", dc_archs[arch] or "") + toolchain:add("dcshflags", dc_archs[arch] or "") + toolchain:add("dcldflags", dc_archs[arch] or "" ) + + -- init flags for rust + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "")]] +end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index d9b1d9944..4f45f6d60 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,24 +21,40 @@ -- define toolchain toolchain("xcode") - -- set toolsets - set_toolsets("cc", "xcrun -sdk macosx clang") - set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("as", "xcrun -sdk macosx clang") - set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("ar", "xcrun -sdk macosx ar") - set_toolsets("ex", "xcrun -sdk macosx ar") - set_toolsets("strip", "xcrun -sdk macosx strip") - set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") - set_toolsets("mm", "xcrun -sdk macosx clang") - set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") - -- check toolchain on_check("check") -- load toolchain - on_load("load") + on_load(function (toolchain) + + -- get cross + local cross + if is_plat("macosx") then + cross = "xcrun -sdk macosx " + elseif is_plat("iphoneos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + else + raise("unknown platform for xcode!") + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "as", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "strip", cross .. "strip") + toolchain:set("toolsets", "dsymutil", cross .. "dsymutil", "dsymutil") + toolchain:set("toolsets", "mm", cross .. "clang") + toolchain:set("toolsets", "mxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + + -- load configurations + import("load_" .. get_config("plat"))(toolchain) + end) -- cgit v1.3.1 From 93db858087c1bdeba2585f2de409e53a8d8e8fbd Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:57:44 +0800 Subject: support watchos for xcode toolchain --- xmake/platforms/watchos/load.lua | 59 --------------------------------- xmake/platforms/watchos/xmake.lua | 4 +-- xmake/toolchains/xcode/load_macosx.lua | 16 --------- xmake/toolchains/xcode/load_watchos.lua | 59 +++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 4 +++ 5 files changed, 65 insertions(+), 77 deletions(-) delete mode 100644 xmake/platforms/watchos/load.lua create mode 100644 xmake/toolchains/xcode/load_watchos.lua (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/xmake/platforms/watchos/load.lua b/xmake/platforms/watchos/load.lua deleted file mode 100644 index 2e0204358..000000000 --- a/xmake/platforms/watchos/load.lua +++ /dev/null @@ -1,59 +0,0 @@ ---!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 load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init architecture - local arch = config.get("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_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_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 1311c47ba..1356af3ab 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -36,8 +36,8 @@ platform("watchos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index b735b8d77..5cebd96bb 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -64,8 +64,6 @@ function main(toolchain) end -- init flags for asm --- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") --- toolchain:set("fasm.asflags", "") toolchain:add("asflags", "-arch " .. arch) if xcode_sdkdir then toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) @@ -77,18 +75,4 @@ function main(toolchain) toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end - - --[[ - -- init flags for golang - toolchain:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - toolchain:add("dcflags", dc_archs[arch] or "") - toolchain:add("dcshflags", dc_archs[arch] or "") - toolchain:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - toolchain:set("rcshflags", "") - toolchain:set("rcldflags", "")]] end diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua new file mode 100644 index 000000000..5048f4bb7 --- /dev/null +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -0,0 +1,59 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_watchos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("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_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_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- 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_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 4f45f6d60..f20fabe1f 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -35,6 +35,10 @@ toolchain("xcode") local arch = get_config("arch") or os.arch() local simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + elseif is_plat("watchos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386") + cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else raise("unknown platform for xcode!") end -- cgit v1.3.1 From fb7bc83c06972744d6f2c5139b5bc079e06b7b11 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:59:45 +0800 Subject: add as to xcode toolchain --- xmake/toolchains/xcode/xmake.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index f20fabe1f..aed4a44e9 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -28,16 +28,16 @@ toolchain("xcode") on_load(function (toolchain) -- get cross - local cross + local cross, arch, simulator if is_plat("macosx") then cross = "xcrun -sdk macosx " elseif is_plat("iphoneos") then - local arch = get_config("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") + arch = get_config("arch") or os.arch() + simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " elseif is_plat("watchos") then - local arch = get_config("arch") or os.arch() - local simulator = (arch == "i386") + arch = get_config("arch") or os.arch() + simulator = (arch == "i386") cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else raise("unknown platform for xcode!") @@ -46,7 +46,6 @@ toolchain("xcode") -- set toolsets toolchain:set("toolsets", "cc", cross .. "clang") toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") - toolchain:set("toolsets", "as", cross .. "clang") toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") toolchain:set("toolsets", "ar", cross .. "ar") @@ -58,6 +57,16 @@ toolchain("xcode") toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + if arch then + toolchain:set("toolsets", "cpp", cross .. "clang -arch " .. arch .. " -E") + end + if is_plat("macosx") then + toolchain:set("toolsets", "as", cross .. "clang") + elseif simulator then + toolchain:set("toolsets", "as", cross .. "clang") + else + toolchain:set("toolsets", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross) .. "clang") + end -- load configurations import("load_" .. get_config("plat"))(toolchain) -- cgit v1.3.1 From a5a4b0ac5b9674ac00049cc1f4ff8f11d5268f6b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:44:16 +0800 Subject: set standalone toolchain --- tests/projects/asm/nasm/src/main.S | 1 - xmake/actions/config/xmake.lua | 2 +- xmake/core/platform/platform.lua | 25 +++++++++++++++++-------- xmake/core/tool/toolchain.lua | 13 ++++++++++++- xmake/modules/detect/tools/find_fasm.lua | 1 + xmake/modules/detect/tools/find_nasm.lua | 1 + xmake/platforms/bsd/check.lua | 16 +++++----------- xmake/platforms/linux/check.lua | 16 +++++----------- xmake/platforms/macosx/check.lua | 16 +++++----------- xmake/toolchains/clang/xmake.lua | 3 +++ xmake/toolchains/cross/xmake.lua | 3 +++ xmake/toolchains/gcc/xmake.lua | 3 +++ xmake/toolchains/llvm/xmake.lua | 3 +++ xmake/toolchains/xcode/xmake.lua | 3 +++ 14 files changed, 62 insertions(+), 44 deletions(-) (limited to 'xmake/toolchains/xcode/xmake.lua') diff --git a/tests/projects/asm/nasm/src/main.S b/tests/projects/asm/nasm/src/main.S index 5b3a93699..e96a8d2c9 100644 --- a/tests/projects/asm/nasm/src/main.S +++ b/tests/projects/asm/nasm/src/main.S @@ -1,6 +1,5 @@ global _main - section .text _main: diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 4953fc718..3b02846d1 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -156,7 +156,7 @@ task("config") , " - sdk/bin" , " - sdk/lib" , " - sdk/include" } - , {nil, "toolchain", "kv", nil, "The Cross Toolchain Name" + , {nil, "toolchain", "kv", nil, "The Toolchain Name" , "e.g." , " - llvm" } diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1ca688636..328bcce75 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -107,19 +107,28 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if not toolchains then - local names = {} - if config.get("toolchain") then - table.insert(names, config.get("toolchain")) - elseif self._INFO:get("toolchains") then - table.join2(names, self._INFO:get("toolchains")) - end + + -- get the given toolchain toolchains = {} - for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name, self:name()) + local toolchain_given = config.get("toolchain") + if toolchain_given then + local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) if not toolchain_inst then os.raise(errors) end table.insert(toolchains, toolchain_inst) + toolchain_given = toolchain_inst + end + + -- get the platform toolchains + if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then + for _, name in ipairs(self._INFO:get("toolchains")) do + local toolchain_inst, errors = toolchain.load(name, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end end self._TOOLCHAINS = toolchains end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 78da9ea7f..f5d6ada4f 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -77,6 +77,16 @@ function _instance:get(name) return self._INFO:get(name) end +-- get toolchain kind +function _instance:kind() + return self._INFO:get("kind") +end + +-- is standalone toolchain? +function _instance:standalone() + return self:kind() == "standalone" +end + -- get the program and name of the given tool kind function _instance:tool(toolkind) local toolpathes = self:get("toolsets." .. toolkind) @@ -271,7 +281,8 @@ function toolchain._apis() { values = { - "toolchain.set_bindir" + "toolchain.set_kind" + , "toolchain.set_bindir" , "toolchain.set_sdkdir" } , keyvalues = diff --git a/xmake/modules/detect/tools/find_fasm.lua b/xmake/modules/detect/tools/find_fasm.lua index 5ebf9e699..0b555a406 100644 --- a/xmake/modules/detect/tools/find_fasm.lua +++ b/xmake/modules/detect/tools/find_fasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.norun = true -- find program local program = find_program(opt.program or "fasm", opt) diff --git a/xmake/modules/detect/tools/find_nasm.lua b/xmake/modules/detect/tools/find_nasm.lua index 40b710d2e..68936502e 100644 --- a/xmake/modules/detect/tools/find_nasm.lua +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.check = "-v" -- find program local program = find_program(opt.program or "nasm", opt) diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 3cd6b8980..71d2e555c 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index a851256e5..71d2e555c 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "cross" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 08e04d7d6..b4eb3b73b 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "xcode" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 5d495fff5..ca84a94be 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("clang") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "clang") diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua index 78be10f98..1cf211646 100644 --- a/xmake/toolchains/cross/xmake.lua +++ b/xmake/toolchains/cross/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("cross") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index ba1ef6989..77f2ef228 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("gcc") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "gcc") diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index d04234809..4c6c4748b 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("llvm") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index aed4a44e9..74462908c 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,6 +21,9 @@ -- define toolchain toolchain("xcode") + -- mark as standalone toolchain + set_kind("standalone") + -- check toolchain on_check("check") -- cgit v1.3.1