diff options
| author | ruki <[email protected]> | 2020-07-31 17:45:29 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-31 17:45:29 +0800 |
| commit | 02ffe167ede48cc1c7cfc012c6f1b6b8f12a2f07 (patch) | |
| tree | 2e658c8b128d6bbd45a81bc41049002b996d7eee /xmake/modules | |
| parent | deeef0bf58b2cc3a4389c782d7705ddf7c932f56 (diff) | |
| parent | c05b341f43ab99a6670773d524197411be81b5ea (diff) | |
Merge pull request #910 from xmake-io/dlang
Improve ldc2 and gdc support for dlang
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/ar.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gdc.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ldc2.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/has_flags.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gdc/has_flags.lua | 102 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/ldc2/has_flags.lua (renamed from xmake/modules/detect/tools/ldc/has_flags.lua) | 0 |
6 files changed, 153 insertions, 15 deletions
diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index 3e520f887..0a8dec91d 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -25,6 +25,7 @@ import("private.utils.progress") -- init it function init(self) self:set("arflags", "-cr") + self:set("dcarflags", "-cr") -- for dlang/gdc, e.g. x86_64-unknown-linux-gnu-gcc-ar end -- make the strip flag diff --git a/xmake/modules/core/tools/gdc.lua b/xmake/modules/core/tools/gdc.lua index 70da6d389..9f42c69be 100644 --- a/xmake/modules/core/tools/gdc.lua +++ b/xmake/modules/core/tools/gdc.lua @@ -11,15 +11,40 @@ -- 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 +-- @author ruki, BarrOff -- @file gdc.lua -- --- inherit dmd -inherit("dmd") +-- imports +inherit("gcc") + +-- init it +function init(self) + + -- init arflags + self:set("dcarflags", "-cr") + + -- init shflags + self:set("dcshflags", "-shared", "-fPIC") + + -- init dcflags for the kind: shared + self:set("shared.dcflags", "-fPIC") +end +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + fast = "-O" + , faster = "-O -frelease" + , fastest = "-O -frelease -fbounds-check=off" + , smallest = "-O -frelease -fbounds-check=off" + , aggressive = "-O -frelease -fbounds-check=off" + } + return maps[level] +end diff --git a/xmake/modules/core/tools/ldc2.lua b/xmake/modules/core/tools/ldc2.lua index 9cf9fd48b..d564281c4 100644 --- a/xmake/modules/core/tools/ldc2.lua +++ b/xmake/modules/core/tools/ldc2.lua @@ -11,28 +11,40 @@ -- 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 +-- @author ruki, BarrOff -- @file ldc2.lua -- --- inherit dmd +-- imports inherit("dmd") -- init it function init(self) - - -- init super - _super.init(self) + + -- init arflags + self:set("dcarflags", "-lib") -- init shflags - self:set("dcshflags", "-shared") + self:set("dcshflags", "-shared", "--relocation-model=pic") - -- init cxflags for the kind: shared - self:set("shared.dcflags", "") + -- init dcflags for the kind: shared + self:set("shared.dcflags", "--relocation-model=pic") end +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + fast = "-O" + , faster = "-O --release" + , fastest = "-O --release --boundscheck=off" + , smallest = "-O --release --boundscheck=off" + , aggressive = "-O --release --boundscheck=off" + } + return maps[level] +end diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua index 04956998b..43d4ea53e 100644 --- a/xmake/modules/detect/tools/gcc/has_flags.lua +++ b/xmake/modules/detect/tools/gcc/has_flags.lua @@ -33,7 +33,7 @@ function _islinker(flags, opt) -- the tool kind is ld or sh? local toolkind = opt.toolkind or "" - return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") + return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh") end -- try running diff --git a/xmake/modules/detect/tools/gdc/has_flags.lua b/xmake/modules/detect/tools/gdc/has_flags.lua index bc4987385..b16c07bc3 100644 --- a/xmake/modules/detect/tools/gdc/has_flags.lua +++ b/xmake/modules/detect/tools/gdc/has_flags.lua @@ -19,5 +19,105 @@ -- -- imports -inherit("detect.tools.dmd.has_flags") +import("lib.detect.cache") +import("core.language.language") + +-- is linker? +function _islinker(flags, opt) + + -- the flags is "-Wl,<arg>" or "-Xlinker <arg>"? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then + return true + end + + -- the tool kind is ld or sh? + local toolkind = opt.toolkind or "" + return toolkind == "dcld" or toolkind == "dcsh" +end + +-- try running +function _try_running(program, argv, opt) + local errors = nil + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt, islinker) + + -- only for compiler + if islinker or #flags > 1 then + return + end + + -- make cache key + local key = "detect.tools.gdc.has_flags" + + -- make flags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- load cache + local cacheinfo = cache.load(key) + + -- get all flags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + cacheinfo[flagskey] = allflags + cache.save(key, cacheinfo) + end + + -- ok? + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt, islinker) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "gdc_has_flags.d") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "void main()\n{}") + end + + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile), opt) + end + + -- check flags for compiler + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile), opt) +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- is linker? + local islinker = _islinker(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt, islinker) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt, islinker) +end + diff --git a/xmake/modules/detect/tools/ldc/has_flags.lua b/xmake/modules/detect/tools/ldc2/has_flags.lua index bc4987385..bc4987385 100644 --- a/xmake/modules/detect/tools/ldc/has_flags.lua +++ b/xmake/modules/detect/tools/ldc2/has_flags.lua |
