diff options
| author | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
|---|---|---|
| committer | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
| commit | 54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch) | |
| tree | d915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/libsodium | |
Diffstat (limited to 'vcpkg/ports/libsodium')
| -rw-r--r-- | vcpkg/ports/libsodium/001-mingw-i386.patch | 21 | ||||
| -rw-r--r-- | vcpkg/ports/libsodium/portfile.cmake | 85 | ||||
| -rw-r--r-- | vcpkg/ports/libsodium/sodiumConfig.cmake.in | 32 | ||||
| -rw-r--r-- | vcpkg/ports/libsodium/vcpkg.json | 15 |
4 files changed, 153 insertions, 0 deletions
diff --git a/vcpkg/ports/libsodium/001-mingw-i386.patch b/vcpkg/ports/libsodium/001-mingw-i386.patch new file mode 100644 index 0000000..6f8cae8 --- /dev/null +++ b/vcpkg/ports/libsodium/001-mingw-i386.patch @@ -0,0 +1,21 @@ +diff --git a/src/libsodium/randombytes/internal/randombytes_internal_random.c b/src/libsodium/randombytes/internal/randombytes_internal_random.c +--- a/src/libsodium/randombytes/internal/randombytes_internal_random.c ++++ b/src/libsodium/randombytes/internal/randombytes_internal_random.c +@@ -45,7 +45,7 @@ + # include <poll.h> + #endif + #ifdef HAVE_RDRAND +-# ifdef __clang__ ++# if defined (__clang__) && (!defined(__MINGW32__) || !defined(__i386__)) + # pragma clang attribute push(__attribute__((target("rdrnd"))), apply_to = function) + # elif defined(__GNUC__) + # pragma GCC target("rdrnd") +@@ -639,7 +639,7 @@ struct randombytes_implementation randombytes_internal_implementation = { + }; + + #ifdef HAVE_RDRAND +-# ifdef __clang__ ++# if defined (__clang__) && (!defined(__MINGW32__) || !defined(__i386__)) + # pragma clang attribute pop + # endif + #endif diff --git a/vcpkg/ports/libsodium/portfile.cmake b/vcpkg/ports/libsodium/portfile.cmake new file mode 100644 index 0000000..a3f4130 --- /dev/null +++ b/vcpkg/ports/libsodium/portfile.cmake @@ -0,0 +1,85 @@ +# libsodium has a special branching/tagging scheme, where regular version tags can actually be moved +# as new patches are applied to that version. This means that we may get unexpected hash mismatches +# when the upstream tag points to a new commit. To avoid this, we must make sure that we always +# use a '-RELEASE' tag, since those seem to be fixed to a single commit. +# See https://github.com/jedisct1/libsodium/issues/1373#issuecomment-2135172301 for more info. +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO jedisct1/libsodium + REF "${VERSION}-RELEASE" + SHA512 477b9dc10d87ae3c83db3fc207b50b9fe39593684a59f164986cce32bdaba95db0df7dee32149bf9a23c5794354fce8241d88a9a4bd4bbf2630483cbbc378c2f + HEAD_REF master + PATCHES + 001-mingw-i386.patch +) + +if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + set(lib_linkage "LIB") + if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + set(lib_linkage "DLL") + endif() + + set(LIBSODIUM_PROJECT_SUBPATH "builds/msvc/vs2022/libsodium/libsodium.vcxproj" CACHE STRING "Triplet variable") + + vcpkg_msbuild_install( + SOURCE_PATH "${SOURCE_PATH}" + PROJECT_SUBPATH "${LIBSODIUM_PROJECT_SUBPATH}" + RELEASE_CONFIGURATION "Release${lib_linkage}" + DEBUG_CONFIGURATION "Debug${lib_linkage}" + ) + + file(INSTALL "${SOURCE_PATH}/src/libsodium/include/sodium.h" "${SOURCE_PATH}/src/libsodium/include/sodium" DESTINATION "${CURRENT_PACKAGES_DIR}/include") + file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/src/libsodium/include/sodium/version.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/sodium") + file(REMOVE "${CURRENT_PACKAGES_DIR}/include/Makefile.am" "${CURRENT_PACKAGES_DIR}/include/sodium/version.h.in") + + block(SCOPE_FOR VARIABLES) + set(PACKAGE_NAME "libsodium") + set(PACKAGE_VERSION "${VERSION}") + set(prefix [[unused]]) + set(exec_prefix [[${prefix}]]) + set(includedir [[${prefix}/include]]) + set(libdir [[${prefix}/lib]]) + set(PKGCONFIG_LIBS_PRIVATE "") + configure_file("${SOURCE_PATH}/libsodium.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libsodium.pc" @ONLY) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libsodium.pc" " -lsodium" " -llibsodium") + if(NOT VCPKG_BUILD_TYPE) + set(includedir [[${prefix}/../include]]) + configure_file("${SOURCE_PATH}/libsodium.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libsodium.pc" @ONLY) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libsodium.pc" " -lsodium" " -llibsodium") + endif() + endblock() +else() + if(VCPKG_TARGET_IS_EMSCRIPTEN) + list(APPEND OPTIONS "--disable-ssp" "--disable-asm") + endif() + if(NOT VCPKG_TARGET_IS_MINGW) + list(APPEND OPTIONS --disable-pie) + endif() + + vcpkg_configure_make( + AUTOCONFIG + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS ${OPTIONS} + ) + vcpkg_install_make() + + file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" + ) +endif() + +vcpkg_fixup_pkgconfig() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/sodium/export.h" "#ifdef SODIUM_STATIC" "#if 1") +endif() + +# vcpkg legacy +configure_file( + "${CMAKE_CURRENT_LIST_DIR}/sodiumConfig.cmake.in" + "${CURRENT_PACKAGES_DIR}/share/unofficial-sodium/unofficial-sodiumConfig.cmake" + @ONLY +) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/vcpkg/ports/libsodium/sodiumConfig.cmake.in b/vcpkg/ports/libsodium/sodiumConfig.cmake.in new file mode 100644 index 0000000..f6d21a2 --- /dev/null +++ b/vcpkg/ports/libsodium/sodiumConfig.cmake.in @@ -0,0 +1,32 @@ +
+if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static" AND NOT WIN32)
+ include(CMakeFindDependencyMacro)
+ find_dependency(Threads)
+endif()
+
+if(NOT TARGET unofficial-sodium::sodium)
+ add_library(unofficial-sodium::sodium UNKNOWN IMPORTED)
+
+ set_target_properties(unofficial-sodium::sodium PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include"
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ )
+
+ if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static" AND NOT WIN32)
+ set_target_properties(unofficial-sodium::sodium PROPERTIES
+ INTERFACE_LINK_LIBRARIES Threads::Threads
+ )
+ endif()
+
+ find_library(VCPKG_SODIUM_LIBRARY_RELEASE NAMES sodium libsodium PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib" NO_DEFAULT_PATH)
+ if(EXISTS "${VCPKG_SODIUM_LIBRARY_RELEASE}")
+ set_property(TARGET unofficial-sodium::sodium APPEND PROPERTY IMPORTED_CONFIGURATIONS "Release")
+ set_target_properties(unofficial-sodium::sodium PROPERTIES IMPORTED_LOCATION_RELEASE "${VCPKG_SODIUM_LIBRARY_RELEASE}")
+ endif()
+
+ find_library(VCPKG_SODIUM_LIBRARY_DEBUG NAMES sodium libsodium PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib" NO_DEFAULT_PATH)
+ if(EXISTS "${VCPKG_SODIUM_LIBRARY_DEBUG}")
+ set_property(TARGET unofficial-sodium::sodium APPEND PROPERTY IMPORTED_CONFIGURATIONS "Debug")
+ set_target_properties(unofficial-sodium::sodium PROPERTIES IMPORTED_LOCATION_DEBUG "${VCPKG_SODIUM_LIBRARY_DEBUG}")
+ endif()
+endif()
diff --git a/vcpkg/ports/libsodium/vcpkg.json b/vcpkg/ports/libsodium/vcpkg.json new file mode 100644 index 0000000..d438b0b --- /dev/null +++ b/vcpkg/ports/libsodium/vcpkg.json @@ -0,0 +1,15 @@ +{ + "name": "libsodium", + "version": "1.0.20", + "port-version": 3, + "description": "A modern and easy-to-use crypto library", + "homepage": "https://libsodium.org/", + "license": "ISC", + "dependencies": [ + { + "name": "vcpkg-msbuild", + "host": true, + "platform": "windows & !mingw" + } + ] +} |