Przeglądaj źródła

libfido2: add package (#5033)

* libfido2: add package

* add more configs

* fix openssl

* fix windows shared

* fix ninja build with msvc

* fix windows shared build

* pkgconf: add msys & cygwin

* remove pacman::libfido2-devel

* fix openssl
star9029 11 miesięcy temu
rodzic
commit
fe05cadc14

+ 13 - 0
packages/l/libfido2/patches/1.15.0/add-syslinks.patch

@@ -0,0 +1,13 @@
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 4c54198..b631d40 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -103,7 +103,7 @@ list(APPEND COMPAT_SOURCES
+ )
+ 
+ if(WIN32)
+-	list(APPEND BASE_LIBRARIES wsock32 ws2_32 bcrypt setupapi hid)
++	list(APPEND BASE_LIBRARIES wsock32 ws2_32 bcrypt setupapi hid crypt32)
+ 	if(USE_PCSC)
+ 		list(APPEND BASE_LIBRARIES winscard)
+ 	endif()

+ 83 - 0
packages/l/libfido2/patches/1.15.0/cmake-pkgconfig-find-deps.patch

@@ -0,0 +1,83 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 94e4292..7d0e142 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -169,27 +169,12 @@ endif()
+ 
+ 
+ if(MSVC)
+-	if((NOT CBOR_INCLUDE_DIRS) OR (NOT CBOR_LIBRARY_DIRS) OR
+-	   (NOT CRYPTO_INCLUDE_DIRS) OR (NOT CRYPTO_LIBRARY_DIRS) OR
+-	   (NOT ZLIB_INCLUDE_DIRS) OR (NOT ZLIB_LIBRARY_DIRS))
+-		message(FATAL_ERROR "please define "
+-		   "{CBOR,CRYPTO,ZLIB}_{INCLUDE,LIBRARY}_DIRS when "
+-		   "building under msvc")
+-	endif()
+-	if(BUILD_TESTS AND BUILD_SHARED_LIBS AND
+-	   ((NOT CBOR_BIN_DIRS) OR (NOT ZLIB_BIN_DIRS) OR (NOT CRYPTO_BIN_DIRS)))
+-		message(FATAL_ERROR "please define {CBOR,CRYPTO,ZLIB}_BIN_DIRS "
+-		   "when building tests")
+-	endif()
+-	if(NOT CBOR_LIBRARIES)
+-		set(CBOR_LIBRARIES cbor)
+-	endif()
+-	if(NOT ZLIB_LIBRARIES)
+-		set(ZLIB_LIBRARIES zlib1)
+-	endif()
+-	if(NOT CRYPTO_LIBRARIES)
+-		set(CRYPTO_LIBRARIES crypto)
+-	endif()
++	include(FindPkgConfig)
++	pkg_search_module(libcbor REQUIRED IMPORTED_TARGET libcbor)
++	find_package(OpenSSL REQUIRED)
++	find_package(ZLIB REQUIRED)
++	set(CBOR_LIBRARIES PkgConfig::libcbor)
++	set(CRYPTO_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
+ 
+ 	set(MSVC_DISABLED_WARNINGS_LIST
+ 		"C4152" # nonstandard extension used: function/data pointer
+@@ -218,26 +203,22 @@ if(MSVC)
+ 	set(NFC_LINUX OFF)
+ else()
+ 	include(FindPkgConfig)
+-	pkg_search_module(CBOR libcbor)
+-	pkg_search_module(CRYPTO libcrypto)
+-	pkg_search_module(ZLIB zlib)
++	pkg_search_module(libcbor REQUIRED IMPORTED_TARGET libcbor)
++	find_package(OpenSSL REQUIRED)
++	find_package(ZLIB REQUIRED)
+ 
+ 	if(NOT CBOR_FOUND AND NOT HAVE_CBOR_H)
+-		message(FATAL_ERROR "could not find libcbor")
++		# message(FATAL_ERROR "could not find libcbor")
+ 	endif()
+ 	if(NOT CRYPTO_FOUND AND NOT HAVE_OPENSSLV_H)
+-		message(FATAL_ERROR "could not find libcrypto")
++		# message(FATAL_ERROR "could not find libcrypto")
+ 	endif()
+ 	if(NOT ZLIB_FOUND)
+ 		message(FATAL_ERROR "could not find zlib")
+ 	endif()
+ 
+-	if(NOT CBOR_LIBRARIES)
+-		set(CBOR_LIBRARIES "cbor")
+-	endif()
+-	if(NOT CRYPTO_LIBRARIES)
+-		set(CRYPTO_LIBRARIES "crypto")
+-	endif()
++	set(CBOR_LIBRARIES PkgConfig::libcbor)
++	set(CRYPTO_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
+ 
+ 	if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ 		pkg_search_module(UDEV libudev REQUIRED)
+@@ -277,8 +258,8 @@ else()
+ 
+ 	if(USE_HIDAPI)
+ 		add_definitions(-DUSE_HIDAPI)
+-		pkg_search_module(HIDAPI hidapi${HIDAPI_SUFFIX} REQUIRED)
+-		set(HIDAPI_LIBRARIES hidapi${HIDAPI_SUFFIX})
++		pkg_search_module(hidapi REQUIRED IMPORTED_TARGET hidapi)
++		set(HIDAPI_LIBRARIES PkgConfig::hidapi)
+ 	endif()
+ 
+ 	if(NFC_LINUX)

+ 93 - 0
packages/l/libfido2/xmake.lua

@@ -0,0 +1,93 @@
+package("libfido2")
+    set_homepage("https://github.com/Yubico/libfido2")
+    set_description("Provides library functionality for FIDO2, including communication with a device over USB or NFC.")
+    set_license("BSD-2-Clause")
+
+    add_urls("https://github.com/Yubico/libfido2/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/Yubico/libfido2.git")
+
+    add_versions("1.15.0", "32e3e431cfe29b45f497300fdb7076971cb77fc584fcfa80084d823a6ed94fbb")
+
+    add_patches("1.15.0", "patches/1.15.0/cmake-pkgconfig-find-deps.patch", "1d8c559529f8589e44f794b33d9216234d44ef857742db9ef94693dbd41c9486")
+    add_patches("1.15.0", "patches/1.15.0/add-syslinks.patch", "1da25738d57afbb8c6b2a95796a9711d234a44903bc32e765377b2b455c340ee")
+
+    add_configs("hidapi", {description = "Use hidapi", default = false, type = "boolean"})
+    add_configs("pcsc", {description = "Enable experimental PCSC support", default = false, type = "boolean"})
+    add_configs("windows_hello", {description = "Abstract Windows Hello as a FIDO device", default = false, type = "boolean"})
+    add_configs("nfc", {description = "Enable NFC support on Linux", default = false, type = "boolean"})
+    add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
+
+    if is_plat("linux") then
+        add_extsources("pacman::libfido2", "apt::libfido2-dev")
+    elseif is_plat("macosx") then
+        add_extsources("brew::libfido2")
+    end
+
+    if is_plat("windows", "mingw") then
+        add_syslinks("setupapi", "hid", "bcrypt")
+    elseif is_plat("macosx") then
+        add_frameworks("CoreFoundation", "IOKit")
+    end
+
+    add_deps("cmake")
+    if is_host("windows") then
+        add_deps("pkgconf")
+    else
+        add_deps("pkg-config")
+    end
+
+    add_deps("openssl", "libcbor", "zlib")
+    if is_plat("linux") then
+        add_deps("libudev")
+    end
+
+    on_load(function(package)
+        if package:config("hidapi") then
+            package:add("deps", "hidapi")
+        end
+        if package:config("pcsc") then
+            if package:is_plat("windows", "mingw") then
+                package:add("syslinks", "winscard")
+            elseif package:is_plat("macosx") then
+                package:add("frameworks", "PCSC")
+            end
+        end
+    end)
+
+    on_install("windows", "linux", "macosx", "bsd", "mingw", "msys", function (package)
+        io.replace("CMakeLists.txt", "-Werror", "", {plain = true})
+        io.replace("CMakeLists.txt", "-WX", "", {plain = true})
+        io.replace("CMakeLists.txt", "/sdl", "", {plain = true})
+
+        local configs = {"-DBUILD_TESTS=OFF", "-DBUILD_EXAMPLES=OFF", "-DBUILD_MANPAGES=OFF"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        if package:config("shared") then
+            table.join2(configs, {"-DBUILD_SHARED_LIBS=ON", "-DBUILD_STATIC_LIBS=OFF"})
+        else
+            table.join2(configs, {"-DBUILD_SHARED_LIBS=OFF", "-DBUILD_STATIC_LIBS=ON"})
+        end
+
+        table.insert(configs, "-DUSE_HIDAPI=" .. (package:config("hidapi") and "ON" or "OFF"))
+        table.insert(configs, "-DUSE_PCSC=" .. (package:config("pcsc") and "ON" or "OFF"))
+        table.insert(configs, "-DUSE_WINHELLO=" .. (package:config("windows_hello") and "ON" or "OFF"))
+        table.insert(configs, "-DNFC_LINUX=" .. (package:config("nfc") and "ON" or "OFF"))
+        table.insert(configs, "-DBUILD_TOOLS=" .. (package:config("tools") and "ON" or "OFF"))
+
+        local openssl = package:dep("openssl")
+        if not openssl:is_system() then
+            table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
+        end
+
+        local opt = {}
+        if package:is_plat("windows") then
+            os.mkdir(path.join(package:buildir(), "src", "pdb"))
+            if package:config("shared") then
+                table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
+            end
+        end
+        import("package.tools.cmake").install(package, configs, opt)
+    end)
+
+    on_test(function (package)
+        assert(package:has_cfuncs("fido_dev_new", {includes = "fido.h"}))
+    end)

+ 1 - 1
packages/p/pkgconf/xmake.lua

@@ -25,7 +25,7 @@ package("pkgconf")
         end
     end)
 
-    on_install("@macosx", "@linux", "@bsd", function(package)
+    on_install("@macosx", "@linux", "@bsd", "@msys", "@cygwin", function(package)
         import("package.tools.autoconf").install(package)
     end)