]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Add support for using system blake3 1429/head
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 30 Mar 2024 19:45:30 +0000 (20:45 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Apr 2024 08:14:30 +0000 (10:14 +0200)
30 files changed:
.clang-format
LICENSE.adoc
cmake/Dependencies.cmake
cmake/FindBlake3.cmake [new file with mode: 0644]
doc/INSTALL.md
src/ccache/Hash.hpp
src/third_party/CMakeLists.txt
src/third_party/blake3/CMakeLists.txt
src/third_party/blake3/blake3/blake3.c [moved from src/third_party/blake3/blake3.c with 100% similarity]
src/third_party/blake3/blake3/blake3.h [moved from src/third_party/blake3/blake3.h with 100% similarity]
src/third_party/blake3/blake3/blake3_avx2.c [moved from src/third_party/blake3/blake3_avx2.c with 100% similarity]
src/third_party/blake3/blake3/blake3_avx2_x86-64_unix.S [moved from src/third_party/blake3/blake3_avx2_x86-64_unix.S with 100% similarity]
src/third_party/blake3/blake3/blake3_avx2_x86-64_windows_gnu.S [moved from src/third_party/blake3/blake3_avx2_x86-64_windows_gnu.S with 100% similarity]
src/third_party/blake3/blake3/blake3_avx2_x86-64_windows_msvc.asm [moved from src/third_party/blake3/blake3_avx2_x86-64_windows_msvc.asm with 100% similarity]
src/third_party/blake3/blake3/blake3_avx512.c [moved from src/third_party/blake3/blake3_avx512.c with 100% similarity]
src/third_party/blake3/blake3/blake3_avx512_x86-64_unix.S [moved from src/third_party/blake3/blake3_avx512_x86-64_unix.S with 100% similarity]
src/third_party/blake3/blake3/blake3_avx512_x86-64_windows_gnu.S [moved from src/third_party/blake3/blake3_avx512_x86-64_windows_gnu.S with 100% similarity]
src/third_party/blake3/blake3/blake3_avx512_x86-64_windows_msvc.asm [moved from src/third_party/blake3/blake3_avx512_x86-64_windows_msvc.asm with 100% similarity]
src/third_party/blake3/blake3/blake3_dispatch.c [moved from src/third_party/blake3/blake3_dispatch.c with 100% similarity]
src/third_party/blake3/blake3/blake3_impl.h [moved from src/third_party/blake3/blake3_impl.h with 100% similarity]
src/third_party/blake3/blake3/blake3_neon.c [moved from src/third_party/blake3/blake3_neon.c with 100% similarity]
src/third_party/blake3/blake3/blake3_portable.c [moved from src/third_party/blake3/blake3_portable.c with 100% similarity]
src/third_party/blake3/blake3/blake3_sse2.c [moved from src/third_party/blake3/blake3_sse2.c with 100% similarity]
src/third_party/blake3/blake3/blake3_sse2_x86-64_unix.S [moved from src/third_party/blake3/blake3_sse2_x86-64_unix.S with 100% similarity]
src/third_party/blake3/blake3/blake3_sse2_x86-64_windows_gnu.S [moved from src/third_party/blake3/blake3_sse2_x86-64_windows_gnu.S with 100% similarity]
src/third_party/blake3/blake3/blake3_sse2_x86-64_windows_msvc.asm [moved from src/third_party/blake3/blake3_sse2_x86-64_windows_msvc.asm with 100% similarity]
src/third_party/blake3/blake3/blake3_sse41.c [moved from src/third_party/blake3/blake3_sse41.c with 100% similarity]
src/third_party/blake3/blake3/blake3_sse41_x86-64_unix.S [moved from src/third_party/blake3/blake3_sse41_x86-64_unix.S with 100% similarity]
src/third_party/blake3/blake3/blake3_sse41_x86-64_windows_gnu.S [moved from src/third_party/blake3/blake3_sse41_x86-64_windows_gnu.S with 100% similarity]
src/third_party/blake3/blake3/blake3_sse41_x86-64_windows_msvc.asm [moved from src/third_party/blake3/blake3_sse41_x86-64_windows_msvc.asm with 100% similarity]

index db62f47a3b65ba8db26eef783186e30e46b55d49..92da3a9d8ff7e49f986730d0660f49343d3a187c 100644 (file)
@@ -31,7 +31,7 @@ IncludeCategories:
   - Regex: '^<ccache/'
     Priority: 2
   # Dependency headers:
-  - Regex: '^<(blake3\.h|cxxurl/url\.hpp|doctest/.*|fmt/.*|hiredis/.*|httplib\.h|nonstd/.*|tl/expected\.hpp|xx(hash|h_x86dispatch)\.h|zstd\.h)>$'
+  - Regex: '^<(blake3/blake3\.h|cxxurl/url\.hpp|doctest/.*|fmt/.*|hiredis/.*|httplib\.h|nonstd/.*|tl/expected\.hpp|xx(hash|h_x86dispatch)\.h|zstd\.h)>$'
     Priority: 3
   # System headers:
   - Regex: '\.h.*>$'
index 543a3a1086ea3a1a7f6498b9e231e94ec6c06bd4..2f20e08bab3aa46c84c86fcea30fa63df4a4be0a 100644 (file)
@@ -48,7 +48,7 @@ the GPL: that is, if separated from the ccache sources, they may be usable
 under less restrictive terms.
 
 
-=== src/third_party/blake3/blake3_*
+=== src/third_party/blake3/blake3/*
 
 This is a subset of https://github.com/BLAKE3-team/BLAKE3[BLAKE3] 1.5.1 with the
 following license:
index 2cb1756022f3a97a788dae55a56ada961bf21621..f162b2dd58b0550066f159b372849feb47c7e93d 100644 (file)
@@ -19,6 +19,7 @@ endif()
 set(DEPS AUTO CACHE STRING "How to retrieve third party dependencies")
 set_property(CACHE DEPS PROPERTY STRINGS AUTO DOWNLOAD LOCAL)
 
+find_package(Blake3 1.4.0 MODULE REQUIRED)
 find_package(CppHttplib 0.10.6 MODULE REQUIRED)
 find_package(Fmt 8.0.0 MODULE REQUIRED)
 find_package(NonstdSpan 0.10.3 MODULE REQUIRED)
diff --git a/cmake/FindBlake3.cmake b/cmake/FindBlake3.cmake
new file mode 100644 (file)
index 0000000..501353c
--- /dev/null
@@ -0,0 +1,30 @@
+mark_as_advanced(BLAKE3_INCLUDE_DIR)
+mark_as_advanced(BLAKE3_LIBRARY)
+
+if(DEP_BLAKE3 STREQUAL "BUNDLED")
+  message(STATUS "Using bundled Blake3 as requested")
+else()
+  find_path(BLAKE3_INCLUDE_DIR blake3.h)
+  find_library(BLAKE3_LIBRARY blake3)
+  if(BLAKE3_INCLUDE_DIR)
+    file(READ "${BLAKE3_INCLUDE_DIR}/blake3.h" _blake3_h)
+    string(REGEX MATCH "#define _blake3_version_string \"([0-9]+).([0-9]+).*([0-9]+)\"" _ "${_blake3_h}")
+    set(_blake3_version_string "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
+    if(NOT "${CMAKE_MATCH_0}" STREQUAL "" AND "${_blake3_version_string}" VERSION_GREATER_EQUAL "${Blake3_FIND_VERSION}")
+      if(BLAKE3_LIBRARY)
+        message(STATUS "Using system Blake3 (${BLAKE3_LIBRARY})")
+        add_library(dep_blake3 UNKNOWN IMPORTED)
+        set_target_properties(
+          dep_blake3
+          PROPERTIES
+          INTERFACE_INCLUDE_DIRECTORIES "${BLAKE3_INCLUDE_DIR}"
+          IMPORTED_LOCATION "${BLAKE3_LIBRARY}"
+        )
+      endif()
+      register_dependency(Blake3 "SYSTEM (${BLAKE3_LIBRARY})" "${_blake3_version_string}")
+    endif()
+  endif()
+  if(NOT TARGET dep_blake3)
+    message(STATUS "Using bundled Blake3 since Blake3>=${Blake3_FIND_VERSION} was not found locally")
+  endif()
+endif()
index 7e24680cbde1aebcaf95e327b7bd27f05d2e7d3d..56e0d6b072d66c144aad9c2a7bcd2ad25c8a7687 100644 (file)
@@ -39,6 +39,7 @@ should be located or retrieved:
 
 ### Dependencies
 
+- [BLAKE3](https://github.com/BLAKE3-team/BLAKE3)[^1]
 - [cpp-httplib](https://github.com/yhirose/cpp-httplib)[^1]
 - [doctest](https://github.com/doctest/doctest)[^2] (optional, disable with `-D
   ENABLE_TESTING=OFF`)
index 990b77bce4bb762838490632ce6b0e5bb892c432..df95b66c2014dbaa525cda90a882fbac37e5aa55 100644 (file)
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include <blake3.h>
+#include <blake3/blake3.h>
 #include <nonstd/span.hpp>
 #include <tl/expected.hpp>
 
index fb614ca807ec619f900aae1d34a2cc50a9cdb293..cda49305e484aa32f1e6f820c44a63bd321778f9 100644 (file)
@@ -1,7 +1,9 @@
-add_subdirectory(blake3)
 add_subdirectory(cxxurl)
 add_subdirectory(win32-compat)
 
+if(NOT TARGET dep_blake3)
+  add_subdirectory(blake3)
+endif()
 if(NOT TARGET dep_cpphttplib)
   add_subdirectory(cpp-httplib)
 endif()
index 7ab255f2111f374cff5815ce9f67c40b96a0911a..8d0e9620cd3a56e570c1efe0d818d5be39cb0a01 100644 (file)
@@ -1,17 +1,25 @@
-add_library(dep_blake3 STATIC blake3.c blake3_dispatch.c blake3_portable.c)
+register_dependency(Blake3 BUNDLED 1.5.1)
 
-target_include_directories(dep_blake3 INTERFACE "${CMAKE_SOURCE_DIR}/src/third_party/blake3")
+add_library(
+  dep_blake3 STATIC
+  "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3.c"
+  "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_dispatch.c"
+  "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_portable.c"
+)
+
+target_include_directories(dep_blake3 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
 target_link_libraries(dep_blake3 PRIVATE standard_settings)
 
 if(MSVC)
-  # No object file is created if masm is passed the compile options from standard_settings,
-  # so don't pass any flags at all to assembler (as no flags are needed anyway).
+  # No object file is created if masm is passed the compile options from
+  # standard_settings, so don't pass any flags at all to assembler (as no
+  # flags are needed anyway).
   string(REPLACE "<FLAGS> " "" CMAKE_ASM_MASM_COMPILE_OBJECT "${CMAKE_ASM_MASM_COMPILE_OBJECT}")
 endif()
 
 include(CheckCSourceCompiles)
 
-function(add_source_if_enabled feature msvc_flags others_flags intrinsic)
+function(_add_blake3_source_if_enabled feature msvc_flags others_flags intrinsic)
   if(MSVC)
     set(compile_flags "${msvc_flags}")
   else()
@@ -29,8 +37,8 @@ function(add_source_if_enabled feature msvc_flags others_flags intrinsic)
   # First check if it's possible to use the assembler variant for the feature.
   string(TOUPPER "have_asm_${feature}" have_feature)
   if(NOT DEFINED "${have_feature}" AND CMAKE_SIZEOF_VOID_P EQUAL 8
-# Force intrinsic version for msbuild because of a bug in the cmake generator
-# or msbuild itself with masm flags.
+      # Force intrinsic version for msbuild because of a bug in the CMake
+      # generator or msbuild itself with masm flags.
       AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
 
     if(NOT CMAKE_REQUIRED_QUIET)
@@ -39,14 +47,16 @@ function(add_source_if_enabled feature msvc_flags others_flags intrinsic)
 
     set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 
-    # Must set CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY explicitly otherwise try_compile
-    # fails, see https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959
+    # Must set CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY explicitly otherwise
+    # try_compile fails, see
+    # <https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959>.
     try_compile(
       ${have_feature}
       ${CMAKE_CURRENT_BINARY_DIR}
-      "${CMAKE_CURRENT_SOURCE_DIR}/blake3_${feature}${suffix}"
+      "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
       CMAKE_FLAGS -DCMAKE_ASM_MASM_CREATE_STATIC_LIBRARY=${CMAKE_C_CREATE_STATIC_LIBRARY}
-      COMPILE_DEFINITIONS ${compile_flags})
+      COMPILE_DEFINITIONS ${compile_flags}
+    )
 
     unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
 
@@ -59,7 +69,7 @@ function(add_source_if_enabled feature msvc_flags others_flags intrinsic)
     endif()
   endif()
 
-  # If the assembler variant didn't work, try the c variant.
+  # If the assembler variant didn't work, try the C variant.
   if(NOT ${have_feature})
     string(TOUPPER "have_c_${feature}" have_feature)
     set(suffix ".c")
@@ -75,36 +85,35 @@ function(add_source_if_enabled feature msvc_flags others_flags intrinsic)
   endif()
 
   if(${have_feature})
-    target_sources(dep_blake3 PRIVATE blake3_${feature}${suffix})
+    target_sources(
+      dep_blake3
+      PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
+    )
     if(suffix STREQUAL ".c")
       if(MINGW AND feature STREQUAL "avx512")
-        # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782.
+        # Workaround for <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782>.
         # Taken from blake3's build.rs.
         set(compile_flags "${compile_flags} -fno-asynchronous-unwind-tables")
       endif()
       set_property(
-        SOURCE blake3_${feature}${suffix}
+        SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
         APPEND PROPERTY COMPILE_FLAGS ${compile_flags})
     elseif(NOT MSVC)
       set_property(
-        SOURCE blake3_${feature}${suffix}
+        SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
         PROPERTY COMPILE_FLAGS ${compile_flags})
     endif()
   else()
     string(TOUPPER "blake3_no_${feature}" no_feature)
-    target_compile_definitions(blake3 PRIVATE ${no_feature})
+    target_compile_definitions(dep_blake3 PRIVATE ${no_feature})
   endif()
 endfunction()
 
 # https://software.intel.com/sites/landingpage/IntrinsicsGuide/
-add_source_if_enabled(sse2 "" "-msse2"
-  "_mm_set1_epi32(42)")
-add_source_if_enabled(sse41 "" "-msse4.1"
-  "_mm_test_all_ones(_mm_set1_epi32(42))")
-add_source_if_enabled(avx2 "/arch:AVX2" "-mavx2"
-  "_mm256_abs_epi8(_mm256_set1_epi32(42))")
-add_source_if_enabled(avx512 "/arch:AVX512" "-mavx512f -mavx512vl"
-  "_mm256_abs_epi64(_mm256_set1_epi32(42))")
+_add_blake3_source_if_enabled(sse2 "" "-msse2" "_mm_set1_epi32(42)")
+_add_blake3_source_if_enabled(sse41 "" "-msse4.1" "_mm_test_all_ones(_mm_set1_epi32(42))")
+_add_blake3_source_if_enabled(avx2 "/arch:AVX2" "-mavx2" "_mm256_abs_epi8(_mm256_set1_epi32(42))")
+_add_blake3_source_if_enabled(avx512 "/arch:AVX512" "-mavx512f -mavx512vl" "_mm256_abs_epi64(_mm256_set1_epi32(42))")
 
 # Neon is always available on AArch64
 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -116,8 +125,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
     ]=]
     HAVE_NEON)
   if(HAVE_NEON)
-    target_sources(blake3 PRIVATE blake3_neon.c)
-    target_compile_definitions(blake3 PRIVATE BLAKE3_USE_NEON)
+    target_sources(dep_blake3 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_neon.c")
+    target_compile_definitions(dep_blake3 PRIVATE BLAKE3_USE_NEON)
   endif()
 endif()