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

scc: migrate to Conan v2 #18715

Merged
merged 17 commits into from
Jul 4, 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
7 changes: 0 additions & 7 deletions recipes/scc/all/CMakeLists.txt

This file was deleted.

15 changes: 12 additions & 3 deletions recipes/scc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
sources:
"2022.08":
url: "https://github.com/Minres/SystemC-Components/releases/download/2022.08/systemc-components.tar.gz"
sha256: "825dfc38e7b00df34330f01ba38f5913e1a88c5002344e433b972faf0e6c4501"
"2023.06":
url: "https://github.com/Minres/SystemC-Components/releases/download/2023.06/SCC-2023.06-full.tar.gz"
sha256: "6d1a842f474daa512030d61526e83182f9289b977a3a7cb88ed151050c33c4e9"
patches:
"2023.06":
- patch_file: "patches/2023.06-fix-conan-targets.patch"
patch_description: "add find_package()-s and disable automatic Conan setup"
patch_type: "conan"
- patch_file: "patches/2023.06-add-fmt-10-support.patch"
patch_description: "fix incompatibility with fmt 10.x and newer"
patch_type: "portability"
patch_source: "https://github.com/Minres/SystemC-Components/pull/51"
173 changes: 125 additions & 48 deletions recipes/scc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,166 @@
import os

from conan import ConanFile
from conan.tools.scm import Version
from conan.tools.files import get
from conans import tools, CMake
from conan.errors import ConanInvalidConfiguration
import functools
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout, CMakeDeps
from conan.tools.files import copy, get, export_conandata_patches, apply_conandata_patches, replace_in_file, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"

required_conan_version = ">=1.50.0"

class SystemcComponentsConan(ConanFile):
name = "scc"
description = """A light weight productivity library for SystemC and TLM 2.0"""
homepage = "https://minres.github.io/SystemC-Components"
url = "https://github.com/conan-io/conan-center-index"
description = "A light-weight productivity library for SystemC and TLM 2.0"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://minres.github.io/SystemC-Components"
topics = ("systemc", "modeling", "tlm", "scc")
settings = "os", "compiler", "build_type", "arch"

package_type = "static-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"enable_phase_callbacks": [True, False],
"enable_phase_callbacks_tracing": [True, False]
"enable_phase_callbacks_tracing": [True, False],
}
default_options = {
"fPIC": True,
"enable_phase_callbacks": False,
"enable_phase_callbacks_tracing": False
"enable_phase_callbacks_tracing": False,
}
generators = "cmake"

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

# no exports_sources attribute, but export_sources(self) method instead
# this allows finer grain exportation of patches per version
def export_sources(self):
self.copy("CMakeLists.txt")
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC


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

def requirements(self):
# https://github.com/Minres/SystemC-Components/blob/2023.06/src/sysc/scc/perf_estimator.h#L20
self.requires("boost/1.83.0", transitive_headers=True, transitive_libs=True)
# https://github.com/Minres/SystemC-Components/blob/2023.06/src/sysc/scc/trace/vcd_trace.hh#L28
self.requires("fmt/10.2.1", transitive_headers=True, transitive_libs=True)
# https://github.com/Minres/SystemC-Components/blob/2023.06/src/common/util/lz4_streambuf.h#L13
self.requires("lz4/1.9.4", transitive_headers=True, transitive_libs=True)
self.requires("rapidjson/cci.20220822")
self.requires("spdlog/1.13.0")
# https://github.com/Minres/SystemC-Components/blob/2023.06/src/sysc/tlm/scc/lwtr/tlm2_lwtr.h
self.requires("systemc-cci/1.0.0", transitive_headers=True, transitive_libs=True)
self.requires("systemc/2.3.4", transitive_headers=True, transitive_libs=True)
# https://github.com/Minres/SystemC-Components/blob/2023.06/src/sysc/scc/trace/gz_writer.hh#L18
self.requires("zlib/[>=1.2.11 <2]", transitive_headers=True, transitive_libs=True)
self.requires("yaml-cpp/0.8.0")

def validate(self):
if is_apple_os(self):
raise ConanInvalidConfiguration(f"{self.name} is not supported on {self.settings.os}.")
if is_msvc(self):
# Fails with
# src\sysc\tlm\scc\tlm_mm.h(116,114): error C2259: 'tlm::scc::tlm_gp_mm_t<16,false>': cannot instantiate abstract class
# (compiling source file '../../../src/src/sysc/tlm/scc/lwtr/tlm2_lwtr.cpp')
# src\sysc\tlm\scc\tlm_mm.h(116,48):
# see declaration of 'tlm::scc::tlm_gp_mm_t<16,false>'
# src\sysc\tlm\scc\tlm_mm.h(116,114):
# due to following members:
# src\sysc\tlm\scc\tlm_mm.h(116,114):
# 'void tlm::tlm_extension<tlm::scc::tlm_gp_mm>::copy_from(const tlm::tlm_extension_base &)': is abstract
# systemc-2.3.4\p\include\tlm_core\tlm_2\tlm_generic_payload\tlm_gp.h(78,18):
# see declaration of 'tlm::tlm_extension<tlm::scc::tlm_gp_mm>::copy_from'
# and
# src\sysc\tlm\scc\tlm_mm.h(31,20): error C2061: syntax error: identifier '__attribute__'
raise ConanInvalidConfiguration(f"{self.ref} recipe is not supported on MSVC. Contributions are welcome!")
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.settings.os == "Macos":
raise ConanInvalidConfiguration(f"{self.name} is not suppported on {self.settings.os}.")
check_min_cppstd(self, 11)
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "7":
raise ConanInvalidConfiguration("GCC < version 7 is not supported")

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

def build_requirements(self):
self.tool_requires("cmake/3.24.0")
self.tool_requires("cmake/[>=3.24 <4]")

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["SC_WITH_PHASE_CALLBACKS"] = self.options.enable_phase_callbacks
cmake.definitions["SC_WITH_PHASE_CALLBACK_TRACING"] = self.options.enable_phase_callbacks_tracing
cmake.definitions["BUILD_SCC_DOCUMENTATION"] = False
cmake.definitions["SCC_LIB_ONLY"] = True
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["SC_WITH_PHASE_CALLBACKS"] = self.options.enable_phase_callbacks
tc.cache_variables["SC_WITH_PHASE_CALLBACK_TRACING"] = self.options.enable_phase_callbacks_tracing
tc.cache_variables["BUILD_SCC_DOCUMENTATION"] = False
tc.cache_variables["SCC_LIB_ONLY"] = True
tc.cache_variables["ENABLE_CONAN"] = False
if self.settings.os == "Windows":
cmake.definitions["SCC_LIMIT_TRACE_TYPE_LIST"] = True
cmake.configure(build_folder=self._build_subfolder)
return cmake
tc.cache_variables["SCC_LIMIT_TRACE_TYPE_LIST"] = True
# Used at https://github.com/Minres/SystemC-Components/blob/2023.06/src/common/util/pool_allocator.h#L110
# but is not set anywhere
tc.preprocessor_definitions["_GLIBCXX_USE_NOEXCEPT"] = "noexcept"
tc.generate()

deps = CMakeDeps(self)
deps.set_property("systemc", "cmake_file_name", "SystemC")
deps.set_property("systemc-cci", "cmake_target_name", "systemc-cci::systemc-cci")
deps.set_property("yaml-cpp", "cmake_target_name", "yaml-cpp::yaml-cpp")
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "third_party", "axi_chi", "CMakeLists.txt"),
" STATIC", "")

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

def package(self):
self.copy(pattern="LICENSE", dst="licenses",
src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE",
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, "share"))

