Skip to content

Commit

Permalink
(#18858) add intx
Browse files Browse the repository at this point in the history
* add intx

* fix

* test v1

* compiler check

* resolve comment

* clean import

---------

Co-authored-by: Carlos Zoido <mrgalleta@gmail.com>
  • Loading branch information
pwqbot and czoido authored Jul 26, 2023
1 parent 108aa46 commit a547bc7
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/intx/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.10.1":
url: "https://github.com/chfast/intx/archive/v0.10.1.tar.gz"
sha256: "4663073458b5e0564e92058e5aa1a7ce88634fc72827191856b17bd7335de29b"
65 changes: 65 additions & 0 deletions recipes/intx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.51.1"

class IntxConan(ConanFile):
name = "intx"
description = "Extended precision integer C++ library"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/chfast/intx"
topics = ("evm", "biginteger", "arbitrary-precision", "header-only")
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"

@property
def _min_cppstd(self):
return 20

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

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "16",
"msvc": "192",
"gcc": "12",
"clang": "15",
"apple-clang": "14.1",
}

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

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

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
8 changes: 8 additions & 0 deletions recipes/intx/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES CXX)

find_package(intx REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE intx::intx)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
26 changes: 26 additions & 0 deletions recipes/intx/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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", "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 can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
6 changes: 6 additions & 0 deletions recipes/intx/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <intx/intx.hpp>

int main(int argc, char**)
{
return static_cast<int>(intx::uint512{argc} / (intx::uint512{1} << 111));
}
9 changes: 9 additions & 0 deletions recipes/intx/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.12)

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/)
18 changes: 18 additions & 0 deletions recipes/intx/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


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

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

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/intx/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.10.1":
folder: all

0 comments on commit a547bc7

Please sign in to comment.