From b6e0bf8b76b572bcf3860424974426d1525467c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michel=20D=C3=A4nzer?= Date: Fri, 10 Feb 2023 16:19:36 +0100 Subject: [PATCH] ci: Pass -Werror to compiler linking stage for LTO With LTO, some compiler warnings are generated only at the compiler's linking stage. Therefore -Werror needs to be passed to the linking stage as well for warnings to be turned into errors. Meson should really do this when both werror and b_lto are enabled, but meanwhile let's do it ourselves. We can't just add -Werror to c{,pp}_link_args, because those are passed for Meson's feature checks, some of which generate warnings, resulting in false negatives. We use gcc/g++ wrapper scripts instead. Part-of: --- .gitlab-ci/build/ccache-g++-link-werror.sh | 15 +++++++++++++++ .gitlab-ci/build/ccache-gcc-link-werror.sh | 15 +++++++++++++++ .gitlab-ci/build/gitlab-ci.yml | 3 ++- .gitlab-ci/build/meson-native-lto-wrappers.txt | 3 +++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 .gitlab-ci/build/ccache-g++-link-werror.sh create mode 100755 .gitlab-ci/build/ccache-gcc-link-werror.sh create mode 100644 .gitlab-ci/build/meson-native-lto-wrappers.txt diff --git a/.gitlab-ci/build/ccache-g++-link-werror.sh b/.gitlab-ci/build/ccache-g++-link-werror.sh new file mode 100755 index 0000000..1264dec --- /dev/null +++ b/.gitlab-ci/build/ccache-g++-link-werror.sh @@ -0,0 +1,15 @@ +#!/bin/sh -e + +if [ "$(ps -p $(ps -p $PPID -o ppid --no-headers) -o comm --no-headers)" != ninja ]; then + # Not invoked by ninja (e.g. for a meson feature check) + exec ccache g++ "$@" +fi + +if [ "$(eval printf "'%s'" "\"\${$(($#-1))}\"")" = "-c" ]; then + # Not invoked for linking + exec ccache g++ "$@" +fi + +# Compiler invoked by ninja for linking. Add -Werror to turn compiler warnings into errors +# with LTO. (meson's werror should arguably do this, but meanwhile we need to) +exec ccache g++ "$@" -Werror diff --git a/.gitlab-ci/build/ccache-gcc-link-werror.sh b/.gitlab-ci/build/ccache-gcc-link-werror.sh new file mode 100755 index 0000000..136f0e7 --- /dev/null +++ b/.gitlab-ci/build/ccache-gcc-link-werror.sh @@ -0,0 +1,15 @@ +#!/bin/sh -e + +if [ "$(ps -p $(ps -p $PPID -o ppid --no-headers) -o comm --no-headers)" != ninja ]; then + # Not invoked by ninja (e.g. for a meson feature check) + exec ccache gcc "$@" +fi + +if [ "$(eval printf "'%s'" "\"\${$(($#-1))}\"")" = "-c" ]; then + # Not invoked for linking + exec ccache gcc "$@" +fi + +# Compiler invoked by ninja for linking. Add -Werror to turn compiler warnings into errors +# with LTO. (meson's werror should arguably do this, but meanwhile we need to) +exec ccache gcc "$@" -Werror diff --git a/.gitlab-ci/build/gitlab-ci.yml b/.gitlab-ci/build/gitlab-ci.yml index 5af7d53..fd799eb 100644 --- a/.gitlab-ci/build/gitlab-ci.yml +++ b/.gitlab-ci/build/gitlab-ci.yml @@ -182,6 +182,7 @@ debian-build-testing: GALLIUM_DRIVERS: "iris,nouveau,kmsro,r300,r600,freedreno,swrast,svga,v3d,vc4,virgl,etnaviv,panfrost,lima,zink,d3d12,asahi,crocus" VULKAN_DRIVERS: swrast EXTRA_OPTION: > + --native-file .gitlab-ci/build/meson-native-lto-wrappers.txt -D spirv-to-dxil=true -D osmesa=true -D tools=drm-shim,etnaviv,freedreno,glsl,intel,intel-ui,nir,nouveau,lima,panfrost,asahi @@ -195,7 +196,7 @@ debian-build-testing: section_switch yamllint "yamllint" .gitlab-ci/run-yamllint.sh section_switch meson "meson" - .gitlab-ci/meson/build.sh + PATH=$PATH:$PWD/.gitlab-ci/build .gitlab-ci/meson/build.sh section_switch shader-db "shader-db" .gitlab-ci/run-shader-db.sh diff --git a/.gitlab-ci/build/meson-native-lto-wrappers.txt b/.gitlab-ci/build/meson-native-lto-wrappers.txt new file mode 100644 index 0000000..e17f64f --- /dev/null +++ b/.gitlab-ci/build/meson-native-lto-wrappers.txt @@ -0,0 +1,3 @@ +[binaries] +c = 'ccache-gcc-link-werror.sh' +cpp = 'ccache-g++-link-werror.sh' -- 2.7.4