def package_info(self):
self.cpp_info.components["busses"].libs = ["busses"]
self.cpp_info.components["scc-sysc"].libs = ["scc-sysc"]
self.cpp_info.components["scc-sysc"].requires = [
"fstapi",
"lwtr",
"scc-util",
"scv-tr",
"boost::date_time",
"fmt::fmt",
"lz4::lz4",
"rapidjson::rapidjson",
"spdlog::spdlog",
"systemc-cci::systemc-cci",
"systemc::systemc",
"yaml-cpp::yaml-cpp",
"zlib::zlib",
]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["scc-sysc"].system_libs = ["pthread", "dl"]

self.cpp_info.components["busses"].libs = ["busses"]
self.cpp_info.components["busses"].requires = ["tlm-interfaces", "scc-sysc"]

self.cpp_info.components["fstapi"].libs = ["fstapi"]
self.cpp_info.components["fstapi"].requires = ["zlib::zlib", "lz4::lz4"]

self.cpp_info.components["lwtr"].libs = ["lwtr"]
self.cpp_info.components["lwtr"].requires = ["zlib::zlib", "lz4::lz4", "systemc::systemc", "fmt::fmt"]

self.cpp_info.components["scc-util"].libs = ["scc-util"]
self.cpp_info.components["scc-util"].requires = ["lz4::lz4"]

self.cpp_info.components["scv-tr"].libs = ["scv-tr"]
self.cpp_info.components["scv-tr"].requires = ["fmt::fmt", "systemc::systemc"]

self.cpp_info.components["tlm-interfaces"].libs = ["tlm-interfaces"]
self.cpp_info.components["tlm-interfaces"].requires = ["scc-sysc", "systemc::systemc"]
11 changes: 11 additions & 0 deletions recipes/scc/all/patches/2023.06-add-fmt-10-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- src/sysc/scc/trace/vcd_trace.hh
+++ src/sysc/scc/trace/vcd_trace.hh
@@ -53,7 +53,7 @@

template<typename T>
inline void vcdEmitValueChangeReal(FPTR os, std::string const& handle, unsigned bits, T val){
- auto buf = fmt::format("r{:.16g} {}\n", val, handle);
+ auto buf = fmt::format("r{:.16g} {}\n", static_cast<double>(val), handle);
Copy link
Member

Choose a reason for hiding this comment

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

FWRITE(buf.c_str(), 1, buf.size(), os);
}

17 changes: 17 additions & 0 deletions recipes/scc/all/patches/2023.06-fix-conan-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -24,5 +24,13 @@
include(Common)

-if(CMAKE_PROJECT_NAME STREQUAL "scc")
+find_package(SystemC REQUIRED CONFIG)
+find_package(systemc-cci REQUIRED CONFIG)
+find_package(fmt REQUIRED CONFIG)
+find_package(spdlog REQUIRED CONFIG)
+find_package(Boost REQUIRED CONFIG)
+find_package(yaml-cpp REQUIRED CONFIG)
+find_package(lz4 REQUIRED CONFIG)
+if(TRUE)
+elseif(CMAKE_PROJECT_NAME STREQUAL "scc")
message(STATUS "Building SCC in standalone mode")
include(GNUInstallDirs)
5 changes: 1 addition & 4 deletions recipes/scc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

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

find_package(scc REQUIRED CONFIG)

add_executable(${PROJECT_NAME} example.cpp)
Expand Down
26 changes: 17 additions & 9 deletions recipes/scc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os

from conans import ConanFile, CMake
from conan.tools.build import cross_building

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

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 not 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")
4 changes: 3 additions & 1 deletion recipes/scc/all/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <util/io-redirector.h>
#include <util/ities.h>
#include <iostream>

int main(int argc, char* argv[]) {
int main() {
util::IoRedirector::get();
std::cout << "scc loaded successfully. Mini test: util::ilog2(32) = " << util::ilog2(32) << std::endl;
return 0;
}
4 changes: 2 additions & 2 deletions recipes/scc/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"2022.08":
folder: "all"
"2023.06":
folder: all
Loading