-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zxcvbn-c: added recipe for version 2.5
- Loading branch information
Showing
9 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
+) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"2.5": | ||
folder: all |