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

pbc: migrate to Conan v2 #18950

Merged
merged 15 commits into from
Jun 13, 2024
1 change: 0 additions & 1 deletion recipes/pbc/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
url: "https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz"
sha256: "772527404117587560080241cedaf441e5cac3269009cdde4c588a1dce4c23d2"
patches:
"0.5.14":
- patch_file: "patches/0.5.14-0001-fix-config-sub-ios.patch"

Check warning on line 7 in recipes/pbc/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0.5.14-0 ... ^ (line: 7)
base_path: ""
133 changes: 72 additions & 61 deletions recipes/pbc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,109 @@
from conans import ConanFile, AutoToolsBuildEnvironment, tools
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import XCRun, to_apple_arch, fix_apple_shared_install_name
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, chdir
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc

required_conan_version = ">=1.53.0"


class PbcConan(ConanFile):
name = "pbc"
topics = ("pbc", "crypto", "cryptography", "security", "pairings", "cryptographic")
description = ("The PBC (Pairing-Based Crypto) library is a C library providing "
"low-level routines for pairing-based cryptosystems.")
license = "LGPL-3.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://crypto.stanford.edu/pbc/"
license = "LGPL-3.0"
description = "The PBC (Pairing-Based Crypto) library is a C library providing low-level routines for pairing-based cryptosystems."
topics = ("crypto", "cryptography", "security", "pairings", "cryptographic")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
_autotools = None
exports_sources = "patches/**"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

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:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("gmp/6.2.1")
self.requires("gmp/6.3.0", transitive_headers=True, transitive_libs=True)

def build_requirements(self):
self.build_requires("bison/3.7.6")
self.build_requires("flex/2.6.4")
def validate(self):
if is_msvc(self):
raise ConanInvalidConfiguration("pbc is not compatible with MSVC due to use of GNU extensions")

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def build_requirements(self):
self.tool_requires("flex/2.6.4")
self.tool_requires("bison/3.8.2")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True)

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(
self, win_bash=tools.os_info.is_windows
)
# Need to override environment or configure will fail despite that flex
# is actually available.
args = ["LEX=flex"]
if self.options.shared:
args.extend(["--disable-static", "--enable-shared"])
else:
args.extend(["--disable-shared", "--enable-static"])
get(self, **self.conan_data["sources"][self.version], strip_root=True)

# No idea why this is necessary, but if you don't set CC this way, then
# configure complains that it can't find gmp.
if (
tools.cross_building(self.settings)
and self.settings.compiler == "apple-clang"
):
def generate(self):
env = VirtualBuildEnv(self)
env.generate()

xcr = tools.XCRun(self.settings)
target = tools.to_apple_arch(self.settings.arch) + "-apple-darwin"
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")

tc = AutotoolsToolchain(self)
tc.configure_args.append("LEX=flex")
# No idea why this is necessary, but if you don't set CC this way, then
# configure complains that it can't find gmp.
if cross_building(self) and self.settings.compiler == "apple-clang":
xcr = XCRun(self)
target = to_apple_arch(self) + "-apple-darwin"
min_ios = ""
if self.settings.os == "iOS":
min_ios = "-miphoneos-version-min={}".format(self.settings.os.version)

args.append(
"CC={} -isysroot {} -target {} {}".format(
xcr.cc, xcr.sdk_path, target, min_ios
)
)
min_ios = f"-miphoneos-version-min={self.settings.os.version}"
tc.configure_args.append(f"CC={xcr.cc} -isysroot {xcr.sdk_path} -target {target} {min_ios}")
tc.generate()

self._autotools.configure(args=args)
return self._autotools
deps = AutotoolsDeps(self)
deps.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
autotools = self._configure_autotools()
autotools.make()
apply_conandata_patches(self)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
self.copy(pattern="COPYING", dst="licenses")
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", self.package_folder, recursive=True)
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.libs = ["pbc"]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
9 changes: 3 additions & 6 deletions recipes/pbc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(pbc CONFIG REQUIRED)
find_package(pbc REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} pbc::pbc)
21 changes: 15 additions & 6 deletions recipes/pbc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

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

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/pbc/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/pbc/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)