Skip to content

Commit

Permalink
Merge pull request #3318 from xmake-io/dlang
Browse files Browse the repository at this point in the history
Improve dlang toolchains
  • Loading branch information
waruqi authored Jan 28, 2023
2 parents a41c8f0 + 67b63e3 commit ef438d1
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/windows_luajit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

* [#3318](https://github.com/xmake-io/xmake/pull/3318): Improve dlang toolchains

## v2.7.6

### New features
Expand Down Expand Up @@ -1510,6 +1514,10 @@

## master (开发中)

### 改进

* [#3318](https://github.com/xmake-io/xmake/pull/3318): 改进 dlang 工具链

## v2.7.6

### 新特性
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xmake/platforms/linux/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion xmake/platforms/macosx/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion xmake/platforms/windows/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions xmake/rules/dlang/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions xmake/toolchains/dlang/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions xmake/toolchains/dmd/xmake.lua
Original file line number Diff line number Diff line change
@@ -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)
52 changes: 52 additions & 0 deletions xmake/toolchains/gdc/check.lua
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions xmake/toolchains/gdc/xmake.lua
Original file line number Diff line number Diff line change
@@ -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)
52 changes: 52 additions & 0 deletions xmake/toolchains/ldc/check.lua
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions xmake/toolchains/ldc/xmake.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ef438d1

Please sign in to comment.