In my case on rpms/simde, I want to compile the testing source in "both" gcc and clang changing the toolchain macro in the %check section.
I am seeing this file to use toolchain macro. https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/macros#_4...
# %global toolchain clang
In this case what is the best practice to use %{optflags}, %{build_cflags}, %{build_cxxflags} macros? Because after setting `%global toolchain clang` in the %check section, these macros are empty.
Here is the simde.spec having both gcc and clang built test cases in the%check section. https://src.fedoraproject.org/fork/jaruga/rpms/simde/blob/wip/clang-flto-ftb...
``` %check ... echo "=== 1.2. tests on gcc with flags ===" mkdir test/build-gcc-with-flags pushd test/build-gcc-with-flags CC=gcc CXX=g++ cmake \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="%{build_cflags}" \ -DCMAKE_CXX_FLAGS="%{build_cxxflags}" \ .. ... %global toolchain clang ... echo "=== 2.2. tests on clang with flags ===" mkdir test/build-clang-with-flags pushd test/build-clang-with-flags CC=clang CXX=clang++ cmake \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="${build_cflags}" \ # <= ${build_cflags} is empty! -DCMAKE_CXX_FLAGS="${build_cxxflags}" \ # <= ${build_cxxflags} is empty! .. ```
The scratch build: https://koji.fedoraproject.org/koji/taskinfo?taskID=48755502
Thanks.
As a reference, the following case works as expected on Fedora rawhide.
``` <mock-chroot> sh-5.0# rpm -q rpm rpm-4.16.0-0.beta3.2.fc33.3.x86_64
<mock-chroot> sh-5.0# rpm -q redhat-rpm-config redhat-rpm-config-166-1.fc33.noarch
<mock-chroot> sh-5.0# rpm --define 'toolchain gcc' --eval '%{optflags}' -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
<mock-chroot> sh-5.0# rpm --define 'toolchain clang' --eval '%{optflags}' -O2 -flto -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fcf-protection ```
On Wed, Aug 5, 2020 at 7:36 PM Jun Aruga jaruga@redhat.com wrote:
In my case on rpms/simde, I want to compile the testing source in "both" gcc and clang changing the toolchain macro in the %check section.
I am seeing this file to use toolchain macro. https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/macros#_4...
# %global toolchain clang
In this case what is the best practice to use %{optflags}, %{build_cflags}, %{build_cxxflags} macros? Because after setting `%global toolchain clang` in the %check section, these macros are empty.
Here is the simde.spec having both gcc and clang built test cases in the%check section. https://src.fedoraproject.org/fork/jaruga/rpms/simde/blob/wip/clang-flto-ftb...
%check ... echo "=== 1.2. tests on gcc with flags ===" mkdir test/build-gcc-with-flags pushd test/build-gcc-with-flags CC=gcc CXX=g++ cmake \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="%{build_cflags}" \ -DCMAKE_CXX_FLAGS="%{build_cxxflags}" \ .. ... %global toolchain clang ... echo "=== 2.2. tests on clang with flags ===" mkdir test/build-clang-with-flags pushd test/build-clang-with-flags CC=clang CXX=clang++ cmake \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="${build_cflags}" \ # <= ${build_cflags} is empty! -DCMAKE_CXX_FLAGS="${build_cxxflags}" \ # <= ${build_cxxflags} is empty! ..
I see no way this can actually work.
For one, there's typos in the second part ($ instead of %, which of course makes them empty when those environment variables aren't defined).
Also I don't think you can set RPM .spec macros *within* a %check script (which is executed by bash), so `%global toolchain clang` would get passed to bash in this case, instead of getting parsed by RPM, no? So the errors after this line are understandable to me.
I also wonder why you are trying to override `toolchain` manually in this case, which I don't think is necessary at all. Reading the docs for those macros, it looks like using %set_build_flags and setting CC and CXX correctly should do what you want to do (unless CMake doesn't read those environment variables correctly, then you need to use %build_cflags, %build_cxxflags, %build_ldflags as you did before).
Fabio
I see no way this can actually work.
For one, there's typos in the second part ($ instead of %, which of course makes them empty when those environment variables aren't defined).
Ahh, sorry for my mistakes. Thank you for finding my mistakes.
Also I don't think you can set RPM .spec macros *within* a %check script (which is executed by bash), so `%global toolchain clang` would get passed to bash in this case, instead of getting parsed by RPM, no? So the errors after this line are understandable to me.
After fixing the typos, then the lines after setting `%global toolchain clang` in %check section, it seems that the macros are used as clang values.
The scratch build: https://koji.fedoraproject.org/koji/taskinfo?taskID=48762229
``` + CC=clang + CXX=clang++ + cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON '-DCMAKE_C_FLAGS=-O2 -flto -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fcf-protection' '-DCMAKE_CXX_FLAGS=-O2 -flto -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fcf-protection' .. ```
I also wonder why you are trying to override `toolchain` manually in this case, which I don't think is necessary at all. Reading the docs for those macros, it looks like using %set_build_flags and setting CC and CXX correctly should do what you want to do (unless CMake doesn't read those environment variables correctly, then you need to use %build_cflags, %build_cxxflags, %build_ldflags as you did before).
Let me check how to use %set_build_flags with CC=clang CXX=clang++.
Thanks!
Let me check how to use %set_build_flags with CC=clang CXX=clang++.
Maybe my intent using the cmake options -DCMAKE_C_FLAGS -DCMAKE_CXX_FLAGS was I wanted to align with the usage in the upstream [1]. I have a resistance to use %set_build_flags in this case, as it has the exported environment variables [2] with the wider scope in %check where I want to run 4 test cases changing the environment variables for each test case.
Though I still do not know how to use %set_build_flags for clang, I can go ahead with the current spec file.
[1] https://github.com/simd-everywhere/simde/blob/0f4bc1a2e0ee28e8eeea9a5c5de9c4... [2] https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/macros#_9...
On Wed, Aug 5, 2020 at 9:36 PM Jun Aruga jaruga@redhat.com wrote:
Let me check how to use %set_build_flags with CC=clang CXX=clang++.
Maybe my intent using the cmake options -DCMAKE_C_FLAGS -DCMAKE_CXX_FLAGS was I wanted to align with the usage in the upstream [1]. I have a resistance to use %set_build_flags in this case, as it has the exported environment variables [2] with the wider scope in %check where I want to run 4 test cases changing the environment variables for each test case.
If you want to make things more complicated, you can always use subshells :)
Though I still do not know how to use %set_build_flags for clang, I can go ahead with the current spec file.
[1] https://github.com/simd-everywhere/simde/blob/0f4bc1a2e0ee28e8eeea9a5c5de9c4... [2] https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/macros#_9...
-- Jun | He - His - Him _______________________________________________ packaging mailing list -- packaging@lists.fedoraproject.org To unsubscribe send an email to packaging-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject....
packaging@lists.fedoraproject.org