summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-06-14 23:15:31 +0800
committerGitHub <[email protected]>2022-06-14 23:15:31 +0800
commit35f5b02e861858a98de4f00b71de9945cc54f567 (patch)
tree3f57666417ec176a1ee49cbf8c390bfe2eb30d02
parent8907619e5351eac46d00dbd5ef8e7c0cfadf8142 (diff)
parent8178635d44e40298437591d17fa9a47a40b9e7fc (diff)
Merge pull request #2461 from xmake-io/opti
Improve optimize for emcc
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/languages/c++/xmake.lua2
-rw-r--r--xmake/modules/core/tools/clang.lua25
-rw-r--r--xmake/modules/core/tools/dmd.lua23
-rw-r--r--xmake/modules/core/tools/emcc.lua16
-rw-r--r--xmake/modules/core/tools/fpc.lua23
-rw-r--r--xmake/modules/core/tools/gcc.lua22
-rw-r--r--xmake/modules/core/tools/go.lua13
-rw-r--r--xmake/modules/core/tools/nim.lua25
-rw-r--r--xmake/modules/core/tools/nvcc.lua28
-rw-r--r--xmake/modules/core/tools/rustc.lua25
-rw-r--r--xmake/modules/core/tools/sdcc.lua25
-rw-r--r--xmake/modules/core/tools/swiftc.lua29
13 files changed, 159 insertions, 99 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 359601d3c..fdd48e6da 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@
* [#2434](https://github.com/xmake-io/xmake/issues/2434): Improve plugins manager, allow to handle multiples plugin repositories
* [#2421](https://github.com/xmake-io/xmake/issues/2421): Improve config option menu
* [#2425](https://github.com/xmake-io/xmake/issues/2425): Add `preprocessor.gcc.directives_only` policy
+* [#2455](https://github.com/xmake-io/xmake/issues/2455): Improve optimize options for emcc
### Bugs Fixed
@@ -1323,6 +1324,7 @@
* [#2434](https://github.com/xmake-io/xmake/issues/2434): 改进插件管理器,允许多插件管理
* [#2421](https://github.com/xmake-io/xmake/issues/2421): 改进配置选项菜单
* [#2425](https://github.com/xmake-io/xmake/issues/2425): 添加 `preprocessor.gcc.directives_only` 策略
+* [#2455](https://github.com/xmake-io/xmake/issues/2455): 改进 emcc 的优化选项
### Bugs 修复
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 52c7baa91..6d4b48b2b 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -65,6 +65,7 @@ language("c++")
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
+ , "target.optimize:check"
, "target.runtimes"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
@@ -87,6 +88,7 @@ language("c++")
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
+ , "target.optimize:check"
, "target.runtimes"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
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