Skip to content

Commit

Permalink
improve ldc
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 29, 2023
1 parent 0e533c2 commit d6f64cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
15 changes: 11 additions & 4 deletions xmake/modules/core/tools/dmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ end

-- make the symbol flag
function nf_symbol(self, level)
local maps = {
debug = "-g -debug"
}
return maps[level]
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps = {
debug = {"-g", "-debug"}
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
end
end

-- make the warning flag
Expand Down
29 changes: 19 additions & 10 deletions xmake/modules/core/tools/ldc2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-- imports
inherit("dmd")
import("core.language.language")

-- init it
function init(self)
Expand All @@ -37,20 +38,28 @@ 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"}
none = "--O0"
, fast = "--O1"
, faster = {"--O2", "--release"}
, fastest = {"--O3", "--release", "--boundscheck=off"}
, smallest = {"--Oz", "--release", "--boundscheck=off"}
, aggressive = {"--O4", "--release", "--boundscheck=off"}
}
return maps[level]
end

-- make the symbol flag
function nf_symbol(self, level)
local maps = {
debug = "-g --d-debug"
}
return maps[level]
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
if not maps then
maps = {
debug = {"-g", "--d-debug"}
, hidden = "-fvisibility=hidden"
}
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
end
end

6 changes: 3 additions & 3 deletions xmake/rules/dlang/build_optimization/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import("core.project.project")
function _add_lto_optimization(target)
if target:has_tool("dc", "ldc2") and target:has_tool("dcld", "ldc2") then
target:add("dcflags", "-flto=thin", {force = true})
target:add("ldflags", "-flto=thin", {force = true})
target:add("shflags", "-flto=thin", {force = true})
-- to use the link-time optimizer, -flto and optimization options should be specified at compile time and during the final link.
target:add("ldflags", "-flto=thin", "-defaultlib=phobos2-ldc-lto,druntime-ldc-lto", {force = true})
target:add("shflags", "-flto=thin", "-defaultlib=phobos2-ldc-lto,druntime-ldc-lto", {force = true})
-- to use the link-time optimizer, lto and optimization options should be specified at compile time and during the final link.
-- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
local optimize = target:get("optimize")
if optimize then
Expand Down

0 comments on commit d6f64cf

Please sign in to comment.