diff options
| author | ruki <[email protected]> | 2017-02-23 13:42:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-23 13:42:17 +0800 |
| commit | 009c17b89cd33cf7915f82d0d994233238a6bc4c (patch) | |
| tree | 3ab555773f156f2e55971a4b1015516fb87cc024 | |
| parent | 3ed1f42166dbe310aa245678adfc95a2de1f2f14 (diff) | |
add rust tools and language
| -rw-r--r-- | tests/console_rust/src/main.rs | 4 | ||||
| -rwxr-xr-x | tests/console_rust/xmake.lua | 32 | ||||
| -rw-r--r-- | xmake/languages/rust/api.lua | 58 | ||||
| -rw-r--r-- | xmake/languages/rust/check_main.lua | 44 | ||||
| -rw-r--r-- | xmake/languages/rust/load.lua | 38 | ||||
| -rwxr-xr-x | xmake/languages/rust/xmake.lua | 112 | ||||
| -rw-r--r-- | xmake/platforms/linux/check.lua | 6 | ||||
| -rw-r--r-- | xmake/platforms/linux/load.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/macosx/check.lua | 6 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/windows/check.lua | 6 | ||||
| -rwxr-xr-x | xmake/tools/ldc.lua | 108 | ||||
| -rwxr-xr-x | xmake/tools/rustc.lua | 131 |
13 files changed, 449 insertions, 104 deletions
diff --git a/tests/console_rust/src/main.rs b/tests/console_rust/src/main.rs new file mode 100644 index 000000000..8915e16ad --- /dev/null +++ b/tests/console_rust/src/main.rs @@ -0,0 +1,4 @@ +fn main() +{ + println!("hello xmake!!"); +} diff --git a/tests/console_rust/xmake.lua b/tests/console_rust/xmake.lua new file mode 100755 index 000000000..3e6996767 --- /dev/null +++ b/tests/console_rust/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_dlang") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.rs") + diff --git a/xmake/languages/rust/api.lua b/xmake/languages/rust/api.lua new file mode 100644 index 000000000..cc70db84c --- /dev/null +++ b/xmake/languages/rust/api.lua @@ -0,0 +1,58 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file api.lua +-- + +-- get apis +function apis() + + -- init apis + _g.values = + { + -- target.add_xxx + "target.add_links" + , "target.add_rcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + -- option.add_xxx + , "option.add_links" + , "option.add_rcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + } + _g.pathes = + { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + } + + -- ok + return _g +end + + diff --git a/xmake/languages/rust/check_main.lua b/xmake/languages/rust/check_main.lua new file mode 100644 index 000000000..a02da9d6f --- /dev/null +++ b/xmake/languages/rust/check_main.lua @@ -0,0 +1,44 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check_main.lua +-- + +-- check it +function main(sourcefile) + + -- load source code + local sourcecode = io.read(sourcefile) + + -- remove comment first + sourcecode = sourcecode:gsub("/%*.-%*/", "") + sourcecode = sourcecode:gsub("//.-\n", "\n") + + -- find func main() { + if sourcecode:find("fn%s+main%s*%(.-%)") then + return true + end + + -- no main function + return false +end + + diff --git a/xmake/languages/rust/load.lua b/xmake/languages/rust/load.lua new file mode 100644 index 000000000..4eb290d07 --- /dev/null +++ b/xmake/languages/rust/load.lua @@ -0,0 +1,38 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- imports +import("api") + +-- load it +function main() + + -- init apis + _g.apis = api.apis() + + -- ok + return _g +end + + diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua new file mode 100755 index 000000000..9f42c5f64 --- /dev/null +++ b/xmake/languages/rust/xmake.lua @@ -0,0 +1,112 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define language +language("rust") + + -- set source file kinds + set_sourcekinds {rc = ".rs"} + + -- set source file flags + set_sourceflags {rc = "rcflags"} + + -- set target kinds + set_targetkinds {binary = "rc-ld", static = "rc-ar", shared = "rc-sh"} + + -- set target flags + set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + + -- on load + on_load("load") + + -- on check_main + on_check_main("check_main") + + -- set name flags + set_nameflags + { + object = + { + "config.includedirs" + , "target.symbols" + , "target.warnings" + , "target.optimize:check" + , "target.vectorexts:check" + , "target.defines" + , "target.undefines" + , "target.includedirs" + , "platform.includedirs" + , "platform.defines" + , "platform.undefines" + } + , binary = + { + "config.linkdirs" + , "target.linkdirs" + , "target.strip" + , "target.symbols" + , "option.linkdirs" + , "platform.linkdirs" + , "config.links" + , "target.links" + , "option.links" + , "platform.links" + } + , shared = + { + "config.linkdirs" + , "target.linkdirs" + , "target.strip" + , "target.symbols" + , "option.linkdirs" + , "platform.linkdirs" + , "config.links" + , "target.links" + , "option.links" + , "platform.links" + } + , static = + { + "target.strip" + , "target.symbols" + } + } + + -- set menu + set_menu { + config = + { + { } + , {nil, "rc", "kv", nil, "The Rust Compiler" } + , {nil, "rc-ld", "kv", nil, "The Rust Linker" } + , {nil, "rc-ar", "kv", nil, "The Rust Static Library Archiver" } + , {nil, "rc-sh", "kv", nil, "The Rust Shared Library Linker" } + + , { } + , {nil, "links", "kv", nil, "The Link Libraries" } + , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } + , {nil, "includedirs","kv", nil, "The Include Search Directories" } + } + } + diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index e24235f8f..e7faa5154 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -118,6 +118,12 @@ function _check_toolchains(config) checker.check_toolchain(config, "dc-ld", "", "dmd", "the dlang linker") checker.check_toolchain(config, "dc-ld", "", "ldc2", "the dlang linker") checker.check_toolchain(config, "dc-ld", "", "gdc", "the dlang linker") + + -- check for rust tools + checker.check_toolchain(config, "rc", "", "rustc", "the rust compiler") + checker.check_toolchain(config, "rc-ar", "", "rustc", "the rust static library archiver") + checker.check_toolchain(config, "rc-sh", "", "rustc", "the rust shared library linker") + checker.check_toolchain(config, "rc-ld", "", "rustc", "the rust linker") end -- check it diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index cad303f7a..caf20d6ba 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -77,6 +77,10 @@ function main() _g["dc-shflags"] = {} _g["dc-ldflags"] = {} + -- init flags for rust + _g["rc-shflags"] = {} + _g["rc-ldflags"] = {} + -- ok return _g end diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 91c18a055..92af39162 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -75,6 +75,12 @@ function _check_toolchains(config) checker.check_toolchain(config, "dc-ld", "", "dmd", "the dlang linker") checker.check_toolchain(config, "dc-ld", "", "ldc2", "the dlang linker") checker.check_toolchain(config, "dc-ld", "", "gdc", "the dlang linker") + + -- check for rust tools + checker.check_toolchain(config, "rc", "", "rustc", "the rust compiler") + checker.check_toolchain(config, "rc-ar", "", "rustc", "the rust static library archiver") + checker.check_toolchain(config, "rc-sh", "", "rustc", "the rust shared library linker") + checker.check_toolchain(config, "rc-ld", "", "rustc", "the rust linker") end -- check it diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 26104e086..d03a416f1 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -67,6 +67,10 @@ function main() _g["dc-shflags"] = {} _g["dc-ldflags"] = {} + -- init flags for rust + _g["rc-shflags"] = {} + _g["rc-ldflags"] = {} + -- ok return _g end diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua index ff93704f2..d178d4ff4 100644 --- a/xmake/platforms/windows/check.lua +++ b/xmake/platforms/windows/check.lua @@ -226,6 +226,12 @@ function _check_toolchains(config) checker.check_toolchain(config, "dc-ld", "", "dmd", "the dlang linker") checker.check_toolchain(config, "dc-ld", "", "ldc2", "the dlang linker") checker.check_toolchain(config, "dc-ld", "", "gdc", "the dlang linker") + + -- check for rust tools + checker.check_toolchain(config, "rc", "", "rustc", "the rust compiler") + checker.check_toolchain(config, "rc-ar", "", "rustc", "the rust static library archiver") + checker.check_toolchain(config, "rc-sh", "", "rustc", "the rust shared library linker") + checker.check_toolchain(config, "rc-ld", "", "rustc", "the rust linker") end -- check the debugger diff --git a/xmake/tools/ldc.lua b/xmake/tools/ldc.lua index 213fd7e34..0e995017c 100755 --- a/xmake/tools/ldc.lua +++ b/xmake/tools/ldc.lua @@ -22,114 +22,14 @@ -- @file ldc.lua -- --- imports -import("core.tool.tool") -import("core.base.option") -import("core.project.config") -import("core.project.project") +-- inherit dmd +inherit("dmd") -- init it function init(shellname, kind) - -- save the shell name - _g.shellname = shellname or "ldc" - - -- save the kind - _g.kind = kind - - -- init arflags - _g.arflags = { "-lib" } - - -- init shflags - _g.shflags = { "-shared", "-fPIC" } - - -- init dcflags for the kind: shared - _g.shared = {} - _g.shared.dcflags = {"-fPIC"} - - -- init features - _g.features = - { - ["compile:multifiles"] = false - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - return "-I" .. dir -end - --- make the link flag -function nf_link(lib) - - -- make it - return "-L-l" .. lib + -- init super + _super.init(shellname or "ldc", kind) end --- make the linkdir flag -function nf_linkdir(dir) - -- make it - return "-L-L" .. dir -end - --- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- make it - return format("%s %s -of%s %s", _g.shellname, flags, targetfile, objectfiles) -end - --- link the target file -function link(objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) -end - --- make the complie command -function compcmd(sourcefiles, objectfile, flags) - - -- make it - return format("%s -c %s -of%s %s", _g.shellname, flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) -end - --- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - os.run(compcmd(sourcefiles, objectfile, flags)) -end - --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".d" - - -- make stub code - io.write(sourcefile, "void main() {\n}") - - -- check it - os.run("%s -c %s -of%s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) -end diff --git a/xmake/tools/rustc.lua b/xmake/tools/rustc.lua new file mode 100755 index 000000000..108b492ff --- /dev/null +++ b/xmake/tools/rustc.lua @@ -0,0 +1,131 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file rustc.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 "rustc" + + -- save the kind + _g.kind = kind + + -- init arflags + _g.arflags = { "--crate-type=lib" } + + -- init shflags + _g.shflags = { "--crate-type=dylib" } + + -- init features + _g.features = + { + ["compile:multifiles"] = false + } +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + +-- make the includedir flag +function nf_includedir(dir) + + -- make it + return "" +end + +-- make the link flag +function nf_link(lib) + + -- make it + return "" +end + +-- make the linkdir flag +function nf_linkdir(dir) + + -- make it + return "" +end + +-- make the link command +function linkcmd(objectfiles, targetkind, targetfile, flags) + + -- make it + return format("%s %s -o %s %s", _g.shellname, flags, targetfile, objectfiles) +end + +-- link the target file +function link(objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) +end + +-- make the complie command +function compcmd(sourcefiles, objectfile, flags) + + -- make it + return format("%s --emit obj %s -o %s %s", _g.shellname, flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +end + +-- complie the source file +function compile(sourcefiles, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(compcmd(sourcefiles, objectfile, flags)) +end + +-- check the given flags +function check(flags) + + -- make an stub source file + local objectfile = os.tmpfile() .. ".o" + local sourcefile = os.tmpfile() .. ".rs" + + -- make stub code + io.write(sourcefile, "fn main() {\n}") + + -- check it + os.run("%s --emit obj %s -o %s %s", _g.shellname, ifelse(flags, flags, ""), objectfile, sourcefile) + + -- remove files + os.rm(objectfile) + os.rm(sourcefile) +end |
