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

primesieve: new package #22577

Merged
merged 9 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/primesieve/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"11.2":
url: "https://github.com/kimwalisch/primesieve/archive/refs/tags/v11.2.tar.gz"
sha256: "86c31bae9c378340b19669eafef8c5e45849adf7b9c92af1d212a2a2bfa0a5db"
97 changes: 97 additions & 0 deletions recipes/primesieve/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, rename, rm, rmdir
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
from conan.tools.scm import Version
import os


required_conan_version = ">=1.53.0"

class PrimesieveConan(ConanFile):
name = "primesieve"
description = "Fast prime number generator"
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/kimwalisch/primesieve"
topics = ("math", "prime-numbers", "sieve-of-eratosthenes")
settings = "os", "arch", "compiler", "build_type"
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_multiarch": [True, False],
"with_msvc_crt_static": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_multiarch": True,
"with_msvc_crt_static": False,
}
package_type = "library"

@property
def _min_cppstd(self):
return 11

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 layout(self):
cmake_layout(self, src_folder="src")

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

if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) <= "5":
raise ConanInvalidConfiguration("GCC<=5 is currently not supported. Contributions with fixes are welcome.")
Comment on lines +53 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) <= "5":
raise ConanInvalidConfiguration("GCC<=5 is currently not supported. Contributions with fixes are welcome.")

I used to work with GCC 4.7 with C++11 minimal support. GCC 4.8 has a really good coverage of C++11. Usually, we don't add restriction to compiler version when the project only requires C++11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC 5 fails to build, not sure why though. @kimwalisch mentioned above that 4.9 is known not to work, for example.


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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_PRIMESIEVE"] = False
tc.variables["BUILD_DOC"] = False
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["BUILD_TESTS"] = False
tc.variables["WITH_MULTIARCH"] = self.options.with_multiarch
tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared
if is_msvc(self):
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW"
tc.variables["WITH_MSVC_CRT_STATIC"] = self.options.with_msvc_crt_static
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)
tc.generate()

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

def package(self):
copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
if is_msvc(self) and self.options.shared:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any insight into this rename? It looks funny that it gets generated with this name in the first place :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is set to avoid issues when packaging both static and shared libraries in the same package. This doesn't apply to us, so I think it's fine to do this? Unless we have a way of telling Conan that this is how it's done.

https://github.com/kimwalisch/primesieve/blob/master/CMakeLists.txt#L138

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, keep the original name, it should work as usual, right? I remember having other projects having this same prefix when exporting dll libs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would fail without this change, I presume it tries to look for "primesieve".lib but it's "primesieve.dll".lib. I'm fine with changing it back, I just don't know how I would get it to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uilianries @RubenRBS Many more recipes are doing this rename. You can run a grep and see this ad-hoc helper function fix_msvc_libname. The problem is coming from the hook error:

primesieve/11.2: WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
[HOOK - conan-center.py] post_package_info(): ERROR: [LIBRARY DOES NOT EXIST (KB-H054)] Component primesieve::primesieve library 'primesieve' is listed in the recipe, but not found installed at self.cpp_info.libdirs. Make sure you compiled the library correctly. If so, then the library name should probably be fixed. Otherwise, then the component should be removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H054-LIBRARY-DOES-NOT-EXIST) 
ERROR: 
	ConanException: [HOOK - conan-center.py] post_package_info(): Some checks failed running the hook, check the output

@Ahajha We just created an issue to review this process conan-io/hooks#528 Let's figure out if there is a bug in the hooks so we can use the original library name instead of the renamed one.

rename(self, os.path.join(self.package_folder, "lib", "primesieve.dll.lib"), os.path.join(self.package_folder, "lib", "primesieve.lib"))

def package_info(self):
self.cpp_info.libs = ["primesieve"]
self.cpp_info.set_property("cmake_file_name", "primesieve")
self.cpp_info.set_property("cmake_target_name", "primesieve::primesieve")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["pthread", "m"]
9 changes: 9 additions & 0 deletions recipes/primesieve/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.8)

project(test_package CXX) # if the project uses c++

find_package(primesieve REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE primesieve::primesieve)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions recipes/primesieve/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")
15 changes: 15 additions & 0 deletions recipes/primesieve/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <primesieve.hpp>

#include <cstdint>
#include <iostream>
#include <vector>

int main() {
std::vector<uint64_t> primes;
primesieve::generate_n_primes(5, &primes);
std::cout << "First 5 primes: ";
for (const auto prime : primes) {
std::cout << prime << ' ';
}
std::cout << '\n';
}
3 changes: 3 additions & 0 deletions recipes/primesieve/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"11.2":
folder: all
Loading