Skip to content

Commit

Permalink
zxcvbn-c: added recipe for version 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
laci-aura committed Apr 20, 2024
1 parent c2268c0 commit a6c5db3
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 0 deletions.
19 changes: 19 additions & 0 deletions recipes/zxcvbn-c/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
87 changes: 87 additions & 0 deletions recipes/zxcvbn-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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
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)
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")
11 changes: 11 additions & 0 deletions recipes/zxcvbn-c/all/patches/2.5-0001-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)
33 changes: 33 additions & 0 deletions recipes/zxcvbn-c/all/patches/2.5-0002-libm.patch
Original file line number Diff line number Diff line change
@@ -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...
13 changes: 13 additions & 0 deletions recipes/zxcvbn-c/all/patches/2.5-0003-crossbuilding.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"
+)

7 changes: 7 additions & 0 deletions recipes/zxcvbn-c/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-c REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE zxcvbn-c::zxcvbn-c)
27 changes: 27 additions & 0 deletions recipes/zxcvbn-c/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 7 additions & 0 deletions recipes/zxcvbn-c/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-c/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.5":
folder: all

0 comments on commit a6c5db3

Please sign in to comment.