diff options
| author | ruki <[email protected]> | 2022-06-15 00:08:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-06-14 20:12:57 +0800 |
| commit | db62122ed2aab5ea823ea80617e673bfedfeb28b (patch) | |
| tree | 8898612c00662fe41573fc2919a18b38fc9ddb6b /xmake/modules | |
| parent | c96e777d90a4cec5941896680191f50e47e0d247 (diff) | |
improve optimize for emcc
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 25 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/core/tools/emcc.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/fpc.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 22 | ||||
| -rw-r--r-- | xmake/modules/core/tools/go.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nim.lua | 25 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rustc.lua | 25 | ||||
| -rw-r--r-- | xmake/modules/core/tools/sdcc.lua | 25 | ||||
| -rw-r--r-- | xmake/modules/core/tools/swiftc.lua | 29 |
11 files changed, 155 insertions, 99 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index e5734a953..ef0a379da 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -20,6 +20,7 @@ -- inherit gcc inherit("gcc") +import("core.language.language") -- init it function init(self) @@ -98,16 +99,20 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Oz" -- smaller than -Os - , aggressive = "-Ofast" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Oz" -- smaller than -Os + , aggressive = "-Ofast" + } + return maps[level] + end end -- make the warning flag diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 3f29da28f..e3785c680 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") +import("core.language.language") -- init it function init(self) @@ -38,15 +39,19 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - fast = "-O" - , faster = "-O -release" - , fastest = "-O -release -inline -boundscheck=off" - , smallest = "-O -release -boundscheck=off" - , aggressive = "-O -release -inline -boundscheck=off" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + fast = "-O" + , faster = "-O -release" + , fastest = "-O -release -inline -boundscheck=off" + , smallest = "-O -release -boundscheck=off" + , aggressive = "-O -release -inline -boundscheck=off" + } + return maps[level] + end end -- make the strip flag diff --git a/xmake/modules/core/tools/emcc.lua b/xmake/modules/core/tools/emcc.lua index a443f43f6..8c08e4b0d 100644 --- a/xmake/modules/core/tools/emcc.lua +++ b/xmake/modules/core/tools/emcc.lua @@ -21,6 +21,22 @@ -- inherit gcc inherit("gcc") +-- make the optimize flag +-- +-- same options must be used at compile and link, @see https://github.com/xmake-io/xmake/issues/2455 +-- https://emscripten.org/docs/compiling/Building-Projects.html?highlight=optimization#building-projects-optimizations +function nf_optimize(self, level) + local maps = { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-O3" + } + return maps[level] +end + -- make the strip flag function nf_strip(self, level) end diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 98b746c8a..57af7a45b 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") +import("core.language.language") -- init it function init(self) @@ -32,15 +33,19 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - none = "-O-" - , fast = "-O1" - , fastest = "-O3" - , smallest = "-O2" - , aggressive = "-O4" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "-O-" + , fast = "-O1" + , fastest = "-O3" + , smallest = "-O2" + , aggressive = "-O4" + } + return maps[level] + end end -- make the strip flag diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index dbb8dbd75..a495f2696 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -135,15 +135,19 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Os" - , aggressive = "-Ofast" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" + } + return maps[level] + end end -- make the vector extension flag diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index 2b2b76623..51f5709af 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") +import("core.language.language") -- init it function init(self) @@ -30,10 +31,14 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = { - none = "-N" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = { + none = "-N" + } + return maps[level] + end end -- make the symbol flag diff --git a/xmake/modules/core/tools/nim.lua b/xmake/modules/core/tools/nim.lua index 0eece46cf..5e73c3eb4 100644 --- a/xmake/modules/core/tools/nim.lua +++ b/xmake/modules/core/tools/nim.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") +import("core.language.language") -- init it -- @@ -62,16 +63,20 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - none = "--opt:none" - , fast = "-d:release" - , faster = "-d:release" - , fastest = "-d:release" - , smallest = {"-d:release", "--opt:size"} - , aggressive = "-d:danger" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "--opt:none" + , fast = "-d:release" + , faster = "-d:release" + , fastest = "-d:release" + , smallest = {"-d:release", "--opt:size"} + , aggressive = "-d:danger" + } + return maps[level] + end end -- make the symbol flag diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index ac4a6efef..823872b5e 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -150,20 +150,20 @@ end -- make the optimize flag function nf_optimize(self, level) - - -- the maps - local maps = - { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Os" - , aggressive = "-Ofast" - } - - -- make it - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" + } + return maps[level] + end end -- make the language flag diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index ab41620cd..c16c6261c 100644 --- a/xmake/modules/core/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") +import("core.language.language") -- init it function init(self) @@ -29,16 +30,20 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - none = "-C opt-level=0" - , fast = "-C opt-level=1" - , faster = "-C opt-level=2" - , fastest = "-C opt-level=3" - , smallest = "-C opt-level=s" - , aggressive = "-C opt-level=z" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "-C opt-level=0" + , fast = "-C opt-level=1" + , faster = "-C opt-level=2" + , fastest = "-C opt-level=3" + , smallest = "-C opt-level=s" + , aggressive = "-C opt-level=z" + } + return maps[level] + end end -- make the symbol flag diff --git a/xmake/modules/core/tools/sdcc.lua b/xmake/modules/core/tools/sdcc.lua index 4605f12f8..c991d888e 100644 --- a/xmake/modules/core/tools/sdcc.lua +++ b/xmake/modules/core/tools/sdcc.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.base.global") import("utils.progress") +import("core.language.language") -- init it function init(self) @@ -79,16 +80,20 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - none = "" - , fast = "--opt-code-speed" - , faster = "--opt-code-speed" - , fastest = "--opt-code-speed" - , smallest = "--opt-code-size" - , aggressive = "--opt-code-speed" - } - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "" + , fast = "--opt-code-speed" + , faster = "--opt-code-speed" + , fastest = "--opt-code-speed" + , smallest = "--opt-code-size" + , aggressive = "--opt-code-speed" + } + return maps[level] + end end -- make the language flag diff --git a/xmake/modules/core/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua index 0788635bc..948e408ab 100644 --- a/xmake/modules/core/tools/swiftc.lua +++ b/xmake/modules/core/tools/swiftc.lua @@ -20,6 +20,7 @@ -- imports import("core.project.config") +import("core.language.language") -- init it function init(self) @@ -103,20 +104,20 @@ end -- make the optimize flag function nf_optimize(self, level) - - -- the maps - local maps = - { - none = "-Onone" - , fast = "-O" - , faster = "-O" - , fastest = "-O" - , smallest = "-O" - , aggressive = "-Ounchecked" - } - - -- make it - return maps[level] + -- only for source kind + local kind = self:kind() + if language.sourcekinds()[kind] then + local maps = + { + none = "-Onone" + , fast = "-O" + , faster = "-O" + , fastest = "-O" + , smallest = "-O" + , aggressive = "-Ounchecked" + } + return maps[level] + end end -- make the vector extension flag |
