xmake 错误的把 clang 的编译参数检测通过了
Xmake 版本
xmake v2.9.9+20250511
操作系统版本和架构
AOSC OS linux, amd64
描述问题
通过这里例子,可以看到xmake检测认为-Wno-c++98-compat-pedantic和-Wno-c++98-compat是gcc认识的flag,实际gcc不认识。
压缩包里提供了文件,我们先截图描述问题。
复现步骤,
- xmake f -c
- xmake -rv
可以看到检测通过,但是被gcc自身报note信息。
通过 gcc --help=warnings | grep compat 也能看到不存在-Wno-c++98-compat参数。
期待的结果
我期待检测时应该fail,并且不要传递给 gcc
工程配置
add_rules("mode.debug", "mode.release")
set_defaultmode("debug")
add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})
set_policy("package.install_only", true)
set_policy("run.autobuild", true)
set_policy("build.warning", true)
target("justtest")
set_kind("binary")
add_files("src/main.cpp")
set_warnings("all", "extra")
set_languages("c++23")
add_cxxflags("-pedantic-errors")
add_cxxflags("-Wno-c++98-compat") --clang
add_cxxflags("-Wno-c++98-compat-pedantic") --clang
set_warnings("everything")
附加信息和错误日志
xffish@aosc-rog [ justtest-xmake-issue ] $ xmake -rvD
checking for gcc ... /usr/local/bin/gcc
checking for the c++ compiler (cxx) ... gcc
checking for /usr/local/bin/gcc ... ok
checking for flags (-fPIC) ... ok
> gcc "-fPIC" "-m64"
checking for flags (-fvisibility-inlines-hidden) ... ok
> gcc "-fvisibility-inlines-hidden" "-m64"
checking for flags (-O0) ... ok
> gcc "-O0" "-m64"
checking for flags (-std=c++23) ... ok
> gcc "-std=c++23" "-m64"
checking for flags (-pedantic-errors) ... ok
> gcc "-pedantic-errors" "-m64"
checking for flags (-Wno-c++98-compat) ... ok
> gcc "-Wno-c++98-compat" "-m64"
checking for flags (-Wno-c++98-compat-pedantic) ... ok
> gcc "-Wno-c++98-compat-pedantic" "-m64"
[ 50%]: cache compiling.debug src/main.cpp
/usr/local/bin/gcc -c -m64 -g -Wall -Wextra -Weffc++ -O0 -std=c++23 -Ibuild/.gens/justtest/linux/x86_64/debug/platform/windows/idl -pedantic-errors -Wno-c++98-compat -Wno-c++98-compat-pedantic -o build/.objs/justtest/linux/x86_64/debug/src/main.cpp.o src/main.cpp
checking for flags (-MMD -MF) ... ok
> gcc "-MMD" "-MF" "/dev/null" "-m64"
checking for flags (-fdiagnostics-color=always) ... ok
> gcc "-fdiagnostics-color=always" "-m64"
checking for flags (-Wno-gnu-line-marker -Werror) ... ok
> gcc "-Wno-gnu-line-marker" "-Werror" "-m64"
src/main.cpp: In function ‘int main()’:
src/main.cpp:5:22: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
5 | for (int i = 1u; i < s.size(); i++) {
| ~~^~~~~~~~~~
在全局域:
cc1plus: 附注:unrecognized command-line option ‘-Wno-gnu-line-marker’ may have been intended to silence earlier diagnostics
cc1plus: 附注:unrecognized command-line option ‘-Wno-c++98-compat-pedantic’ may have been intended to silence earlier diagnostics
cc1plus: 附注:unrecognized command-line option ‘-Wno-c++98-compat’ may have been intended to silence earlier diagnostics
checking for g++ ... /usr/local/bin/g++
checking for the linker (ld) ... g++
checking for /usr/local/bin/g++ ... ok
checking for flags (-fPIC) ... ok
> g++ "-fPIC" "-m64" "-m64"
[ 75%]: linking.debug justtest
/usr/local/bin/g++ -o build/linux/x86_64/debug/justtest build/.objs/justtest/linux/x86_64/debug/src/main.cpp.o -m64
build cache stats:
cache directory: /home/xffish/workspace_cpp/justtest-xmake-issue/build/.build_cache
cache hit rate: 100%
cache hit: 1
cache hit total time: 0.000s
cache miss: 0
cache miss total time: 0.000s
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.000s
[100%]: build ok, spent 0.436s
Bot detected the issue body's language is not English, translate it automatically.
Title: xmake mistakenly detected the compile parameter of clang
目前 flags 检测原本就不是完全准的,不要太依赖这个。而且这边是通过尝试编译来检测的,只要加了 flags 不影响编译导致失败,都会通过。
Bot detected the issue body's language is not English, translate it automatically.
At present, flags detection is not completely accurate, don't rely too much on this. Moreover, this is detected by trying to compile. As long as flags is added, it will pass if it does not affect the compilation and fails.
有群友说“gcc help列出来的flag有没有占到10%都得打个问号”,那好吧,本issue不合理,关闭。
Bot detected the issue body's language is not English, translate it automatically.
Some group members said, "If there is any flag listed in gcc help accounts for 10%, it needs to be questioned." Well, this issue is unreasonable, so close it.
help 列出来的原本就少,而且像 -Wxxx 这种的,根本不可能在 help 里面每个 Warnings 挨个给你列出来,help 检测只是加速常用 flags 的快速检测,其他的 fallback 到尝试编译检测,依赖编译是否通过。像这种只是 警告,不会编译报错的,很难全部检测出来,而且不影响编译。
Bot detected the issue body's language is not English, translate it automatically.
There are only a few lists of help, and it is impossible for each Warnings to be listed one by one in help in help. Help detection only accelerates the rapid detection of commonly used flags, and other fallbacks try to compile and detect, depending on whether the compilation passes. Such things are just warnings and will not compile errors, and it is difficult to detect them all, and they will not affect the compilation.