diff --git a/recipes/zxcvbn-c/all/conandata.yml b/recipes/zxcvbn-c/all/conandata.yml new file mode 100644 index 00000000000000..02bab3e9743193 --- /dev/null +++ b/recipes/zxcvbn-c/all/conandata.yml @@ -0,0 +1,19 @@ +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-tests.patch" + patch_description: "disable building of tests; also fixes the 'file failed to create symbolic link' error on Windows" + patch_type: "portability" + - patch_file: "patches/2.5-0002-libm.patch" + patch_description: "disable libm linking and unsupported compile options" + patch_type: "portability" + - patch_file: "patches/2.5-0003-crossbuilding.patch" + patch_description: "crossbuilding: disable the dictgen executable building" + patch_type: "portability" diff --git a/recipes/zxcvbn-c/all/conanfile.py b/recipes/zxcvbn-c/all/conanfile.py new file mode 100644 index 00000000000000..2bdfbece627862 --- /dev/null +++ b/recipes/zxcvbn-c/all/conanfile.py @@ -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 copy, download, export_conandata_patches, get, patch, rm +import os + +required_conan_version = ">=1.54.0" + +class ZxcvbncConan(ConanFile): + name = "zxcvbn-c" + 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}") + + def export_sources(self): + export_conandata_patches(self) + + 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) + rm(self, "makefile", self.source_folder) + download(self, filename="CMakeLists.txt", **sources["cmakelists"]) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def _patch_sources(self): + # for the conditional #include "stdafx.h" in zxcvbn.c + if self.settings.os == "Windows": + with open(os.path.join(self.source_folder, "stdafx.h"), "ab") as f: + f.close() + + for it in self.conan_data.get("patches", {}).get(self.version, []): + if "tests" in it["patch_file"] and not self.conf.get("tools.build:skip_test", default=True): + continue + if "libm" in it["patch_file"] and self.settings.os not in ["Emscripten", "Windows"]: + continue + if "crossbuilding" in it["patch_file"] and not cross_building(self): + continue + entry = it.copy() + patch_file_path = os.path.join(self.export_sources_folder, entry.pop("patch_file")) + patch(self, patch_file=patch_file_path, **entry) + + 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")) + copy(self, "*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, "*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, "dictgen*", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) + copy(self, "*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) + copy(self, "*.dylib", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) + copy(self, "*.so*", 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") diff --git a/recipes/zxcvbn-c/all/patches/2.5-0001-tests.patch b/recipes/zxcvbn-c/all/patches/2.5-0001-tests.patch new file mode 100644 index 00000000000000..34ebe3d292cff9 --- /dev/null +++ b/recipes/zxcvbn-c/all/patches/2.5-0001-tests.patch @@ -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) diff --git a/recipes/zxcvbn-c/all/patches/2.5-0002-libm.patch b/recipes/zxcvbn-c/all/patches/2.5-0002-libm.patch new file mode 100644 index 00000000000000..f305e9462d3168 --- /dev/null +++ b/recipes/zxcvbn-c/all/patches/2.5-0002-libm.patch @@ -0,0 +1,33 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -6,10 +6,10 @@ + target_compile_features(dictgen PUBLIC cxx_std_11) + target_compile_options(dictgen PRIVATE "-O3") + +-add_compile_options("-Wall" "-Wextra") + +-find_library(LIBM m) + ++ ++ + # list of dictionaries + set(WORDS words-eng_wiki.txt words-female.txt words-male.txt words-passwd.txt words-surname.txt words-tv_film.txt) + list(TRANSFORM WORDS PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) +@@ -23,7 +23,7 @@ + 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 @@ + # 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... diff --git a/recipes/zxcvbn-c/all/patches/2.5-0003-crossbuilding.patch b/recipes/zxcvbn-c/all/patches/2.5-0003-crossbuilding.patch new file mode 100644 index 00000000000000..8e840ab62b6779 --- /dev/null +++ b/recipes/zxcvbn-c/all/patches/2.5-0003-crossbuilding.patch @@ -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" ++) + diff --git a/recipes/zxcvbn-c/all/test_package/CMakeLists.txt b/recipes/zxcvbn-c/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..6a8b130fa1c2cf --- /dev/null +++ b/recipes/zxcvbn-c/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(zxcvbn-c REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE zxcvbn-c::zxcvbn-c) diff --git a/recipes/zxcvbn-c/all/test_package/conanfile.py b/recipes/zxcvbn-c/all/test_package/conanfile.py new file mode 100644 index 00000000000000..0a808db45f2453 --- /dev/null +++ b/recipes/zxcvbn-c/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +# It will become the standard on Conan 2.x +class TestPackageConan(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") diff --git a/recipes/zxcvbn-c/all/test_package/test_package.c b/recipes/zxcvbn-c/all/test_package/test_package.c new file mode 100644 index 00000000000000..94532fb932215f --- /dev/null +++ b/recipes/zxcvbn-c/all/test_package/test_package.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + ZxcvbnMatch("password", NULL, NULL); + + return EXIT_SUCCESS; +} diff --git a/recipes/zxcvbn-c/config.yml b/recipes/zxcvbn-c/config.yml new file mode 100644 index 00000000000000..ab826811e95e76 --- /dev/null +++ b/recipes/zxcvbn-c/config.yml @@ -0,0 +1,3 @@ +versions: + "2.5": + folder: all