From 97b3d2a6e4726e131967aa4282795fde53f9a29a Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Aug 31 2021 05:56:10 +0000 Subject: Update compiler guidelines for compiler policy change https://fedoraproject.org/wiki/Changes/CompilerPolicy --- diff --git a/guidelines/modules/ROOT/pages/index.adoc b/guidelines/modules/ROOT/pages/index.adoc index 523d951..59536a8 100644 --- a/guidelines/modules/ROOT/pages/index.adoc +++ b/guidelines/modules/ROOT/pages/index.adoc @@ -738,7 +738,34 @@ Thus it is not necessary to use `+%doc+`. [#compiler] == Compiler -Fedora uses gcc as the compiler (for all languages that gcc supports). Packages may only build with an alternative compiler to gcc if upstream does not support gcc. +Fedora packages should default to using gcc as the compiler (for all languages that gcc supports) or clang if upstream does not support building with gcc. However, if there is a good technical reason, packagers may choose not to use the default compiler. Examples of valid technical reasons to not use the default compiler, include but are not limited to: + +* The default compiler cannot build a package correctly. +* The packager needs to disable a compiler feature (e.g. LTO) in order for the default compiler to correctly compile their package. +* The default compiler takes significantly longer to build a package. +* The default compiler is missing a feature that would benefit the package. + +Packagers choosing to use a non-default compiler should document the reason for this decision in a comment in the spec file. + +== Compiler macros + +If clang is being used to build a package, packagers must set the %toolchain macro to clang: + +.... +%global toolchain clang +.... + +This ensures that Fedora's clang-specific compiler flags are used when compiling. + +If a packager wants to use conditional macros in a spec file to make it easier to switch between two different compilers, then the following macros names should be used: + +.... +%bcond_with toolchain_clang +%bcond_with toolchain_gcc +.... + +Packagers may also use the %build_cc, %build_cxx, or %build_cpp macros in the spec file in place of hard-coding the compiler name. The values of these variables are controled by setting the %toolchain macro to either clang or gcc. + == Compiler flags