summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-19 22:39:51 +0800
committerruki <[email protected]>2020-05-19 09:59:07 +0800
commit6ee9db874fcfeb94fcc06982f132ea469ec98e0e (patch)
tree85d36f6fed4718827bfec3267ef62cef27dedda1
parent5dfb51f3e1c06c07097158153f39c45830029685 (diff)
add dlang toolchain
-rw-r--r--xmake/core/tool/toolchain.lua9
-rw-r--r--xmake/modules/core/tools/dmd.lua23
-rw-r--r--xmake/platforms/macosx/xmake.lua2
-rw-r--r--xmake/toolchains/dlang/xmake.lua36
-rw-r--r--xmake/toolchains/envs/xmake.lua2
5 files changed, 64 insertions, 8 deletions
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index d915ffcf8..032445b3d 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -187,7 +187,12 @@ function _instance:_checktool(toolkind, toolpath)
if sandbox_inst then
local filter = sandbox_inst:filter()
if filter then
- toolpath = filter:handle(toolpath)
+ local value = filter:handle(toolpath)
+ if value and value:trim() ~= "" then
+ toolpath = value
+ else
+ return
+ end
end
end
@@ -207,7 +212,7 @@ function _instance:_checktool(toolkind, toolpath)
if program then
utils.cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program))
else
- utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name)
+ utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, toolpath)
end
end
return program, toolname
diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua
index 4d74c21ae..378c68642 100644
--- a/xmake/modules/core/tools/dmd.lua
+++ b/xmake/modules/core/tools/dmd.lua
@@ -134,15 +134,30 @@ end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
- local flag = "-L-rpath=" .. os.args(dir)
- if self:has_flags(flag) then
- return flag
+ dir = path.translate(dir)
+ if self:has_flags("-L-rpath=" .. dir, "ldflags") then
+ return "-L-rpath=" .. os.args(dir:gsub("@[%w_]+", function (name)
+ local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
+ return maps[name]
+ end))
+
+ elseif self:has_flags("-L-rpath -L" .. dir, "ldflags") then
+ return "-L-rpath -L" .. os.args(dir:gsub("%$ORIGIN", "@loader_path"))
end
end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags)
- return self:program(), table.join(flags, "-of" .. targetfile, objectfiles)
+
+ -- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
+ local flags_extra = {}
+ if targetkind == "shared" and is_plat("macosx") then
+ table.insert(flags_extra, "-L-install_name")
+ table.insert(flags_extra, "-L@rpath/" .. path.filename(targetfile))
+ end
+
+ -- init arguments
+ return self:program(), table.join(flags, flags_extra, "-of" .. targetfile, objectfiles)
end
-- link the target file
diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua
index 85e646851..aef9fb37e 100644
--- a/xmake/platforms/macosx/xmake.lua
+++ b/xmake/platforms/macosx/xmake.lua
@@ -41,7 +41,7 @@ platform("macosx")
-- set toolchains
-- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda")
- set_toolchains("envs", "xcode", "clang", "gcc")
+ set_toolchains("envs", "xcode", "clang", "gcc", "dlang")
-- set menu
set_menu {
diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua
new file mode 100644
index 000000000..1ce144f8e
--- /dev/null
+++ b/xmake/toolchains/dlang/xmake.lua
@@ -0,0 +1,36 @@
+--!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("dlang")
+
+ -- set toolsets
+ set_toolsets("dc", "dmd", "ldc2", "gdc")
+ set_toolsets("dcld", "dmd", "ldc2", "gdc")
+ set_toolsets("dcsh", "dmd", "ldc2", "gdc")
+ set_toolsets("dcar", "dmd", "ldc2", "gdc")
+
+ -- on load
+ on_load(function (toolchain)
+ local march = is_arch("x86_64", "x64") and "-m64" or "-m32"
+ toolchain:add("dcflags", march)
+ toolchain:add("dcshflags", march)
+ toolchain:add("dcldflags", march)
+ end)
diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua
index 401f6d72b..1fc043025 100644
--- a/xmake/toolchains/envs/xmake.lua
+++ b/xmake/toolchains/envs/xmake.lua
@@ -33,7 +33,7 @@ toolchain("envs")
set_toolsets("mm", "$(env MM)")
set_toolsets("mxx", "$(env MXX)")
set_toolsets("as", "$(env AS)")
- set_toolsets("dc", "$(env DC")
+ set_toolsets("dc", "$(env DC)")
set_toolsets("sc", "$(env SC)")
set_toolsets("gc", "$(env GC)")
set_toolsets("rc", "$(env RC)")