summaryrefslogtreecommitdiff
path: root/xmake/rules/dlang/build_optimization/config.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-01-29 13:31:18 +0800
committerruki <[email protected]>2023-01-29 13:31:18 +0800
commitdd1e63c09b84c0fd0b886503da3cc468ef7ea0a5 (patch)
treefcffd63076a8292e0572651fe44248d08657e5b7 /xmake/rules/dlang/build_optimization/config.lua
parentc2dffcc808eea9bd15adc5842b6a2636a5138409 (diff)
add lto for ldc2
Diffstat (limited to 'xmake/rules/dlang/build_optimization/config.lua')
-rw-r--r--xmake/rules/dlang/build_optimization/config.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/xmake/rules/dlang/build_optimization/config.lua b/xmake/rules/dlang/build_optimization/config.lua
new file mode 100644
index 000000000..6de97dfdd
--- /dev/null
+++ b/xmake/rules/dlang/build_optimization/config.lua
@@ -0,0 +1,47 @@
+--!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 config.lua
+--
+
+-- imports
+import("core.tool.compiler")
+import("core.project.project")
+
+-- add lto optimization
+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.
+ -- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
+ local optimize = target:get("optimize")
+ if optimize then
+ local optimize_flags = compiler.map_flags("dc", "optimize", optimize)
+ target:add("ldflags", optimize_flags)
+ target:add("shflags", optimize_flags)
+ end
+ end
+end
+
+function main(target)
+ if target:policy("build.optimization.lto") or
+ project.policy("build.optimization.lto") then
+ _add_lto_optimization(target)
+ end
+end