Skip to content

Commit 5d4d607

Browse files
(#13913) [cppfront] new cppfront recipe (2nd attempt)
* new cppfront recipe * Update recipes/cppfront/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * Update recipes/cppfront/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * Update recipes/cppfront/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]>
1 parent fc725e6 commit 5d4d607

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

recipes/cppfront/all/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(cppfront CXX)
3+
4+
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/source/cppfront.cpp)
5+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
6+
7+
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
8+

recipes/cppfront/all/conandata.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sources:
2+
"cci.20221024":
3+
url: "https://github.com/hsutter/cppfront/archive/b1754dbd53a496a9104b43ecde6064c9980246bd.zip"
4+
sha256: "8668bddbd7fc06d4975c867521c005f898eca8f83f018e7c28b54dbcf9aa3ab9"
5+
"cci.20220924":
6+
url: "https://github.com/hsutter/cppfront/archive/98f6dd46957e100f813245241f183c8aedbcb36f.zip"
7+
sha256: "db51c1ac634d45c6047c7eec5c29993ff215443edadf334370f53d09a11cc5b1"

recipes/cppfront/all/conanfile.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from conan import ConanFile
2+
3+
from conan.errors import ConanInvalidConfiguration
4+
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
5+
from conan.tools.build import check_min_cppstd
6+
from conan.tools.files import copy, get
7+
from conan.tools.microsoft import check_min_vs, is_msvc
8+
9+
import os
10+
11+
required_conan_version = ">=1.47.0"
12+
13+
class CppfrontConan(ConanFile):
14+
name = "cppfront"
15+
description = "Cppfront is a experimental compiler from a potential C++ 'syntax 2' (Cpp2) to today's 'syntax 1' (Cpp1)"
16+
topics = ("cpp2")
17+
url = "https://github.com/conan-io/conan-center-index"
18+
homepage = "https://github.com/hsutter/cppfront"
19+
license = "CC-BY-NC-ND-4.0"
20+
settings = "os", "arch", "compiler", "build_type"
21+
22+
@property
23+
def _minimum_cpp_standard(self):
24+
return 20
25+
26+
@property
27+
def _compilers_minimum_version(self):
28+
return {"gcc": "11",
29+
"Visual Studio": "16.9",
30+
"clang": "12",
31+
"apple-clang": "13",
32+
}
33+
34+
def layout(self):
35+
cmake_layout(self, src_folder="src")
36+
37+
def export_sources(self):
38+
copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))
39+
40+
def source(self):
41+
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)
42+
43+
def validate(self):
44+
if self.info.settings.compiler.cppstd:
45+
check_min_cppstd(self, self._minimum_cpp_standard)
46+
47+
def _lazy_lt_semver(v1, v2):
48+
lv1 = [int(v) for v in v1.split(".")]
49+
lv2 = [int(v) for v in v2.split(".")]
50+
min_length = min(len(lv1), len(lv2))
51+
return lv1[:min_length] < lv2[:min_length]
52+
53+
check_min_vs(self, "192.9")
54+
if not is_msvc(self):
55+
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
56+
if not minimum_version:
57+
self.output.warn(f"{self.name} {self.version} requires C++20. Your compiler is unknown. Assuming it supports C++20.")
58+
elif _lazy_lt_semver(str(self.settings.compiler.version), minimum_version):
59+
raise ConanInvalidConfiguration(f"{self.name} {self.version} requires C++20, which your compiler does not support.")
60+
if self.info.settings.compiler == "clang" and str(self.info.settings.compiler.version) in ("13", "14"):
61+
raise ConanInvalidConfiguration(f"{self.ref} currently does not work with Clang {self.info.settings.compiler.version} on CCI, it enters in an infinite build loop (smells like a compiler bug). Contributions are welcomed!")
62+
63+
def generate(self):
64+
tc = CMakeToolchain(self)
65+
tc.generate()
66+
67+
def build(self):
68+
cmake = CMake(self)
69+
cmake.configure()
70+
cmake.build()
71+
72+
def package(self):
73+
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
74+
copy(self, "cppfront*", src=self.source_folder, dst=os.path.join(self.package_folder, "bin"))
75+
copy(self, pattern="*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
76+
77+
cmake = CMake(self)
78+
cmake.install()
79+
80+
@staticmethod
81+
def _chmod_plus_x(filename):
82+
if os.name == "posix":
83+
os.chmod(filename, os.stat(filename).st_mode | 0o111)
84+
85+
def package_info(self):
86+
bin_path = os.path.join(self.package_folder, "bin")
87+
self.output.info(f"Appending PATH environment variable: {bin_path}")
88+
self.env_info.PATH.append(bin_path)
89+
90+
bin_ext = ".exe" if self.settings.os == "Windows" else ""
91+
cppfront_bin = os.path.join(self.package_folder, "bin", "cppfront{}".format(bin_ext)).replace("\\", "/")
92+
93+
# CppFront environment variable is used by a lot of scripts as a way to override a hard-coded embedded m4 path
94+
self.output.info("Setting CppFront environment variable: {}".format(cppfront_bin))
95+
self.env_info.cppfront = cppfront_bin
96+
97+
self.cpp_info.frameworkdirs = []
98+
self.cpp_info.includedirs = []
99+
self.cpp_info.libdirs = []
100+
self.cpp_info.resdirs = []
101+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from conan import ConanFile
2+
from conan.tools.files import copy
3+
from conan.tools.build import can_run
4+
from conan.tools.layout import basic_layout
5+
import os
6+
7+
8+
class TestPackageConan(ConanFile):
9+
settings = "os", "arch", "compiler", "build_type"
10+
generators = "VirtualBuildEnv"
11+
test_type = "explicit"
12+
13+
def layout(self):
14+
basic_layout(self)
15+
16+
def build_requirements(self):
17+
self.tool_requires(self.tested_reference_str)
18+
19+
def build(self):
20+
if can_run(self):
21+
copy(self, "pure2-hello.cpp2", src=self.recipe_folder, dst=self.build_folder)
22+
self.run("cppfront {}".format(os.path.join(self.build_folder, "pure2-hello.cpp2")), env="conanbuild")
23+
24+
def test(self):
25+
if can_run(self):
26+
self.run("cppfront -h", env="conanbuild")
27+
assert os.path.isfile(os.path.join(self.build_folder, "pure2-hello.cpp"))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
main: () -> int = {
2+
std::cout << "Hello " << name() << "\n";
3+
}
4+
5+
name: () -> std::string = {
6+
s: std::string = "world";
7+
decorate(s);
8+
return s;
9+
}
10+
11+
decorate: (inout s: std::string) = {
12+
s = "[" + s + "]";
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from conans import ConanFile, tools
2+
import os
3+
import shutil
4+
5+
class TestPackageV1Conan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
8+
@property
9+
def _cppfront_input_path(self):
10+
return os.path.join(self.build_folder, "pure2-hello.cpp2")
11+
12+
def build(self):
13+
if not tools.cross_building(self):
14+
shutil.copy2(src=os.path.join(self.source_folder, "..", "test_package", "pure2-hello.cpp2"), dst=os.path.join(self.build_folder, "pure2-hello.cpp2"))
15+
self.run("cppfront {}".format(os.path.join(self.build_folder, "pure2-hello.cpp2")), run_environment=True)
16+
17+
def test(self):
18+
if not tools.cross_building(self):
19+
self.run("cppfront -h", run_environment=True)
20+
assert os.path.isfile(os.path.join(self.build_folder, "pure2-hello.cpp"))

recipes/cppfront/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
versions:
2+
"cci.20221024":
3+
folder: all
4+
"cci.20220924":
5+
folder: all

0 commit comments

Comments
 (0)