From: "Yixun Lan" <dlan@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: media-libs/libjxl/, media-libs/libjxl/files/
Date: Wed, 30 Mar 2022 11:22:59 +0000 (UTC) [thread overview]
Message-ID: <1648639355.ed8bf6b9c2e14a245d38526f9e70ddf0789d5e29.dlan@gentoo> (raw)
commit: ed8bf6b9c2e14a245d38526f9e70ddf0789d5e29
Author: Yixun Lan <dlan <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 30 11:07:22 2022 +0000
Commit: Yixun Lan <dlan <AT> gentoo <DOT> org>
CommitDate: Wed Mar 30 11:22:35 2022 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ed8bf6b9
media-libs/libjxl: rework atomic issue with upstream's solution
backport patch from libjxl upstream to fix the atomic issue,
btw, we can safely drop this patch in next version bump.
URL: https://github.com/libjxl/libjxl/pull/1166
Bug: https://bugs.gentoo.org/836125
Package-Manager: Portage-3.0.30, Repoman-3.0.3
Signed-off-by: Yixun Lan <dlan <AT> gentoo.org>
media-libs/libjxl/files/libjxl-0.7.0-atomic.patch | 136 +++++++++++++++++++++
media-libs/libjxl/files/libjxl-0.7.0-pthread.patch | 40 ------
media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild | 2 +-
3 files changed, 137 insertions(+), 41 deletions(-)
diff --git a/media-libs/libjxl/files/libjxl-0.7.0-atomic.patch b/media-libs/libjxl/files/libjxl-0.7.0-atomic.patch
new file mode 100644
index 000000000000..44d76fcfb10f
--- /dev/null
+++ b/media-libs/libjxl/files/libjxl-0.7.0-atomic.patch
@@ -0,0 +1,136 @@
+include following patches :
+
+fde214c5f4dc5ffd0360401a68df33182edf9226 Refactor c11/atomic patch for riscv64
+326711f86719e6ce7b0422a7970ce8f8b1598f25 Make sure to list Threads::Threads in JPEGXL_DEC_INTERNAL_LIBS
+b12bb7a5f37d6bcaf134cfab7828ae08c4a0e60d Remove duplicate reference to hwy library
+87fe7c16e1fb2e21b6a1dca26782950ae1559d99 libjxl implementation rely on c11 atomics
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index fc1bbac..cce9748 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -191,6 +191,15 @@ endif() # JPEGXL_STATIC
+ set(THREADS_PREFER_PTHREAD_FLAG YES)
+ find_package(Threads REQUIRED)
+
++# These settings are important to drive check_cxx_source_compiles
++# See CMP0067 (min cmake version is 3.10 anyway)
++set(CMAKE_CXX_STANDARD 11)
++set(CMAKE_CXX_EXTENSIONS OFF)
++set(CMAKE_CXX_STANDARD_REQUIRED YES)
++
++# Atomics
++find_package(Atomics REQUIRED)
++
+ if(JPEGXL_STATIC)
+ if (MINGW)
+ # In MINGW libstdc++ uses pthreads directly. When building statically a
+@@ -298,10 +307,6 @@ endif () # !MSVC
+
+ include(GNUInstallDirs)
+
+-set(CMAKE_CXX_STANDARD 11)
+-set(CMAKE_CXX_EXTENSIONS OFF)
+-set(CMAKE_CXX_STANDARD_REQUIRED YES)
+-
+ add_subdirectory(third_party)
+
+ # Copy the JXL license file to the output build directory.
+diff --git a/cmake/FindAtomics.cmake b/cmake/FindAtomics.cmake
+new file mode 100644
+index 0000000..9a6cdc3
+--- /dev/null
++++ b/cmake/FindAtomics.cmake
+@@ -0,0 +1,53 @@
++# Original issue:
++# * https://gitlab.kitware.com/cmake/cmake/-/issues/23021#note_1098733
++#
++# For reference:
++# * https://gcc.gnu.org/wiki/Atomic/GCCMM
++#
++# riscv64 specific:
++# * https://lists.debian.org/debian-riscv/2022/01/msg00009.html
++#
++# ATOMICS_FOUND - system has c++ atomics
++# ATOMICS_LIBRARIES - libraries needed to use c++ atomics
++
++include(CheckCXXSourceCompiles)
++
++# RISC-V only has 32-bit and 64-bit atomic instructions. GCC is supposed
++# to convert smaller atomics to those larger ones via masking and
++# shifting like LLVM, but it’s a known bug that it does not. This means
++# anything that wants to use atomics on 1-byte or 2-byte types needs
++# -latomic, but not 4-byte or 8-byte (though it does no harm).
++set(atomic_code
++ "
++ #include <atomic>
++ #include <cstdint>
++ std::atomic<uint8_t> n8 (0); // riscv64
++ std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc
++ int main() {
++ ++n8;
++ ++n64;
++ return 0;
++ }")
++
++check_cxx_source_compiles("${atomic_code}" ATOMICS_LOCK_FREE_INSTRUCTIONS)
++
++if(ATOMICS_LOCK_FREE_INSTRUCTIONS)
++ set(ATOMICS_FOUND TRUE)
++ set(ATOMICS_LIBRARIES)
++else()
++ set(CMAKE_REQUIRED_LIBRARIES "-latomic")
++ check_cxx_source_compiles("${atomic_code}" ATOMICS_IN_LIBRARY)
++ set(CMAKE_REQUIRED_LIBRARIES)
++ if(ATOMICS_IN_LIBRARY)
++ set(ATOMICS_LIBRARY atomic)
++ include(FindPackageHandleStandardArgs)
++ find_package_handle_standard_args(Atomics DEFAULT_MSG ATOMICS_LIBRARY)
++ set(ATOMICS_LIBRARIES ${ATOMICS_LIBRARY})
++ unset(ATOMICS_LIBRARY)
++ else()
++ if(Atomics_FIND_REQUIRED)
++ message(FATAL_ERROR "Neither lock free instructions nor -latomic found.")
++ endif()
++ endif()
++endif()
++unset(atomic_code)
+diff --git a/lib/jxl.cmake b/lib/jxl.cmake
+index 97dfd73..8f69894 100644
+--- a/lib/jxl.cmake
++++ b/lib/jxl.cmake
+@@ -346,6 +346,8 @@ set(JPEGXL_DEC_INTERNAL_LIBS
+ brotlidec-static
+ brotlicommon-static
+ hwy
++ Threads::Threads
++ ${ATOMICS_LIBRARIES}
+ )
+
+ if(JPEGXL_ENABLE_PROFILER)
+@@ -355,7 +357,6 @@ endif()
+ set(JPEGXL_INTERNAL_LIBS
+ ${JPEGXL_DEC_INTERNAL_LIBS}
+ brotlienc-static
+- Threads::Threads
+ )
+
+ # strips the -static suffix from all the elements in LIST
+@@ -467,7 +468,7 @@ add_library(jxl_dec-static STATIC
+ $<TARGET_OBJECTS:jxl_dec-obj>
+ )
+ target_link_libraries(jxl_dec-static
+- PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_DEC_INTERNAL_LIBS} hwy)
++ PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_DEC_INTERNAL_LIBS})
+ target_include_directories(jxl_dec-static PUBLIC
+ "${PROJECT_SOURCE_DIR}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
+@@ -488,7 +489,7 @@ endif()
+ # to do, remove $<TARGET_OBJECTS:jxl_dec-obj> here and depend on jxl_dec-static
+ add_library(jxl-static STATIC ${JPEGXL_INTERNAL_OBJECTS})
+ target_link_libraries(jxl-static
+- PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_INTERNAL_LIBS} hwy)
++ PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_INTERNAL_LIBS})
+ target_include_directories(jxl-static PUBLIC
+ "${PROJECT_SOURCE_DIR}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/include"
diff --git a/media-libs/libjxl/files/libjxl-0.7.0-pthread.patch b/media-libs/libjxl/files/libjxl-0.7.0-pthread.patch
deleted file mode 100644
index ea64e5805479..000000000000
--- a/media-libs/libjxl/files/libjxl-0.7.0-pthread.patch
+++ /dev/null
@@ -1,40 +0,0 @@
-
-Due to there is no 1, 2byte atomic instruction in 64bit RISC-V hardware,
-the software layer have to emulate relavant function in atomic library
-
-Let's explicitly pass -pthread here to work around pthread builtin since glibc version 2.34
-as the "-pthread" option will pull in libatomic for machines like RISC-V
-
-the command of "gcc dumpspecs | grep pthread" will show accordingly in RISC-V:
-pthread:--push-state --as-needed -latomic --pop-state
-
-https://bugs.gentoo.org/836125
-https://github.com/libjxl/libjxl/issues/1283
-
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 4df740b..59c7f03 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -190,6 +190,9 @@ endif() # JPEGXL_STATIC
- # Threads
- set(THREADS_PREFER_PTHREAD_FLAG YES)
- find_package(Threads REQUIRED)
-+if(CMAKE_USE_PTHREADS_INIT)
-+ target_link_libraries(Threads::Threads INTERFACE -pthread)
-+endif()
-
- if(JPEGXL_STATIC)
- if (MINGW)
-diff --git a/tools/conformance/CMakeLists.txt b/tools/conformance/CMakeLists.txt
-index bd25b1c..d125dc5 100644
---- a/tools/conformance/CMakeLists.txt
-+++ b/tools/conformance/CMakeLists.txt
-@@ -4,7 +4,7 @@
- # license that can be found in the LICENSE file.
-
- add_executable(djxl_conformance djxl_conformance.cc)
--target_link_libraries(djxl_conformance jxl_dec)
-+target_link_libraries(djxl_conformance jxl_dec -pthread)
-
- if(BUILD_TESTING AND CMAKE_EXECUTABLE_SUFFIX STREQUAL "")
- # Script to validate the tooling.
diff --git a/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild b/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild
index ed687e3fccc7..4ca67a00d906 100644
--- a/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild
+++ b/media-libs/libjxl/libjxl-0.7.0_pre20220311.ebuild
@@ -30,7 +30,7 @@ DEPEND="app-arch/brotli:=[${MULTILIB_USEDEP}]
RDEPEND="${DEPEND}"
-PATCHES=( "${FILESDIR}/${PN}-0.7.0-pthread.patch" )
+PATCHES=( "${FILESDIR}/${PN}-0.7.0-atomic.patch" )
S="${WORKDIR}/libjxl-libjxl-3f8e77f"
next reply other threads:[~2022-03-30 11:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 11:22 Yixun Lan [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-07-09 4:47 [gentoo-commits] repo/gentoo:master commit in: media-libs/libjxl/, media-libs/libjxl/files/ Sam James
2024-01-19 13:34 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1648639355.ed8bf6b9c2e14a245d38526f9e70ddf0789d5e29.dlan@gentoo \
--to=dlan@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox