diff options
| author | ruki <[email protected]> | 2023-01-28 15:46:33 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-28 15:46:33 +0800 |
| commit | ef438d143f44b65400792b361297fc3b930d0a28 (patch) | |
| tree | b43ef0c064e3dae979746c9291b713afd648f8c0 | |
| parent | a41c8f08b24be14442ddc7f816bad41fd5213c44 (diff) | |
| parent | 67b63e391aed8b0d7ebfdf529922fca6131432c6 (diff) | |
Merge pull request #3318 from xmake-io/dlang
Improve dlang toolchains
| -rw-r--r-- | .github/workflows/windows_luajit.yml | 4 | ||||
| -rw-r--r-- | CHANGELOG.md | 8 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | README_zh.md | 5 | ||||
| -rw-r--r-- | xmake/platforms/linux/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/macosx/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/windows/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/dlang/xmake.lua | 8 | ||||
| -rw-r--r-- | xmake/toolchains/dlang/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/toolchains/dmd/xmake.lua | 48 | ||||
| -rw-r--r-- | xmake/toolchains/gdc/check.lua | 52 | ||||
| -rw-r--r-- | xmake/toolchains/gdc/xmake.lua | 44 | ||||
| -rw-r--r-- | xmake/toolchains/ldc/check.lua | 52 | ||||
| -rw-r--r-- | xmake/toolchains/ldc/xmake.lua | 43 |
14 files changed, 267 insertions, 22 deletions
diff --git a/.github/workflows/windows_luajit.yml b/.github/workflows/windows_luajit.yml index 6c15dd914..0952c965d 100644 --- a/.github/workflows/windows_luajit.yml +++ b/.github/workflows/windows_luajit.yml @@ -80,8 +80,8 @@ jobs: Copy-Item ./7zip/7z.dll ./winenv/bin curl -fsSL "https://curl.se/windows/dl-7.85.0/curl-7.85.0-win32-mingw.zip" -o .\curl.zip Expand-Archive ./curl.zip -DestinationPath ./curl - Copy-Item ./curl/curl-7.81.0-win32-mingw/bin/curl.exe ./winenv/bin - Copy-Item ./curl/curl-7.81.0-win32-mingw/bin/curl-ca-bundle.crt ./winenv/bin + Copy-Item ./curl/curl-7.85.0-win32-mingw/bin/curl.exe ./winenv/bin + Copy-Item ./curl/curl-7.85.0-win32-mingw/bin/curl-ca-bundle.crt ./winenv/bin $version = (Get-Command xmake/xmake.exe).FileVersionInfo ./nsis/makensis.exe /DMAJOR=$($version.ProductMajorPart) /DMINOR=$($version.ProductMinorPart) /DALTER=$($version.ProductBuildPart) /DBUILD=$($($version.ProductVersion -split '\+')[1]) /D${{ matrix.arch }} .\scripts\installer.nsi (New-Item ./artifacts/${{env.RELEASE_NAME}} -ItemType Directory).FullName diff --git a/CHANGELOG.md b/CHANGELOG.md index 62d71e1a8..9bc5e8f68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Changes + +* [#3318](https://github.com/xmake-io/xmake/pull/3318): Improve dlang toolchains + ## v2.7.6 ### New features @@ -1510,6 +1514,10 @@ ## master (开发中) +### 改进 + +* [#3318](https://github.com/xmake-io/xmake/pull/3318): 改进 dlang 工具链 + ## v2.7.6 ### 新特性 @@ -251,7 +251,10 @@ clang-cl LLVM Clang C/C++ Compiler compatible with msvc yasm The Yasm Modular Assembler clang A C language family frontend for LLVM go Go Programming Language Compiler -dlang D Programming Language Compiler +dlang D Programming Language Compiler (Auto) +dmd D Programming Language Compiler +ldc The LLVM-based D Compiler +gdc The GNU D Compiler (GDC) gfortran GNU Fortran Programming Language Compiler zig Zig Programming Language Compiler sdcc Small Device C Compiler diff --git a/README_zh.md b/README_zh.md index 610664935..e4ef2ae93 100644 --- a/README_zh.md +++ b/README_zh.md @@ -260,7 +260,10 @@ clang-cl LLVM Clang C/C++ Compiler compatible with msvc yasm The Yasm Modular Assembler clang A C language family frontend for LLVM go Go Programming Language Compiler -dlang D Programming Language Compiler +dlang D Programming Language Compiler (Auto) +dmd D Programming Language Compiler +ldc The LLVM-based D Compiler +gdc The GNU D Compiler (GDC) gfortran GNU Fortran Programming Language Compiler zig Zig Programming Language Compiler sdcc Small Device C Compiler diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index ea70ed8e2..f87b422d0 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -40,7 +40,7 @@ platform("linux") set_installdir("/usr/local") -- set toolchains - set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust", "swift", "gfortran", "zig", "fpc", "nim") + set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "go", "rust", "swift", "gfortran", "zig", "fpc", "nim") -- set menu set_menu { diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index c7465b109..298e6dd2d 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -40,7 +40,7 @@ platform("macosx") set_installdir("/usr/local") -- set toolchains - set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig", "fpc", "nim") + set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "rust", "go", "gfortran", "zig", "fpc", "nim") -- set menu set_menu { diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 6dc3d7682..2b83bb34d 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -38,7 +38,7 @@ platform("windows") set_formats("symbol", "$(name).pdb") -- set toolchains - set_toolchains("msvc", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "swift", "go", "gfortran", "zig", "fpc", "nim") + set_toolchains("msvc", "clang", "yasm", "nasm", "cuda", "rust", "swift", "go", "gfortran", "zig", "fpc", "nim") -- set menu set_menu { diff --git a/xmake/rules/dlang/xmake.lua b/xmake/rules/dlang/xmake.lua index 3e123e0d8..cebbaef3e 100644 --- a/xmake/rules/dlang/xmake.lua +++ b/xmake/rules/dlang/xmake.lua @@ -18,12 +18,16 @@ -- @file xmake.lua -- --- define rule: dlang.build rule("dlang.build") set_sourcekinds("dc") on_build_files("private.action.build.object", {batch = true}) + on_load(function (target) + local toolchains = target:get("toolchains") or get_config("toolchain") + if not toolchains or not table.contains(table.wrap(toolchains), "dlang", "dmd", "ldc", "gdc") then + target:add("toolchains", "dlang") + end + end) --- define rule: dlang rule("dlang") -- add build rules diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua index 17e5f36b1..4f828d544 100644 --- a/xmake/toolchains/dlang/xmake.lua +++ b/xmake/toolchains/dlang/xmake.lua @@ -20,30 +20,18 @@ -- define toolchain toolchain("dlang") - - -- set homepage set_homepage("https://dlang.org/") - set_description("D Programming Language Compiler") + set_description("D Programming Language Compiler (Auto)") - -- check toolchain on_check("check") - -- on load on_load(function (toolchain) - - -- imports - import("core.project.config") - - -- get cross prefix local cross = toolchain:cross() or "" - - -- set toolset toolchain:add("toolset", "dc", "$(env DC)", "dmd", "ldc2", cross .. "gdc") toolchain:add("toolset", "dcld", "$(env DC)", "dmd", "ldc2", cross .. "gdc") toolchain:add("toolset", "dcsh", "$(env DC)", "dmd", "ldc2", cross .. "gdc") toolchain:add("toolset", "dcar", "$(env DC)", "dmd", "ldc2", cross .. "gcc-ar") - -- init flags local march if toolchain:is_arch("x86_64", "x64") then march = "-m64" diff --git a/xmake/toolchains/dmd/xmake.lua b/xmake/toolchains/dmd/xmake.lua new file mode 100644 index 000000000..d9ab947a6 --- /dev/null +++ b/xmake/toolchains/dmd/xmake.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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +toolchain("dmd") + set_homepage("https://dlang.org/") + set_description("D Programming Language Compiler") + + on_check(function (toolchain) + import("lib.detect.find_tool") + if find_tool("dmd") then + return true + end + end) + + on_load(function (toolchain) + local cross = toolchain:cross() or "" + toolchain:add("toolset", "dc", "dmd") + toolchain:add("toolset", "dcld", "dmd") + toolchain:add("toolset", "dcsh", "dmd") + toolchain:add("toolset", "dcar", "dmd") + + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + toolchain:add("dcflags", march or "") + toolchain:add("dcshflags", march or "") + toolchain:add("dcldflags", march or "") + end) diff --git a/xmake/toolchains/gdc/check.lua b/xmake/toolchains/gdc/check.lua new file mode 100644 index 000000000..7df55de8b --- /dev/null +++ b/xmake/toolchains/gdc/check.lua @@ -0,0 +1,52 @@ +--!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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("lib.detect.find_tool") +import("detect.sdks.find_cross_toolchain") + +function main(toolchain) + + -- we attempt to find gdc in $PATH + if find_tool("gdc") then + return true + end + + -- we need find gdc2 in the given toolchain sdk directory + local sdkdir = toolchain:sdkdir() + local bindir = toolchain:bindir() + local cross = toolchain:cross() + if not sdkdir and not bindir and not cross then + return + end + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross}) + if cross_toolchain then + toolchain:config_set("cross", cross_toolchain.cross) + toolchain:config_set("bindir", cross_toolchain.bindir) + toolchain:config_set("sdkdir", cross_toolchain.sdkdir) + toolchain:configs_save() + else + raise("cross toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/gdc/xmake.lua b/xmake/toolchains/gdc/xmake.lua new file mode 100644 index 000000000..de06eb4af --- /dev/null +++ b/xmake/toolchains/gdc/xmake.lua @@ -0,0 +1,44 @@ +--!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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("gdc") + set_homepage("https://gdcproject.org/") + set_description("The GNU D Compiler (GDC).") + + on_check("check") + + on_load(function (toolchain) + local cross = toolchain:cross() or "" + toolchain:add("toolset", "dc", cross .. "gdc") + toolchain:add("toolset", "dcld", cross .. "gdc") + toolchain:add("toolset", "dcsh", cross .. "gdc") + toolchain:add("toolset", "dcar", cross .. "gcc-ar") + + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + toolchain:add("dcflags", march or "") + toolchain:add("dcshflags", march or "") + toolchain:add("dcldflags", march or "") + end) diff --git a/xmake/toolchains/ldc/check.lua b/xmake/toolchains/ldc/check.lua new file mode 100644 index 000000000..44f6a9a63 --- /dev/null +++ b/xmake/toolchains/ldc/check.lua @@ -0,0 +1,52 @@ +--!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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("lib.detect.find_tool") +import("detect.sdks.find_cross_toolchain") + +function main(toolchain) + + -- we attempt to find ldc2 in $PATH + if find_tool("ldc2") then + return true + end + + -- we need find ldc2 in the given toolchain sdk directory + local sdkdir = toolchain:sdkdir() + local bindir = toolchain:bindir() + local cross = toolchain:cross() + if not sdkdir and not bindir and not cross then + return + end + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross}) + if cross_toolchain then + toolchain:config_set("cross", cross_toolchain.cross) + toolchain:config_set("bindir", cross_toolchain.bindir) + toolchain:config_set("sdkdir", cross_toolchain.sdkdir) + toolchain:configs_save() + else + raise("cross toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/ldc/xmake.lua b/xmake/toolchains/ldc/xmake.lua new file mode 100644 index 000000000..864d8665e --- /dev/null +++ b/xmake/toolchains/ldc/xmake.lua @@ -0,0 +1,43 @@ +--!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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("ldc") + set_homepage("https://github.com/ldc-developers/ldc") + set_description("The LLVM-based D Compiler.") + + on_check("check") + + on_load(function (toolchain) + toolchain:add("toolset", "dc", "ldc2") + toolchain:add("toolset", "dcld", "ldc2") + toolchain:add("toolset", "dcsh", "ldc2") + toolchain:add("toolset", "dcar", "ldc2") + + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + toolchain:add("dcflags", march or "") + toolchain:add("dcshflags", march or "") + toolchain:add("dcldflags", march or "") + end) |
