Skip to content

Commit 1523515

Browse files
committed
package the fork as a conan recipe so a build can select the segment backend
1 parent 8eeb574 commit 1523515

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

conanfile.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import os
2+
3+
from conan import ConanFile
4+
from conan.tools.build import check_min_cppstd
5+
from conan.tools.files import copy, save
6+
from conan.tools.layout import basic_layout
7+
8+
required_conan_version = ">=2.0"
9+
10+
# Raises the standard of every consumer target that links Metall::Metall. The
11+
# engine headers are C++23, and a consumer may pin a lower standard on its own
12+
# target (metall-ffi pins 20), which wins over the toolchain default. A compile
13+
# feature on the imported target is what CMake takes the maximum of.
14+
CXX_STD_MODULE = """\
15+
if(TARGET Metall::Metall)
16+
set_property(TARGET Metall::Metall APPEND PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_23)
17+
endif()
18+
"""
19+
20+
21+
class MetallConan(ConanFile):
22+
"""The metall fork, packaged so consumers can select the segment backend.
23+
24+
Same package name, version, cmake file name and target name as the
25+
upstream recipe, so a consumer graph switches backends through
26+
[replace_requires] in a profile without touching any recipe.
27+
"""
28+
29+
name = "metall"
30+
version = "0.32"
31+
homepage = "https://github.com/dice-group/metall"
32+
description = "Meta allocator for persistent memory, with the privateer segment backend"
33+
license = "MIT", "Apache-2.0"
34+
package_type = "header-library"
35+
settings = "os", "arch", "compiler", "build_type"
36+
options = {"use_privateer": [True, False]}
37+
default_options = {"use_privateer": True}
38+
exports_sources = "include/*", "LICENSE*", "COPYRIGHT"
39+
no_copy_source = True
40+
41+
def layout(self):
42+
basic_layout(self)
43+
44+
def requirements(self):
45+
self.requires("boost/[>=1.81 <2]", transitive_headers=True)
46+
if self.options.use_privateer:
47+
# The adapter is a header of this package and includes engine
48+
# headers, so consumers compile against them and link the engine.
49+
self.requires("privateer/0.2.0@dice-group/rewrite",
50+
transitive_headers=True, transitive_libs=True)
51+
52+
def validate(self):
53+
check_min_cppstd(self, 23 if self.options.use_privateer else 17)
54+
55+
def package(self):
56+
copy(self, "*", src=os.path.join(self.source_folder, "include"),
57+
dst=os.path.join(self.package_folder, "include"))
58+
copy(self, "LICENSE*", src=self.source_folder,
59+
dst=os.path.join(self.package_folder, "licenses"))
60+
copy(self, "COPYRIGHT", src=self.source_folder,
61+
dst=os.path.join(self.package_folder, "licenses"))
62+
if self.options.use_privateer:
63+
save(self, os.path.join(self.package_folder, "lib", "cmake", "metall_cxx_std.cmake"),
64+
CXX_STD_MODULE)
65+
66+
def package_info(self):
67+
self.cpp_info.set_property("cmake_file_name", "Metall")
68+
self.cpp_info.set_property("cmake_target_name", "Metall::Metall")
69+
70+
self.cpp_info.bindirs = []
71+
self.cpp_info.libdirs = []
72+
self.cpp_info.requires = ["boost::headers"]
73+
74+
if self.settings.os in ["Linux", "FreeBSD"]:
75+
self.cpp_info.system_libs.append("pthread")
76+
77+
if self.options.use_privateer:
78+
# metall/metall.hpp includes metall/ext/privateer.hpp under this
79+
# define, and the adapter is what aliases metall::manager to
80+
# manager_privateer. Every consumer in one binary must see it, or
81+
# two translation units name two different types under one symbol.
82+
self.cpp_info.defines.append("METALL_USE_PRIVATEER")
83+
self.cpp_info.requires.append("privateer::privateer")
84+
self.cpp_info.set_property(
85+
"cmake_build_modules", [os.path.join("lib", "cmake", "metall_cxx_std.cmake")])

0 commit comments

Comments
 (0)