cc-rs: Compiler version doesn't include clang or GCC: "cc" "--version"
On Debian Sid:
Output of cc --version, which is different from gcc --version:
cc (Debian 13.2.0-13) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Output of cc -v, which is the same as gcc -v:
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 13.2.0-13' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/reproducible-path/gcc-13-13.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/reproducible-path/gcc-13-13.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Debian 13.2.0-13)
So it’s may be better to use -v to check the compiler type?
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Reactions: 2
- Comments: 20 (1 by maintainers)
Commits related to this issue
- Auto merge of #123644 - dtolnay:cc, r=Mark-Simulacrum Update non-bootstrap `cc` dependency to fix compile family detection warning `x.py check compiler/rustc_llvm` **Before:** (https://github.com/r... — committed to rust-lang-ci/rust by bors 3 months ago
- Auto merge of #123644 - dtolnay:cc, r=Mark-Simulacrum Update non-bootstrap `cc` dependency to fix compile family detection warning `x.py check compiler/rustc_llvm` **Before:** (https://github.com/r... — committed to RalfJung/miri by bors 3 months ago
- Bump cc-rs to 1.0.94 to work around spurious warnings Under Ubuntu 23.10 (gcc 13), older cc crate versions would complain that the compiler could not be identified. See https://github.com/rust-lang/... — committed to fish-shell/fish-shell by mqudsi 2 months ago
- Bump cc-rs to 1.0.94 to work around spurious warnings Under Ubuntu 23.10 (gcc 13), older cc crate versions would complain that the compiler could not be identified. See https://github.com/rust-lang/... — committed to vertesians/fish-shell by mqudsi 2 months ago
For everyone subscribing, #1000 should fix this and once it is merged, I will cut a new release.
Thanks, I will work on a patch once I fixed the make problem.
The standard way to check what version of compiler you have is to analyze the preprocessor definitions defined by the compiler for a trivial program. Simply relying on the output of
--versionis never used in any sane C++ build system.For instance, CMake looks at preprocessor definitions emitted by the compiler to detect compiler versions. It’s usually pretty complex for the more difficult compilers, but this is more reasonable than relying on inspecting the output of
--version. Note: you would have to check clang before gcc since clang pretends to be gcc.Clang:
GCC:
Ok I decided to use the following
.cfile for detecting compiler family:Tested with clang, apple clang and gcc on macOS, mingw gcc and msvc on windows
I don’t know Rust and have never seen this repo before, but it’s affecting some third-party software I’m using that needs this library. (I am, however, very familiar with C/C++.)
Since we’re invoking the compiler to begin with, perhaps we could do a little more work to get something more reliable? For example, we could compile and run a small program like this:
We could get detailed information from this, such as the width of
intand so on. Since we completely control the output, we could construct JSON if we wanted to.I’ve found this list highly useful for compiler detection. There are other lists for detecting OS and host/target architecture.
Waiting for #1015 to merge
Tested Clang and GCC on Ubuntu 23.10 and it works. Thanks!
I’m seeing this too