xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

The behavior of `set_optimize` is inconsistent on MSVC-related platforms. #5332

Closed ObeliskGate closed 2 months ago

ObeliskGate commented 2 months ago

Xmake 版本

2.9.3

操作系统版本和架构

Windows 11 22H2

描述问题

根据 MSVC 文档, /Ox是弱于/O2的选项, 也就是在 xmake 中应该/Ox对应faster/O2对应fastestaggressive等.

clclang-cl的代码实现也与上述描述相同.

但在文档以及 CMake 相关实现中, 实现为/O2对应faster/Ox对应fastest并且混入了浮点数相关选项, 互相不相符.

而在cl的编译命令mapflags中也有类似的问题: -O3-Ofast都被对应到-Ox而非-O2上并且同样出现了浮点数选项.

我不太清楚会不会导致冲突, 但在浮点数已经有target:set_fpmodels控制的情况下, 这样的映射很可能是不必要的.

这种混乱看上去是由一次不彻底的重构导致的, 期待后续修复.

期待的结果

MSVC 相关平台优化选项表现一致.

工程配置

N/A

附加信息和错误日志

N/A

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


Xmake version

2.9.3

Operating system version and architecture

Windows 11 22H2

Describe the problem

According to MSVC documentation, /Ox is weaker than / The option of O2, that is, in xmake, /Ox should correspond to faster and /O2 should correspond to fastest and aggressive, etc.

cl and [clang-cl](https:/ /github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/modules/core/tools/clang_cl.lua#L101) The code implementation is also the same as the above description.

But in Document and [CMake related implementation](https://github .com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/plugins/project/cmake/cmakelists.lua#L793), implemented as /O2 corresponds to faster and /Ox corresponds to fastest and is mixed in The options related to floating point numbers are inconsistent with each other.

There is also a similar one in cl’s compilation command mapflags Problem: Both -O3 and -Ofast are mapped to -Ox instead of -O2 and floating point options also appear.

I'm not sure whether it will cause conflicts, but when the floating point number is already controlled by target:set_fpmodels, such a mapping Most likely unnecessary.

This chaos appears to be caused by an incomplete refactoring, and we look forward to a subsequent fix.

Expected results

MSVC-related platform optimization options behave consistently.

Project configuration

N/A

Additional information and error logs

N/A

waruqi commented 2 months ago

根据 MSVC 文档, /Ox是弱于/O2的选项, 也就是在 xmake 中应该/Ox对应faster而/O2对应fastest及aggressive等.

现在不就是么,只是文档没更新而已。

https://github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/modules/core/tools/cl.lua#L185-L186

但在文档以及 CMake 相关实现中, 实现为/O2对应faster而/Ox对应fastest并且混入了浮点数相关选项, 互相不相符.

后来更新没同步过去而已,刚改了。

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


According to MSVC documentation, /Ox is weaker than /O2 Options, that is, in xmake, /Ox should correspond to faster and /O2 should correspond to fastest, aggressive, etc.

Isn't that the case now? It's just that the documentation has not been updated.

https://github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/modules/core/tools/cl.lua#L185-L186

But in Document and [CMake related implementation](https:// github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/plugins/project/cmake/cmakelists.lua#L793), the implementation is that /O2 corresponds to faster and /Ox corresponds to fastest, and floating point related options are mixed in. Does not match.

Later, the update just didn't synchronize, so I just changed it.

ObeliskGate commented 2 months ago

后来更新没同步过去而已,刚改了。

改了我就 close 了.

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


Later, the updates were not synchronized, and they were just changed. Once the change is made, I will close it.