-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CMake] Deprecate GCC_INSTALL_PREFIX #77537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Fangrui Song (MaskRay) ChangesPart of https://reviews.llvm.org/D158218 GCC_INSTALL_PREFIX is a rarely-used legacy option inherited from
Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Full diff: https://github.com/llvm/llvm-project/pull/77537.diff 1 Files Affected:
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 9f814478c45503..7076907da2528a 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -193,6 +193,12 @@ set(C_INCLUDE_DIRS "" CACHE STRING
set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
set(DEFAULT_SYSROOT "" CACHE STRING
"Default <path> to all compiler invocations for --sysroot=<path>." )
+if(GCC_INSTALL_PREFIX)
+ message(WARNING "GCC_INSTALL_PREFIX is deprecated and will be removed. Use "
+ "configuration files (https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+ "to specify the default --gcc-install-dir= or --gcc-triple=. --gcc-toolchain= is discouraged. "
+ "The option is often unneeded or better replaced with --gcc-install-dir=/--gcc-triple.")
+endif()
set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of removing this. It doesn't make a lot of sense now that we have better config file support.
Seems okay to me, but it would be good to include an update to the release notes, which ideally shows an example of what replacing the cmake flag with a config file would look like. |
Part of https://reviews.llvm.org/D158218 GCC_INSTALL_PREFIX is a rarely-used legacy option inherited from pre-CMake build system and has configuration file replacement nowadays. Many `clang/test/Driver` tests specify `--gcc-toolchain=` to prevent failures when `GCC_INSTALL_PREFIX` is specified: some contributors add them to fix tests and some just do cargo culting. This is not healthy for contributors adding cross compilation support for this rarely used option. `DEFAULT_SYSROOT` should in spirit be deprecated as well, but a relative path doesn't have good replacement, so don't deprecate it for now. Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833 --- With `GCC_INSTALL_PREFIX=/usr`, `clang a.c` behaves like `clang --gcc-toolchain=/usr a.c`. Here is a simplified version of GCC installation detection code. ``` if (OPT_gcc_install_dir_EQ) return OPT_gcc_install_dir_EQ; if (OPT_gcc_triple) candidate_gcc_triples = {OPT_gcc_triple}; else candidate_gcc_triples = collectCandidateTriples(); if (OPT_gcc_toolchain) prefixes = {OPT_gcc_toolchain}; else prefixes = {OPT_sysroot/usr, OPT_sysroot}; for (prefix : prefixes) if "$prefix/lib/gcc" exists // also tries $prefix/lib/gcc-cross for (triple : candidate_gcc_triples) if "$prefix/lib/gcc/$triple" exists return "$prefix/lib/gcc/$triple/$version"; // pick the largest version ``` `--gcc-toolchain=` specifies a directory where `lib/gcc{,-cross}/$triple/$version` can be found. If you actually want to use a specific version of GCC, specify something like `--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11` in a configuration file. You can also specify `--gcc-triple=`. ``` clang --gcc-toolchain=/usr a.c clang --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11 a.c # specific version clang --gcc-triple=x86_64-linux-gnu a.c ```
36acf7d
to
8bd31c3
Compare
Thanks for the feedback. I have added pseudocode how GCC installation detection works in the description and changed release note/CMake warning to mention this pull request. The Debian example is too long, so I decide not to add too much code in the release node:) |
Are you going to fix gcc search for clang? i build a gcc 14 manually and clang cannot find it on linux. It actually works for x86_64-w64-mingw32-gcc cross compiler on linux. it cannot find any installation i have if gcc is set up in the $PATH.
I mean, it should at least try to find gcc libs in $PATH automatically on linux. |
Part of https://reviews.llvm.org/D158218 GCC_INSTALL_PREFIX is a rarely-used legacy option inherited from pre-CMake build system and has configuration file replacement nowadays. Many `clang/test/Driver` tests specify `--gcc-toolchain=` to prevent failures when `GCC_INSTALL_PREFIX` is specified: some contributors add them to fix tests and some just do cargo culting. This is not healthy for contributors adding cross compilation support for this rarely used option. `DEFAULT_SYSROOT` should in spirit be deprecated as well, but a relative path doesn't have good replacement, so don't deprecate it for now. Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833 --- With `GCC_INSTALL_PREFIX=/usr`, `clang a.c` behaves like `clang --gcc-toolchain=/usr a.c`. Here is a simplified version of GCC installation detection code. ``` if (OPT_gcc_install_dir_EQ) return OPT_gcc_install_dir_EQ; if (OPT_gcc_triple) candidate_gcc_triples = {OPT_gcc_triple}; else candidate_gcc_triples = collectCandidateTriples(); if (OPT_gcc_toolchain) prefixes = {OPT_gcc_toolchain}; else prefixes = {OPT_sysroot/usr, OPT_sysroot}; for (prefix : prefixes) if "$prefix/lib/gcc" exists // also tries $prefix/lib/gcc-cross for (triple : candidate_gcc_triples) if "$prefix/lib/gcc/$triple" exists return "$prefix/lib/gcc/$triple/$version"; // pick the largest version ``` `--gcc-toolchain=` specifies a directory where `lib/gcc{,-cross}/$triple/$version` can be found. If you actually want to use a specific version of GCC, specify something like `--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11` in a configuration file. You can also specify `--gcc-triple=`. On Debian and its derivatives where the target triple omits the vendor part, the following ways are roughly equivalent, except that `--gcc-install-dir=` specifies a version as well: ``` clang --gcc-toolchain=/usr a.c clang --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11 a.c clang --gcc-triple=x86_64-linux-gnu a.c ```
…5458) Setting GCC_INSTALL_PREFIX leads to a warning (#77537). Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
unless USE_DEPRECATED_GCC_INSTALL_PREFIX (temporary escape hatch) is set. Setting GCC_INSTALL_PREFIX leads to a warning for Clang 18.1 (llvm#77537) and will be completely removed for Clang 20. Link: discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
unless USE_DEPRECATED_GCC_INSTALL_PREFIX (temporary escape hatch) is set. Setting GCC_INSTALL_PREFIX leads to a warning for Clang 18.1 (#77537) and will be completely removed for Clang 20. Link: discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
…vm#85458) Setting GCC_INSTALL_PREFIX leads to a warning (llvm#77537). Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
…5891) unless USE_DEPRECATED_GCC_INSTALL_PREFIX (temporary escape hatch) is set. Setting GCC_INSTALL_PREFIX leads to a warning for Clang 18.1 (llvm#77537) and will be completely removed for Clang 20. Link: discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
Upstream want to deprecate `DEFAULT_SYSROOT`[^1][^2][^3], but one blocker is wasi-sdk's usage of it. Let's try to help that along by switching to using config files[^4] instead. This should result in no user-facing changes in functionality. (If it does, then that's an LLVM bug that should be fixed there.) [^1]: https://reviews.llvm.org/D158218 [^2]: llvm/llvm-project#94284 [^3]: llvm/llvm-project#77537 [^4]: https://clang.llvm.org/docs/UsersManual.html#configuration-files
Upstream want to deprecate `DEFAULT_SYSROOT`[^1][^2][^3], but one blocker is wasi-sdk's usage of it. Let's try to help that along by switching to using config files[^4] instead. This should result in no user-facing changes in functionality. (If it does, then that's an LLVM bug that should be fixed there.) [^1]: https://reviews.llvm.org/D158218 [^2]: llvm/llvm-project#94284 [^3]: llvm/llvm-project#77537 [^4]: https://clang.llvm.org/docs/UsersManual.html#configuration-files
Release: https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.5 Major Changes and Fixes: -- CMake 3.20 minimum required -- Issue encountered during standalone LLVM build: CMake Error at CMakeLists.txt:8 (include): include could not find requested file: This error is due to the line: include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake) Upstream commit [1] harmonized policy handling by introducing this shared include for all LLVM sub-projects. However, in the LLVM CMakeLists, LLVM_COMMON_CMAKE_UTILS is set unconditionally, preventing external override — which is required in Buildroot when building from separated archives. To solve this: We apply a patch to wrap the assignment of LLVM_COMMON_CMAKE_UTILS in an `if(NOT DEFINED ...)` block, allowing Buildroot to set the path externally. In the `llvm-cmake` package, we also **adjust the installation path** of the CMake modules: instead of installing directly into `lib/cmake/llvm`, we now install them under `lib/cmake/llvm/Modules` to match the expected layout. This ensures that: LLVM can include `${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake` without errors. -- Also the Clang build system has removed support for the GCC_INSTALL_PREFIX option, raising a fatal error when attempting to use it: CMake Error at CMakeLists.txt:211 (message): GCC_INSTALL_PREFIX is deprecated and will be removed. Use configuration files (https://clang.llvm.org/docs/UsersManual.html#configuration-files) to specify the default --gcc-install-dir= or --gcc-triple=. --gcc-toolchain= is discouraged. See llvm/llvm-project#77537 for details. Remove the use of GCC_INSTALL_PREFIX and replace it with a Clang configuration file as recommended by upstream. A configuration file is now automatically generated at: $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg It contains: --gcc-install-dir=<path to external toolchain's lib/gcc/...> --target=<GNU target triplet> We dynamically detect the GCC install path by scanning $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/<target>/<version>/ The Clang toolchain wrapper was also updated to add --config=<file> when BR_CLANG_CONFIG_FILE is defined. -- Fix LLVM_MAIN_SRC_DIR path: set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH ...) This path isn't correct when using standalone archive builds. We explicitly pass LLVM_MAIN_SRC_DIR=$(BUILD_DIR)/llvm-$(LLVM_PROJECT_VERSION) to fix the path. [2] -- Add LLVM_ENABLE_RUNTIMES: Upstream added LLVM_ENABLE_RUNTIMES for runtimes [3] -- Removed LLVM_INCLUDE_GO_TESTS: Upstream dropped this option; we remove it too [4] -- Disable TensorFlow Lite integration: LLVM_HAVE_TFLITE is added to the CMakelist We now explicitly disable it to avoid unexpected TensorFlow Lite dependency. -- Clang introduced CLANG_ENABLE_LIBXML2 [5] We now explicitly disable it by setting CLANG_ENABLE_LIBXLM2=OFF since we set LLVM_ENABLE_LIBXML2 to OFF in LLVM -- Host-python3, which is now always needed by Clang’s resource bundling script. [6] -- Clang explicitly request to disable llvm tests when llvm_gtest is missing.[7] CMake Error at CMakeLists.txt:126 (message): llvm-gtest not found. Please install llvm-gtest or disable tests with -DLLVM_INCLUDE_TESTS=OFF -- Also update the installation path in COMPILER_RT_SETUP_RUNTIME_LIBS to use CLANG_VERSION_MAJOR instead of HOST_CLANG_VERSION, ensuring that the runtime files are placed correctly in the /lib/clang/<major>/ folder. [8] -- Add llvm-runtimes dependency libunwind needs runtimes [9] -- Fix for libclc out of tree patch Due to upstream changes in libclc, the old patch no longer applies. Only the fix related to invoking './prepare_builtins' directly is still relevant and preserved, as it is required to avoid a build failure when the binary is not in PATH. -- Upstream commit [10] removed the use of llvm-config in libclc and replaced it with proper use of LLVM_CMAKE_DIR. We now pass -DLLVM_CMAKE_DIR instead of DLLVM_CONFIG -- Libclc expects to invoke some LLVM tools. We explicitly set LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR to ensure it finds these tools. [11] -- Remove LLAsm_COMPILER and CLC_COMPILER [12] -- LIBUNWIND_INSTALL_HEADERS is On by default [13] -- Update spirv-llvm-translator to align with LLVM 20.1.5 Release: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/releases/tag/v20.1.2 [1] llvm/llvm-project@9dd01a5 [2] llvm/llvm-project@d2b158e [3] llvm/llvm-project@176db3b [4] llvm/llvm-project@6ce8727 [5] llvm/llvm-project@df239a6 [6] llvm/llvm-project@96962d5 [7] llvm/llvm-project@8216910 [8] llvm/llvm-project@e1b88c8 [9] llvm/llvm-project@0af67d1 [10] llvm/llvm-project@b264787 [11] llvm/llvm-project@0aeeff3 [12] llvm/llvm-project@72f9881 [13] llvm/llvm-project@f8409af Signed-off-by: El Mehdi YOUNES <[email protected]> Signed-off-by: Bernd Kuhls <[email protected]> [Bernd: rebased, removed gcc-15 patches for llvm 15, bumped to 20.1.5] used 'git describe' to set the version number for spirv-llvm-translator] [Mehdi: changed llvm-runtimes version to $(LLVM_PROJECT_VERSION)] Signed-off-by: Julien Olivain <[email protected]>
Part of https://reviews.llvm.org/D158218
GCC_INSTALL_PREFIX is a rarely-used legacy option inherited from
pre-CMake build system and has configuration file replacement nowadays.
Many
clang/test/Driver
tests specify--gcc-toolchain=
to preventfailures when
GCC_INSTALL_PREFIX
is specified: some contributors addthem to fix tests and some just do cargo culting. This is not healthy
for contributors adding cross compilation support for this rarely used
option.
DEFAULT_SYSROOT
should in spirit be deprecated as well, but a relativepath doesn't have good replacement, so don't deprecate it for now.
Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091
Link: https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833
With
GCC_INSTALL_PREFIX=/usr
,clang a.c
behaves likeclang --gcc-toolchain=/usr a.c
.Here is a simplified version of GCC installation detection code.
--gcc-toolchain=
specifies a directory wherelib/gcc{,-cross}/$triple/$version
can be found. If you actually wantto use a specific version of GCC, specify something like
--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11
in a configurationfile. You can also specify
--gcc-triple=
.On Debian and its derivatives where the target triple omits the vendor part, the following ways are roughly equivalent, except that
--gcc-install-dir=
specifies a version as well: