mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 14:17:52 -05:00
vcpkg: Patch snappy for AVX-by-default toolchains via overlay port
snappy 1.2.2, a transitive dependency of arrow, includes <immintrin.h> only when SNAPPY_HAVE_BMI2 or SNAPPY_HAVE_X86_CRC32 is set, but MemCopy64() selects an AVX code path on a separate condition, `defined(__x86_64__) && defined(__AVX__)`. The vcpkg port passes -DSNAPPY_HAVE_BMI2=OFF and -DSNAPPY_HAVE_X86_CRC32=OFF to keep the binaries portable, so on a toolchain whose default target enables AVX that branch is compiled with no intrinsics header and snappy.cc fails with "'__m256i' was not declared in this scope". This broke the clang-tidy and clazy-report workflows the first night after they moved to ubuntu-26.04. The runner switch also changed the vcpkg compiler hash, so the binary cache went from "Restored 103 package(s)" to "Restored 0 package(s)" and every port was rebuilt from source, which is what exposed snappy in the first place. The bug is not GCC 15 specific: microsoft/vcpkg#51047 reports it against GCC 14.3.1. It is still present in snappy 1.3.1 and main, and vcpkg master still ships 1.2.2 with the SNAPPY_HAVE_* options off, so neither a baseline bump nor a port update fixes it. Vendor the port under ThirdParty/vcpkg-overlay-ports and add avx-immintrin.patch, which includes <immintrin.h> for the __AVX__ branch as well. The patch cannot change the ISA baseline of the result: it only supplies a header on a path the compiler was already going to take. Verified by reproducing the failure locally with an overlay triplet setting -march=x86-64-v3, confirming the patched port builds both with and without that flag, and checking that objdump finds no AVX instructions in the library built with the stock toolchain. Reference the two overlay ports by their individual directories rather than by the parent directory. The two configurations resolve different versions of both ports (default: snappy 1.2.2#1, thrift 0.22.0; rhel8: snappy 1.2.1, thrift 0.20.0#1), so an overlay of the whole directory would downgrade thrift for the default builds and bump snappy for RHEL8. Dry runs of both manifests confirm each profile now picks up only its own overlay. The bumped port-version misses the existing vcpkg binary caches, but those caches are already cold for the ubuntu-26.04 workflows.
This commit is contained in:
1 parent
b1f093fa7d
commit
f6787a9ea1
11 files changed
+198
-1
No files matched your search
@@ -0,0 +1,16 @@
|
||||
diff --git a/snappy.cc b/snappy.cc
|
||||
index 8dc3713..81c56d6 100644
|
||||
--- a/snappy.cc
|
||||
+++ b/snappy.cc
|
||||
@@ -64,6 +64,11 @@
|
||||
// Please do not replace with <x86intrin.h>. or with headers that assume more
|
||||
// advanced SSE versions without checking with all the OWNERS.
|
||||
#include <immintrin.h>
|
||||
+#elif defined(__x86_64__) && defined(__AVX__)
|
||||
+// MemCopy64() below uses AVX intrinsics guarded only by __AVX__, which is
|
||||
+// independent of the SNAPPY_HAVE_* macros above. When the compiler targets
|
||||
+// AVX by default, that branch is compiled without any intrinsics header.
|
||||
+#include <immintrin.h>
|
||||
#elif SNAPPY_HAVE_NEON_CRC32
|
||||
#include <arm_acle.h>
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
# Use -Werror for clang only.
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
- if(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")
|
||||
+ if(0)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")
|
||||
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
@@ -0,0 +1,23 @@
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index c3062e2..05477e9 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -417,4 +417,18 @@ if(SNAPPY_INSTALL)
|
||||
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||
)
|
||||
+
|
||||
+ cmake_policy(SET CMP0057 NEW)
|
||||
+ set(LIBS_PRIVATE "")
|
||||
+ foreach(lib IN LISTS CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
|
||||
+ if(lib IN_LIST CMAKE_C_IMPLICIT_LINK_LIBRARIES)
|
||||
+ continue()
|
||||
+ elseif(EXISTS "${lib}")
|
||||
+ string(APPEND LIBS_PRIVATE " ${lib}")
|
||||
+ else()
|
||||
+ string(APPEND LIBS_PRIVATE " -l${lib}")
|
||||
+ endif()
|
||||
+ endforeach()
|
||||
+ configure_file(snappy.pc.in "${CMAKE_CURRENT_BINARY_DIR}/snappy.pc" @ONLY)
|
||||
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/snappy.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
endif(SNAPPY_INSTALL)
|
||||
@@ -0,0 +1,51 @@
|
||||
vcpkg_from_github(
|
||||
OUT_SOURCE_PATH SOURCE_PATH
|
||||
REPO google/snappy
|
||||
REF ${VERSION}
|
||||
SHA512 0c1e1019e1bec9281f9877996d896e59e1533456130143224acb9cbfc35c1b0dd9de0a76e4a36494844d9ec58c295eed8c50bdf6dbabe47cf679652eb24b1281
|
||||
HEAD_REF master
|
||||
PATCHES
|
||||
no-werror.patch
|
||||
pkgconfig.diff
|
||||
rtti.diff
|
||||
# snappy.cc includes <immintrin.h> only when SNAPPY_HAVE_BMI2 or
|
||||
# SNAPPY_HAVE_X86_CRC32 is set, but MemCopy64() uses AVX intrinsics
|
||||
# whenever the compiler defines __AVX__. The options below turn the
|
||||
# SNAPPY_HAVE_* macros off, so a toolchain that targets AVX by default
|
||||
# (the ubuntu-26.04 GitHub runner) compiles that branch with no
|
||||
# intrinsics header. The upstream vcpkg port carries no patch; see
|
||||
# https://github.com/microsoft/vcpkg/issues/51047
|
||||
avx-immintrin.patch
|
||||
)
|
||||
file(COPY "${CURRENT_PORT_DIR}/snappy.pc.in" DESTINATION "${SOURCE_PATH}")
|
||||
|
||||
vcpkg_check_features(OUT_FEATURE_OPTIONS options
|
||||
FEATURES
|
||||
rtti SNAPPY_WITH_RTTI
|
||||
)
|
||||
|
||||
vcpkg_cmake_configure(
|
||||
SOURCE_PATH "${SOURCE_PATH}"
|
||||
OPTIONS
|
||||
${options}
|
||||
-DSNAPPY_BUILD_TESTS=OFF
|
||||
-DSNAPPY_BUILD_BENCHMARKS=OFF
|
||||
|
||||
# These variables can be overriden in a custom triplet, see usage file
|
||||
-DSNAPPY_HAVE_SSSE3=OFF
|
||||
-DSNAPPY_HAVE_X86_CRC32=OFF
|
||||
-DSNAPPY_HAVE_NEON_CRC32=OFF
|
||||
-DSNAPPY_HAVE_BMI2=OFF
|
||||
-DSNAPPY_HAVE_NEON=OFF
|
||||
)
|
||||
|
||||
vcpkg_cmake_install()
|
||||
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/Snappy)
|
||||
vcpkg_copy_pdbs()
|
||||
vcpkg_fixup_pkgconfig()
|
||||
|
||||
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
|
||||
|
||||
file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
|
||||
|
||||
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index cd71a47..d92aed0 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -53,8 +53,10 @@ if(MSVC)
|
||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||
|
||||
# Disable RTTI.
|
||||
+ if(NOT SNAPPY_WITH_RTTI)
|
||||
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
|
||||
+ endif()
|
||||
else(MSVC)
|
||||
# Use -Wall for clang and gcc.
|
||||
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
|
||||
@@ -82,9 +84,11 @@ else(MSVC)
|
||||
string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
|
||||
|
||||
+ if(NOT SNAPPY_WITH_RTTI)
|
||||
# Disable RTTI.
|
||||
string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
|
||||
+ endif()
|
||||
endif(MSVC)
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
|
||||
@@ -0,0 +1,11 @@
|
||||
prefix=${pcfiledir}/../..
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: snappy
|
||||
Description: A fast compressor/decompressor.
|
||||
Version: @PROJECT_VERSION@
|
||||
Libs: -L${libdir} -lsnappy
|
||||
Cflags: -I${includedir}
|
||||
Libs.private: @LIBS_PRIVATE@
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
snappy provides CMake targets:
|
||||
|
||||
find_package(Snappy CONFIG REQUIRED)
|
||||
target_link_libraries(main PRIVATE Snappy::snappy)
|
||||
|
||||
Optimizations based on hardware support are disabled by default.
|
||||
You can enable them by adding corresponding flags to VCPKG_CMAKE_CONFIGURE_OPTIONS inside a custom triplet file, for example:
|
||||
|
||||
if("${PORT}" STREQUAL "snappy")
|
||||
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DSNAPPY_HAVE_SSSE3=ON -DSNAPPY_HAVE_BMI2=ON)
|
||||
endif()
|
||||
|
||||
For a full list of possible options, see project's root CMakeLists.txt.
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "snappy",
|
||||
"version": "1.2.2",
|
||||
"port-version": 3,
|
||||
"$comment": "Local overlay of vcpkg's snappy port: adds avx-immintrin.patch so the port builds with a toolchain that targets AVX by default. See ThirdParty/vcpkg-overlay-ports/snappy/portfile.cmake.",
|
||||
"description": "A fast compressor/decompressor.",
|
||||
"homepage": "https://github.com/google/snappy",
|
||||
"license": null,
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
}
|
||||
],
|
||||
"features": {
|
||||
"rtti": {
|
||||
"description": "Build with dynamic typeinfo."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,6 @@
|
||||
}
|
||||
],
|
||||
"overlay-ports": [
|
||||
"ThirdParty/vcpkg-overlay-ports"
|
||||
"ThirdParty/vcpkg-overlay-ports/thrift"
|
||||
]
|
||||
}
|
||||
@@ -13,5 +13,8 @@
|
||||
],
|
||||
"overlay-triplets": [
|
||||
"ThirdParty/vcpkg-overlay-triplets"
|
||||
],
|
||||
"overlay-ports": [
|
||||
"ThirdParty/vcpkg-overlay-ports/snappy"
|
||||
]
|
||||
}
|
||||
@@ -7,6 +7,24 @@
|
||||
| `vcpkg-configuration.json` | Default registry configuration used by all builds |
|
||||
| `vcpkg-configuration-rhel8.json` | RHEL8-specific registry configuration with a separate baseline |
|
||||
|
||||
## Overlay ports
|
||||
|
||||
`ThirdParty/vcpkg-overlay-ports/` holds local copies of upstream vcpkg ports
|
||||
that need a patch the upstream port does not carry. Each configuration file
|
||||
opts in to individual ports rather than the whole directory, because the two
|
||||
baselines resolve different versions: pointing a profile at the parent
|
||||
directory would silently override every port in it.
|
||||
|
||||
| Port | Used by | Reason |
|
||||
|------|---------|--------|
|
||||
| `snappy` | `vcpkg-configuration.json` | `snappy.cc` guards `<immintrin.h>` on `SNAPPY_HAVE_BMI2`/`SNAPPY_HAVE_X86_CRC32`, which the port turns off, but `MemCopy64()` uses AVX intrinsics whenever `__AVX__` is defined. Fails on the ubuntu-26.04 runner. [microsoft/vcpkg#51047](https://github.com/microsoft/vcpkg/issues/51047) |
|
||||
| `thrift` | `vcpkg-configuration-rhel8.json` | `Mutex.h` uses `int64_t` without including `<cstdint>`, which GCC 15 no longer provides transitively |
|
||||
|
||||
When adding a port, copy it from `ThirdParty/vcpkg/ports/<name>`, add the patch
|
||||
to `PATCHES` with a comment explaining why, bump `port-version`, and add the
|
||||
port's path to the `overlay-ports` array of the configurations that need it.
|
||||
Drop the overlay once upstream carries an equivalent fix.
|
||||
|
||||
## Changing the baseline
|
||||
|
||||
The `baseline` field in each configuration file pins the vcpkg registry to a specific commit of [microsoft/vcpkg](https://github.com/microsoft/vcpkg). Packages available at that commit are used for dependency resolution.
|
||||
|
||||
Reference in new issue
Block a user