Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zxcvbn: added recipe for version 2.5 #23671

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions recipes/zxcvbn/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"2.5":
archive:
url: "https://github.com/tsyrogit/zxcvbn-c/archive/refs/tags/v2.5.tar.gz"
sha256: "77d6c6ecb35952a8d8ce7f736b7a2bf466275c48210e309b73782d6b7e84dffd"
cmakelists:
url: "https://raw.githubusercontent.com/tsyrogit/zxcvbn-c/31948901f613a8500e710fe13772591e4ab245bc/CMakeLists.txt"
sha256: "8a5f3c6a7afd203fc3e5e877ec06252a0823473a976e0db910334425005affaa"
patches:
"2.5":
- patch_file: "patches/2.5-0001-no-tests.patch"
patch_description: "disable building of tests which are broken in the CMakeLists.txt"
patch_type: "portability"
88 changes: 88 additions & 0 deletions recipes/zxcvbn/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.files import apply_conandata_patches, copy, download, get, patch, rm
import os

required_conan_version = ">=1.54.0"

class ZxcvbnConan(ConanFile):
name = "zxcvbn"
description = "C/C++ implementation of the zxcvbn password strength estimation"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/tsyrogit/zxcvbn-c"
topics = ("password", "security", "zxcvbn")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def build_requirements(self):
if cross_building(self):
self.tool_requires(f"{self.name}/{self.version}")
Comment on lines +27 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any insight into why this is needed? From what I can gather, cross compiling should not need to depend on the library itself


def export_sources(self):
copy(self, f"{self.version}-*.patch", dst=os.path.join(self.export_sources_folder, "patches"), src=os.path.join(self.recipe_folder, "patches"))

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def source(self):
sources = self.conan_data["sources"][self.version]
get(self, **sources["archive"], strip_root=True)
download(self, filename="CMakeLists.txt", **sources["cmakelists"])
# fixes Linux build when "Makefile" is generated but the original "makefile" used
rm(self, "makefile", self.source_folder)
# for the conditional #include "stdafx.h" in zxcvbn.c
with open(os.path.join(self.source_folder, "stdafx.h"), "ab") as f:
f.close()

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

def _patch_if_exists(self, patch_name):
patch_file=os.path.join(self.export_sources_folder, "patches", f"{self.version}-{patch_name}.patch")
if os.path.exists(patch_file):
print(f"Applying the '{patch_name}' patch...")
patch(self, patch_file=patch_file)

def _patch_sources(self):
apply_conandata_patches(self)
if cross_building(self):
self._patch_if_exists("no-dictgen")
if self.settings.os not in ["Linux", "FreeBSD"]:
self._patch_if_exists("no-libm")
if self.settings.os == "Windows":
self._patch_if_exists("windows-portability")
Comment on lines +64 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patches should not be conditional, the sources should be modified unconditionally if possible.


def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build(target="zxcvbn-shared" if self.options.shared else "zxcvbn-static")

def package(self):
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "zxcvbn.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include"))
for pattern in ["*.a", "*.so*", "*.dylib", "*.lib"]:
copy(self, pattern, src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
for pattern in ["*.dll", "dictgen", "dictgen.exe"]:
copy(self, pattern, src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)

def package_info(self):
self.cpp_info.libs = ["zxcvbn"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
11 changes: 11 additions & 0 deletions recipes/zxcvbn/all/patches/2.5-0001-no-tests.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -38,7 +38,7 @@
set_target_properties(zxcvbn-static PROPERTIES OUTPUT_NAME zxcvbn)

# in root projects we also want to build/run tests...
-if(PROJECT_IS_TOP_LEVEL)
+if(FALSE)

# C tests
add_executable(test-internals test-internals.c dict-src.h dict-crc.h zxcvbn.h)
13 changes: 13 additions & 0 deletions recipes/zxcvbn/all/patches/2.5-no-dictgen.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -2,7 +2,7 @@

project(zxcvbn-c VERSION 0 LANGUAGES C CXX)

-add_executable(dictgen dict-generate.cpp)
-target_compile_features(dictgen PUBLIC cxx_std_11)
-target_compile_options(dictgen PRIVATE "-O3")
+add_custom_target(dictgen
+ COMMAND ${CMAKE_COMMAND} -E echo "Using prebuilt dictgen"
+)

20 changes: 20 additions & 0 deletions recipes/zxcvbn/all/patches/2.5-no-libm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,7 @@ add_custom_command(OUTPUT dict-crc.h zxcvbn.dict COMMAND dictgen -b -o ${CMAKE_C
add_library(zxcvbn-shared SHARED zxcvbn.c dict-crc.h dict-src.h)
target_include_directories(zxcvbn-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(zxcvbn-shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(zxcvbn-shared PUBLIC ${LIBM})
+
set_target_properties(zxcvbn-shared PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME zxcvbn
@@ -34,7 +34,7 @@ set_target_properties(zxcvbn-shared PROPERTIES
# build static version of library
add_library(zxcvbn-static STATIC zxcvbn.c dict-crc.h dict-src.h)
target_include_directories(zxcvbn-static PRIVATE ${CMAKE_CURRENT_BINARY_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(zxcvbn-static PUBLIC ${LIBM})
+
set_target_properties(zxcvbn-static PROPERTIES OUTPUT_NAME zxcvbn)

# in root projects we also want to build/run tests...
17 changes: 17 additions & 0 deletions recipes/zxcvbn/all/patches/2.5-windows-portability.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,4 +9,4 @@
-add_compile_options("-Wall" "-Wextra")
+

find_library(LIBM m)

@@ -29,7 +29,7 @@ set_target_properties(zxcvbn-shared PROPERTIES
OUTPUT_NAME zxcvbn
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
-)
+ WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

# build static version of library
add_library(zxcvbn-static STATIC zxcvbn.c dict-crc.h dict-src.h)
7 changes: 7 additions & 0 deletions recipes/zxcvbn/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(zxcvbn REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE zxcvbn::zxcvbn)
25 changes: 25 additions & 0 deletions recipes/zxcvbn/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os

class ZxcvbnTestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
7 changes: 7 additions & 0 deletions recipes/zxcvbn/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <zxcvbn.h>

int main(void) {
ZxcvbnMatch("password", NULL, NULL);

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/zxcvbn/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.5":
folder: all