diff options
| author | ruki <[email protected]> | 2016-12-19 09:14:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-06 17:20:08 +0800 |
| commit | f7a4d5e18d50ccaa23adfcb06358f9368770ed6a (patch) | |
| tree | 31cb4924c35ad3ed7b81dd8fda337fb6648dcc30 | |
| parent | 3ec8380e312ebfd82a359632ad660fb842b9211d (diff) | |
add golang
| -rw-r--r-- | tests/console_go/src/main.go | 22 | ||||
| -rwxr-xr-x | tests/console_go/xmake.lua | 32 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/linker.lua | 6 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 16 | ||||
| -rw-r--r-- | xmake/platforms/macosx/checker.lua | 13 | ||||
| -rwxr-xr-x | xmake/tools/go.lua | 153 |
7 files changed, 229 insertions, 15 deletions
diff --git a/tests/console_go/src/main.go b/tests/console_go/src/main.go new file mode 100644 index 000000000..c91ae5091 --- /dev/null +++ b/tests/console_go/src/main.go @@ -0,0 +1,22 @@ +/*!The Qiyi Golang Backend Server + * + * Copyright (C) 2016, qiyi.com All rights reserved. + * + * @author ruki + * @file main.go + * + */ +package main + +/* ///////////////////////////////////////////////////////////////////////////////////////////////// + * imports + */ +import "fmt" + +/* ///////////////////////////////////////////////////////////////////////////////////////////////// + * main + */ +func main() { + + fmt.Println("hello xmake for go!") +} diff --git a/tests/console_go/xmake.lua b/tests/console_go/xmake.lua new file mode 100755 index 000000000..d69c3d457 --- /dev/null +++ b/tests/console_go/xmake.lua @@ -0,0 +1,32 @@ +-- the debug mode +if is_mode("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if is_mode("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +target("console_go") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.go") + diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index a204681d4..21604b24e 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -32,7 +32,7 @@ local raise = require("sandbox/modules/raise") function sandbox_core_tool_linker.linkcmd(objectfiles, targetfile, target) -- get the linker instance - local instance, errors = linker.load(target:get("kind")) + local instance, errors = linker.load(target:get("kind"), target:sourcekinds()) if not instance then raise(errors) end @@ -45,7 +45,7 @@ end function sandbox_core_tool_linker.linkflags(target) -- get the linker instance - local instance, errors = linker.load(target:get("kind")) + local instance, errors = linker.load(target:get("kind"), target:sourcekinds()) if not instance then raise(errors) end @@ -58,7 +58,7 @@ end function sandbox_core_tool_linker.link(objectfiles, targetfile, target) -- get the linker instance - local instance, errors = linker.load(target:get("kind")) + local instance, errors = linker.load(target:get("kind"), target:sourcekinds()) if not instance then raise(errors) end diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index b11e5c065..44ec094b6 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -251,6 +251,7 @@ function compiler.kind_of_file(sourcefile) , [".mm"] = "mxx" , [".s"] = "as" , [".asm"] = "as" + , [".go"] = "go" , [".swift"] = "sc" } @@ -301,6 +302,7 @@ function compiler.load(sourcekind) , mxx = { "mxflags", "mxxflags" } , as = { "asflags" } , sc = { "scflags" } + , go = { "goflags" } } instance._FLAGNAMES = flagnames[sourcekind] diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 378c20cf6..e378223a3 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -51,7 +51,16 @@ function linker:_flagname() end -- get the link kind of the target kind -function linker._kind_of_target(targetkind) +function linker._kind_of_target(targetkind, sourcekinds) + + -- link the target of golang objects + if sourcekinds then + for _, sourcekind in ipairs(sourcekinds) do + if sourcekind == "go" then + return "go" + end + end + end -- the kinds local kinds = @@ -259,10 +268,10 @@ function linker:kind() end -- load the linker from the given target kind -function linker.load(targetkind) +function linker.load(targetkind, sourcekinds) -- get the linker kind - local kind = linker._kind_of_target(targetkind) + local kind = linker._kind_of_target(targetkind, sourcekinds) if not kind then return nil, string.format("unknown target kind: %s", targetkind) end @@ -293,6 +302,7 @@ function linker.load(targetkind) { ld = "ldflags" , sh = "shflags" + , go = "goflags" } instance._FLAGNAME = flagname[kind] diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua index 9dcbe040e..bf6789733 100644 --- a/xmake/platforms/macosx/checker.lua +++ b/xmake/platforms/macosx/checker.lua @@ -24,12 +24,6 @@ import("core.tool.tool") import("platforms.checker", {rootdir = os.programdir()}) --- check from envar -function _check_toolchain_from_env(config, env) - - checker.check_toolchain(config, "cc", "xcrun -sdk macosx ", "clang", "the c compiler") -end - -- check the toolchains function _check_toolchains(config) @@ -38,12 +32,12 @@ function _check_toolchains(config) checker.check_toolchain_from_env(config, "cxx", "CXX", "the c++ compiler") checker.check_toolchain_from_env(config, "mm", "MM", "the objc compiler") checker.check_toolchain_from_env(config, "mxx", "MXX", "the objc++ compiler") + checker.check_toolchain_from_env(config, "sc", "SC", "the swift compiler") checker.check_toolchain_from_env(config, "as", "AS", "the assember") checker.check_toolchain_from_env(config, "ld", "LD", "the linker") checker.check_toolchain_from_env(config, "ar", "AR", "the static library archiver") checker.check_toolchain_from_env(config, "ex", "AR", "the static library extractor") checker.check_toolchain_from_env(config, "sh", "SH", "the shared library linker") - checker.check_toolchain_from_env(config, "sc", "SC", "the swift compiler") checker.check_toolchain_from_env(config, "dd", "DD", "the debugger") -- check with xcrun @@ -53,6 +47,7 @@ function _check_toolchains(config) checker.check_toolchain(config, "mm", "xcrun -sdk macosx ", "clang", "the objc compiler") checker.check_toolchain(config, "mxx", "xcrun -sdk macosx ", "clang++", "the objc++ compiler") checker.check_toolchain(config, "mxx", "xcrun -sdk macosx ", "clang", "the objc++ compiler") + checker.check_toolchain(config, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler") checker.check_toolchain(config, "as", "xcrun -sdk macosx ", "clang", "the assember") checker.check_toolchain(config, "ld", "xcrun -sdk macosx ", "clang++", "the linker") checker.check_toolchain(config, "ld", "xcrun -sdk macosx ", "clang", "the linker") @@ -60,7 +55,6 @@ function _check_toolchains(config) checker.check_toolchain(config, "ex", "xcrun -sdk macosx ", "ar", "the static library extractor") checker.check_toolchain(config, "sh", "xcrun -sdk macosx ", "clang++", "the shared library linker") checker.check_toolchain(config, "sh", "xcrun -sdk macosx ", "clang", "the shared library linker") - checker.check_toolchain(config, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler") checker.check_toolchain(config, "dd", "xcrun -sdk macosx ", "lldb", "the debugger") -- check without xcrun @@ -70,6 +64,8 @@ function _check_toolchains(config) checker.check_toolchain(config, "mm", "", "clang", "the objc compiler") checker.check_toolchain(config, "mxx", "", "clang++", "the objc++ compiler") checker.check_toolchain(config, "mxx", "", "clang", "the objc++ compiler") + checker.check_toolchain(config, "go", "", "go", "the golang compiler") + checker.check_toolchain(config, "sc", "", "swiftc", "the swift compiler") checker.check_toolchain(config, "as", "", "clang", "the assember") checker.check_toolchain(config, "ld", "", "clang++", "the linker") checker.check_toolchain(config, "ld", "", "clang", "the linker") @@ -77,7 +73,6 @@ function _check_toolchains(config) checker.check_toolchain(config, "ex", "", "ar", "the static library extractor") checker.check_toolchain(config, "sh", "", "clang++", "the shared library linker") checker.check_toolchain(config, "sh", "", "clang", "the shared library linker") - checker.check_toolchain(config, "sc", "", "swiftc", "the swift compiler") checker.check_toolchain(config, "dd", "", "lldb", "the debugger") end diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua new file mode 100755 index 000000000..e2eecc33a --- /dev/null +++ b/xmake/tools/go.lua @@ -0,0 +1,153 @@ +--!The Make-like Build Utility based on Lua +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file go.lua +-- + +-- imports +import("core.tool.tool") +import("core.base.option") +import("core.project.config") +import("core.project.project") + +-- init it +function init(shellname, kind) + + -- save the shell name + _g.shellname = shellname or "go" + + -- save the kind + _g.kind = kind + +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + +-- make the strip flag +function strip(level) + return "" +end + +-- make the symbol flag +function symbol(level, symbolfile) + return "" +end + +-- make the warning flag +function warning(level) + return "" +end + +-- make the optimize flag +function optimize(level) + return "" +end + +-- make the vector extension flag +function vectorext(extension) + return "" +end + +-- make the language flag +function language(stdname) + return "" +end + +-- make the define flag +function define(macro) + return "" +end + +-- make the undefine flag +function undefine(macro) + return "" +end + +-- make the includedir flag +function includedir(dir) + return "" +end + +-- make the linklib flag +function linklib(lib) + return "" +end + +-- make the linkdir flag +function linkdir(dir) + return "" +end + +-- make the link command +function linkcmd(objectfiles, targetfile, flags) + + -- make it + return format("%s tool link %s -o %s %s", _g.shellname, flags, targetfile, objectfiles) +end + +-- make the complie command +function compcmd(sourcefile, objectfile, flags) + + -- make it + return format("%s tool compile %s -o %s %s", _g.shellname, flags, objectfile, sourcefile) +end + +-- link the target file +function link(objectfiles, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(objectfiles, targetfile, flags)) +end + +-- complie the source file +function compile(sourcefile, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(compcmd(sourcefile, objectfile, flags)) +end + +-- check the given flags +function check(flags) + + -- make an stub source file + local objectfile = os.tmpfile() .. ".o" + local sourcefile = os.tmpfile() .. ".go" + + -- make stub code + io.write(sourcefile, "package main\nfunc main() {\n}") + + -- check it + os.run("%s tool compile %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile) + + -- remove files + os.rm(objectfile) + os.rm(sourcefile) +end + |
