diff options
| author | ruki <[email protected]> | 2020-09-03 23:29:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-09-03 23:29:54 +0800 |
| commit | 304cd31298a66501aecec161c31f5e94aa5ac142 (patch) | |
| tree | 450b0d979f3690b1b1e6d61c63af4980c97b6023 | |
| parent | 30e13046db1c1e72c78731d184eb491f2e0f4e3b (diff) | |
add emcc/emscripten toolchain
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | README_zh.md | 1 | ||||
| -rw-r--r-- | xmake/modules/core/tools/emar.lua | 24 | ||||
| -rw-r--r-- | xmake/modules/core/tools/emcc.lua | 48 | ||||
| -rw-r--r-- | xmake/modules/core/tools/emxx.lua | 24 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/emcc/has_flags.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/emxx/has_flags.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_emar.lua | 67 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_emcc.lua | 52 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_emxx.lua | 52 | ||||
| -rw-r--r-- | xmake/toolchains/emcc/xmake.lua | 51 |
12 files changed, 370 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index abd8f6851..acc5a162f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * [#2941](https://github.com/microsoft/winget-pkgs/pull/2941): Add support for winget * Add xmake-tinyc installer without msvc compiler for windows +* Add tinyc compiler toolchain +* Add emcc compiler toolchain (emscripten) to compiling to asm.js and WebAssembly ### Change @@ -814,6 +816,8 @@ * [#2941](https://github.com/microsoft/winget-pkgs/pull/2941): 支持通过 winget 来安装 xmake * 添加 xmake-tinyc 安装包,内置tinyc编译器,支持windows上无msvc环境也可直接编译c代码 +* 添加 tinyc 编译工具链 +* 添加 emcc (emscripten) 编译工具链去编译 asm.js 和 WebAssembly ### 改进 @@ -196,6 +196,7 @@ gnu-rm GNU Arm Embedded Toolchain envs Environment variables toolchain fasm Flat Assembler tinyc Tiny C Compiler +emcc A toolchain for compiling to asm.js and WebAssembly ``` ## Supported Languages diff --git a/README_zh.md b/README_zh.md index a8f6bc8ac..af3ff03f0 100644 --- a/README_zh.md +++ b/README_zh.md @@ -199,6 +199,7 @@ gnu-rm GNU Arm Embedded Toolchain envs Environment variables toolchain fasm Flat Assembler tinyc Tiny C Compiler +emcc A toolchain for compiling to asm.js and WebAssembly ``` ## 支持语言 diff --git a/xmake/modules/core/tools/emar.lua b/xmake/modules/core/tools/emar.lua new file mode 100644 index 000000000..db8fd5fae --- /dev/null +++ b/xmake/modules/core/tools/emar.lua @@ -0,0 +1,24 @@ +--!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 emar.lua +-- + +-- inherit ar +inherit("ar") + + diff --git a/xmake/modules/core/tools/emcc.lua b/xmake/modules/core/tools/emcc.lua new file mode 100644 index 000000000..8ec5ca4ea --- /dev/null +++ b/xmake/modules/core/tools/emcc.lua @@ -0,0 +1,48 @@ +--!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 emcc.lua +-- + +-- inherit gcc +inherit("gcc") + +-- make the strip flag +function nf_strip(self, level) + local maps = + { + debug = "-Wl,-S" + , all = "-s" + } + return maps[level] +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir) +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + + -- init arguments + opt = opt or {} + local argv = table.join("-o", targetfile, objectfiles, flags) + if is_host("windows") and not opt.rawargs then + argv = winos.cmdargv(argv) + end + return self:program(), argv +end diff --git a/xmake/modules/core/tools/emxx.lua b/xmake/modules/core/tools/emxx.lua new file mode 100644 index 000000000..f9c389c3b --- /dev/null +++ b/xmake/modules/core/tools/emxx.lua @@ -0,0 +1,24 @@ +--!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 em++.lua +-- + +-- inherit emcc +inherit("emcc") + + diff --git a/xmake/modules/detect/tools/emcc/has_flags.lua b/xmake/modules/detect/tools/emcc/has_flags.lua new file mode 100644 index 000000000..12c042355 --- /dev/null +++ b/xmake/modules/detect/tools/emcc/has_flags.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 has_flags.lua +-- + +-- imports +inherit("detect.tools.gcc.has_flags") + diff --git a/xmake/modules/detect/tools/emxx/has_flags.lua b/xmake/modules/detect/tools/emxx/has_flags.lua new file mode 100644 index 000000000..7abf3872f --- /dev/null +++ b/xmake/modules/detect/tools/emxx/has_flags.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 has_flags.lua +-- + +-- imports +inherit("detect.tools.emcc.has_flags") + diff --git a/xmake/modules/detect/tools/find_emar.lua b/xmake/modules/detect/tools/find_emar.lua new file mode 100644 index 000000000..ef4ce81b5 --- /dev/null +++ b/xmake/modules/detect/tools/find_emar.lua @@ -0,0 +1,67 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_emar.lua +-- + +-- imports +import("core.tool.compiler") +import("lib.detect.find_program") + +-- check +function _check(program) + + -- make an stub source file + local libraryfile = os.tmpfile() .. ".a" + local objectfile = os.tmpfile() .. ".o" + local sourcefile = os.tmpfile() .. ".c" + io.writefile(sourcefile, "int test(void)\n{return 0;}") + + -- compile it + compiler.compile(sourcefile, objectfile) + + -- archive it + os.runv(program, {"-cr", libraryfile, objectfile}) + + -- remove files + os.rm(objectfile) + os.rm(sourcefile) + os.rm(libraryfile) +end + +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_emar() +-- local ar, version = find_emar({program = "xcrun -sdk macosx g++", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + opt.check = opt.check or _check + + -- find program + return find_program(opt.program or "emar", opt) +end diff --git a/xmake/modules/detect/tools/find_emcc.lua b/xmake/modules/detect/tools/find_emcc.lua new file mode 100644 index 000000000..2eda7543c --- /dev/null +++ b/xmake/modules/detect/tools/find_emcc.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_emcc.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find emcc +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local emcc = find_emcc() +-- local emcc, version = find_emcc({version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "emcc", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/modules/detect/tools/find_emxx.lua b/xmake/modules/detect/tools/find_emxx.lua new file mode 100644 index 000000000..6adaea5c9 --- /dev/null +++ b/xmake/modules/detect/tools/find_emxx.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_emxx.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find emxx +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local emxx = find_emxx() +-- local emxx, version = find_emxx({version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "em++", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/toolchains/emcc/xmake.lua b/xmake/toolchains/emcc/xmake.lua new file mode 100644 index 000000000..0d0901865 --- /dev/null +++ b/xmake/toolchains/emcc/xmake.lua @@ -0,0 +1,51 @@ +--!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("emcc") + + -- set homepage + set_homepage("http://emscripten.org") + set_description("A toolchain for compiling to asm.js and WebAssembly") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolset + set_toolset("cc", "emcc") + set_toolset("cxx", "emcc", "em++") + set_toolset("ld", "em++", "emcc") + set_toolset("sh", "em++", "emcc") + set_toolset("ar", "emar") + set_toolset("ex", "emar") + set_toolset("as", "emcc") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("emcc") + end) + + -- on load + on_load(function (toolchain) + toolchain:add("cxflags", "") + toolchain:add("asflags", "") + toolchain:add("ldflags", "") + toolchain:add("shflags", "") + end) |
