Gentoo Archives: gentoo-commits

From: Yixun Lan <dlan@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: media-libs/libjxl/, media-libs/libjxl/files/
Date: Wed, 30 Mar 2022 11:23:07
Message-Id: 1648639355.ed8bf6b9c2e14a245d38526f9e70ddf0789d5e29.dlan@gentoo
1 commit: ed8bf6b9c2e14a245d38526f9e70ddf0789d5e29
2 Author: Yixun Lan <dlan <AT> gentoo <DOT> org>
3 AuthorDate: Wed Mar 30 11:07:22 2022 +0000
4 Commit: Yixun Lan <dlan <AT> gentoo <DOT> org>
5 CommitDate: Wed Mar 30 11:22:35 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ed8bf6b9
7
8 media-libs/libjxl: rework atomic issue with upstream's solution
9
10 backport patch from libjxl upstream to fix the atomic issue,
11 btw, we can safely drop this patch in next version bump.
12
13 URL: https://github.com/libjxl/libjxl/pull/1166
14 Bug: https://bugs.gentoo.org/836125
15 Package-Manager: Portage-3.0.30, Repoman-3.0.3
16 Signed-off-by: Yixun Lan <dlan <AT> gentoo.org>
17
18 media-libs/libjxl/files/libjxl-0.7.0-atomic.patch | 136 +++++++++++++++++++++
19 media-libs/libjxl/files/libjxl-0.7.0-pthread.patch | 40 ------
20 media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild | 2 +-
21 3 files changed, 137 insertions(+), 41 deletions(-)
22
23 diff --git a/media-libs/libjxl/files/libjxl-0.7.0-atomic.patch b/media-libs/libjxl/files/libjxl-0.7.0-atomic.patch
24 new file mode 100644
25 index 000000000000..44d76fcfb10f
26 --- /dev/null
27 +++ b/media-libs/libjxl/files/libjxl-0.7.0-atomic.patch
28 @@ -0,0 +1,136 @@
29 +include following patches :
30 +
31 +fde214c5f4dc5ffd0360401a68df33182edf9226 Refactor c11/atomic patch for riscv64
32 +326711f86719e6ce7b0422a7970ce8f8b1598f25 Make sure to list Threads::Threads in JPEGXL_DEC_INTERNAL_LIBS
33 +b12bb7a5f37d6bcaf134cfab7828ae08c4a0e60d Remove duplicate reference to hwy library
34 +87fe7c16e1fb2e21b6a1dca26782950ae1559d99 libjxl implementation rely on c11 atomics
35 +
36 +diff --git a/CMakeLists.txt b/CMakeLists.txt
37 +index fc1bbac..cce9748 100644
38 +--- a/CMakeLists.txt
39 ++++ b/CMakeLists.txt
40 +@@ -191,6 +191,15 @@ endif() # JPEGXL_STATIC
41 + set(THREADS_PREFER_PTHREAD_FLAG YES)
42 + find_package(Threads REQUIRED)
43 +
44 ++# These settings are important to drive check_cxx_source_compiles
45 ++# See CMP0067 (min cmake version is 3.10 anyway)
46 ++set(CMAKE_CXX_STANDARD 11)
47 ++set(CMAKE_CXX_EXTENSIONS OFF)
48 ++set(CMAKE_CXX_STANDARD_REQUIRED YES)
49 ++
50 ++# Atomics
51 ++find_package(Atomics REQUIRED)
52 ++
53 + if(JPEGXL_STATIC)
54 + if (MINGW)
55 + # In MINGW libstdc++ uses pthreads directly. When building statically a
56 +@@ -298,10 +307,6 @@ endif () # !MSVC
57 +
58 + include(GNUInstallDirs)
59 +
60 +-set(CMAKE_CXX_STANDARD 11)
61 +-set(CMAKE_CXX_EXTENSIONS OFF)
62 +-set(CMAKE_CXX_STANDARD_REQUIRED YES)
63 +-
64 + add_subdirectory(third_party)
65 +
66 + # Copy the JXL license file to the output build directory.
67 +diff --git a/cmake/FindAtomics.cmake b/cmake/FindAtomics.cmake
68 +new file mode 100644
69 +index 0000000..9a6cdc3
70 +--- /dev/null
71 ++++ b/cmake/FindAtomics.cmake
72 +@@ -0,0 +1,53 @@
73 ++# Original issue:
74 ++# * https://gitlab.kitware.com/cmake/cmake/-/issues/23021#note_1098733
75 ++#
76 ++# For reference:
77 ++# * https://gcc.gnu.org/wiki/Atomic/GCCMM
78 ++#
79 ++# riscv64 specific:
80 ++# * https://lists.debian.org/debian-riscv/2022/01/msg00009.html
81 ++#
82 ++# ATOMICS_FOUND - system has c++ atomics
83 ++# ATOMICS_LIBRARIES - libraries needed to use c++ atomics
84 ++
85 ++include(CheckCXXSourceCompiles)
86 ++
87 ++# RISC-V only has 32-bit and 64-bit atomic instructions. GCC is supposed
88 ++# to convert smaller atomics to those larger ones via masking and
89 ++# shifting like LLVM, but it’s a known bug that it does not. This means
90 ++# anything that wants to use atomics on 1-byte or 2-byte types needs
91 ++# -latomic, but not 4-byte or 8-byte (though it does no harm).
92 ++set(atomic_code
93 ++ "
94 ++ #include <atomic>
95 ++ #include <cstdint>
96 ++ std::atomic<uint8_t> n8 (0); // riscv64
97 ++ std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc
98 ++ int main() {
99 ++ ++n8;
100 ++ ++n64;
101 ++ return 0;
102 ++ }")
103 ++
104 ++check_cxx_source_compiles("${atomic_code}" ATOMICS_LOCK_FREE_INSTRUCTIONS)
105 ++
106 ++if(ATOMICS_LOCK_FREE_INSTRUCTIONS)
107 ++ set(ATOMICS_FOUND TRUE)
108 ++ set(ATOMICS_LIBRARIES)
109 ++else()
110 ++ set(CMAKE_REQUIRED_LIBRARIES "-latomic")
111 ++ check_cxx_source_compiles("${atomic_code}" ATOMICS_IN_LIBRARY)
112 ++ set(CMAKE_REQUIRED_LIBRARIES)
113 ++ if(ATOMICS_IN_LIBRARY)
114 ++ set(ATOMICS_LIBRARY atomic)
115 ++ include(FindPackageHandleStandardArgs)
116 ++ find_package_handle_standard_args(Atomics DEFAULT_MSG ATOMICS_LIBRARY)
117 ++ set(ATOMICS_LIBRARIES ${ATOMICS_LIBRARY})
118 ++ unset(ATOMICS_LIBRARY)
119 ++ else()
120 ++ if(Atomics_FIND_REQUIRED)
121 ++ message(FATAL_ERROR "Neither lock free instructions nor -latomic found.")
122 ++ endif()
123 ++ endif()
124 ++endif()
125 ++unset(atomic_code)
126 +diff --git a/lib/jxl.cmake b/lib/jxl.cmake
127 +index 97dfd73..8f69894 100644
128 +--- a/lib/jxl.cmake
129 ++++ b/lib/jxl.cmake
130 +@@ -346,6 +346,8 @@ set(JPEGXL_DEC_INTERNAL_LIBS
131 + brotlidec-static
132 + brotlicommon-static
133 + hwy
134 ++ Threads::Threads
135 ++ ${ATOMICS_LIBRARIES}
136 + )
137 +
138 + if(JPEGXL_ENABLE_PROFILER)
139 +@@ -355,7 +357,6 @@ endif()
140 + set(JPEGXL_INTERNAL_LIBS
141 + ${JPEGXL_DEC_INTERNAL_LIBS}
142 + brotlienc-static
143 +- Threads::Threads
144 + )
145 +
146 + # strips the -static suffix from all the elements in LIST
147 +@@ -467,7 +468,7 @@ add_library(jxl_dec-static STATIC
148 + $<TARGET_OBJECTS:jxl_dec-obj>
149 + )
150 + target_link_libraries(jxl_dec-static
151 +- PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_DEC_INTERNAL_LIBS} hwy)
152 ++ PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_DEC_INTERNAL_LIBS})
153 + target_include_directories(jxl_dec-static PUBLIC
154 + "${PROJECT_SOURCE_DIR}"
155 + "${CMAKE_CURRENT_SOURCE_DIR}/include"
156 +@@ -488,7 +489,7 @@ endif()
157 + # to do, remove $<TARGET_OBJECTS:jxl_dec-obj> here and depend on jxl_dec-static
158 + add_library(jxl-static STATIC ${JPEGXL_INTERNAL_OBJECTS})
159 + target_link_libraries(jxl-static
160 +- PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_INTERNAL_LIBS} hwy)
161 ++ PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_INTERNAL_LIBS})
162 + target_include_directories(jxl-static PUBLIC
163 + "${PROJECT_SOURCE_DIR}"
164 + "${CMAKE_CURRENT_SOURCE_DIR}/include"
165
166 diff --git a/media-libs/libjxl/files/libjxl-0.7.0-pthread.patch b/media-libs/libjxl/files/libjxl-0.7.0-pthread.patch
167 deleted file mode 100644
168 index ea64e5805479..000000000000
169 --- a/media-libs/libjxl/files/libjxl-0.7.0-pthread.patch
170 +++ /dev/null
171 @@ -1,40 +0,0 @@
172 -
173 -Due to there is no 1, 2byte atomic instruction in 64bit RISC-V hardware,
174 -the software layer have to emulate relavant function in atomic library
175 -
176 -Let's explicitly pass -pthread here to work around pthread builtin since glibc version 2.34
177 -as the "-pthread" option will pull in libatomic for machines like RISC-V
178 -
179 -the command of "gcc dumpspecs | grep pthread" will show accordingly in RISC-V:
180 -pthread:--push-state --as-needed -latomic --pop-state
181 -
182 -https://bugs.gentoo.org/836125
183 -https://github.com/libjxl/libjxl/issues/1283
184 -
185 -diff --git a/CMakeLists.txt b/CMakeLists.txt
186 -index 4df740b..59c7f03 100644
187 ---- a/CMakeLists.txt
188 -+++ b/CMakeLists.txt
189 -@@ -190,6 +190,9 @@ endif() # JPEGXL_STATIC
190 - # Threads
191 - set(THREADS_PREFER_PTHREAD_FLAG YES)
192 - find_package(Threads REQUIRED)
193 -+if(CMAKE_USE_PTHREADS_INIT)
194 -+ target_link_libraries(Threads::Threads INTERFACE -pthread)
195 -+endif()
196 -
197 - if(JPEGXL_STATIC)
198 - if (MINGW)
199 -diff --git a/tools/conformance/CMakeLists.txt b/tools/conformance/CMakeLists.txt
200 -index bd25b1c..d125dc5 100644
201 ---- a/tools/conformance/CMakeLists.txt
202 -+++ b/tools/conformance/CMakeLists.txt
203 -@@ -4,7 +4,7 @@
204 - # license that can be found in the LICENSE file.
205 -
206 - add_executable(djxl_conformance djxl_conformance.cc)
207 --target_link_libraries(djxl_conformance jxl_dec)
208 -+target_link_libraries(djxl_conformance jxl_dec -pthread)
209 -
210 - if(BUILD_TESTING AND CMAKE_EXECUTABLE_SUFFIX STREQUAL "")
211 - # Script to validate the tooling.
212
213 diff --git a/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild b/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild
214 index ed687e3fccc7..4ca67a00d906 100644
215 --- a/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild
216 +++ b/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild
217 @@ -30,7 +30,7 @@ DEPEND="app-arch/brotli:=[${MULTILIB_USEDEP}]
218
219 RDEPEND="${DEPEND}"
220
221 -PATCHES=( "${FILESDIR}/${PN}-0.7.0-pthread.patch" )
222 +PATCHES=( "${FILESDIR}/${PN}-0.7.0-atomic.patch" )
223
224 S="${WORKDIR}/libjxl-libjxl-3f8e77f"