Skip to content

Commit 8e8536d

Browse files
(#12902) antlr4-cppruntime: Upgrade to 4.11.0/4.11.1
* antlr4-cppruntime: Upgrade to 4.11.1. * antlr4-cppruntime: No longer requires libuuid as of 4.11. * antlr4-cppruntime: The minimum version of GCC is now 8. * antlr4-cppruntime: Revert the minimum version of GCC to 7. * antlr4-cppruntime: Add the patches that fix the compiler errors reported by GCC 7. * antlr4-cppruntime: Remove the trailing space at the end of each patch file. * antlr4-cppruntime: Fix the version key in conandata.yml. * antlr4-cppruntime: CI seems to be stuck. * Prepare for Conan 2.0 Signed-off-by: Uilian Ries <[email protected]> * Fix the comparisons. Co-authored-by: Uilian Ries <[email protected]> * Retrigger the CI. * antlr4-cppruntime: Add patch files that drop the `libuuid` dependency from 4.9.3, 4.10 and 4.10.1. * antlr4-cppruntime: Register patch files for 4.9.3, 4.10 and 4.10.1. * antlr4-cppruntime: Remove the requirement of `libuuid/1.0.3` and its build requirements from the Conan file. * antlr4-cppruntime: Enable ARM builds on all supported versions. * antlr4-cppruntime: Remove `PkgConfigDeps` from the Conan file since `libuuid` has been dropped. * antlr4-cppruntime: `_create_cmake_module_alias_targets` should not be a static function. * antlr4-cppruntime: Simplify the implementation and fix the typos in `validate()`. * antlr4-cppruntime: Restore the CMake wrapper otherwise antlr's runtime library (< 4.11) is always linked against the static MSVC runtime. * antlr4-cppruntime: Use the new function `check_min_vs()`` to handle both `Visual Studio` and `msvc` easily. * antlr4-cppruntime: Remove the dead releases, 4.10.0 and 4.11.0. * antlr4-cppruntime: Add the metadata for each patch for better record keeping. * antlr4-cppruntime: Remove `VirtualBuildEnv` since there is no more build requirement. * antlr4-cppruntime: Fix the minimum version of the MSVC compiler; should be `192` instead of `1920`. * antlr4-cppruntime: Set `WITH_STATIC_CRT` in CMakeToolchain's cached variables. * antlr4-cppruntime: Remove the `CMakeLists.txt` wrapper with the new cache variable set in the toolchain. * antlr4-cppruntime: Simplify the implementation of `validate()`. * antlr4-cppruntime: Remove 4.10 and 4.11 from `config.yml`. * antlr4-cppruntime: Remove `Visual Studio` and `msvc` from the C++17 dictionary. The first `check_min_vs()` call already ensures that MSVC supports C++17. Signed-off-by: Uilian Ries <[email protected]> Co-authored-by: Uilian Ries <[email protected]>
1 parent 8445a7b commit 8e8536d

14 files changed

+237
-114
lines changed

recipes/antlr4-cppruntime/all/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

recipes/antlr4-cppruntime/all/conandata.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,38 @@ sources:
22
"4.9.3":
33
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.9.3.tar.gz"
44
sha256: "efe4057d75ab48145d4683100fec7f77d7f87fa258707330cadd1f8e6f7eecae"
5-
"4.10":
6-
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.10.tar.gz"
7-
sha256: "39b2604fc75fa77323bd7046f2fb750c818cf11fcce2cd6cca06b6697f60ffbb"
85
"4.10.1":
96
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.10.1.tar.gz"
107
sha256: "a320568b738e42735946bebc5d9d333170e14a251c5734e8b852ad1502efa8a2"
8+
"4.11.1":
9+
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.11.1.tar.gz"
10+
sha256: "81f87f03bb83b48da62e4fc8bfdaf447efb9fb3b7f19eb5cbc37f64e171218cf"
1111
patches:
1212
"4.9.3":
1313
- patch_file: "patches/0001-update-cmakelist.patch"
14-
base_path: "source_subfolder"
14+
- patch_file: "patches/0004-update-DropLibuuid-4.9.3-1.patch"
15+
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#1) which is not used since 4.9."
16+
patch_type: "backport"
17+
patch_source: "https://github.com/antlr/antlr4/pull/3787"
18+
- patch_file: "patches/0004-update-DropLibuuid-4.9.3-2.patch"
19+
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#2) which is not used since 4.9."
20+
patch_type: "backport"
21+
patch_source: "https://github.com/antlr/antlr4/pull/3787"
22+
"4.10.1":
23+
- patch_file: "patches/0004-update-DropLibuuid-4.10.x-1.patch"
24+
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#1) which is not used since 4.9."
25+
patch_type: "backport"
26+
patch_source: "https://github.com/antlr/antlr4/pull/3787"
27+
- patch_file: "patches/0004-update-DropLibuuid-4.10.x-2.patch"
28+
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#2) which is not used since 4.9."
29+
patch_type: "backport"
30+
patch_source: "https://github.com/antlr/antlr4/pull/3787"
31+
"4.11.1":
32+
- patch_file: "patches/0002-update-FlatHashSet.patch"
33+
patch_description: "Fix the compiler errors reported by GCC 7 due to the new type FlatHashSet introduced in 4.11."
34+
patch_type: "portability"
35+
patch_source: "https://github.com/antlr/antlr4/pull/3885"
36+
- patch_file: "patches/0003-update-FlatHashMap.patch"
37+
patch_description: "Fix the compiler errors reported by GCC 7 due to the new type FlatHashMap introduced in 4.11."
38+
patch_type: "portability"
39+
patch_source: "https://github.com/antlr/antlr4/pull/3885"

recipes/antlr4-cppruntime/all/conanfile.py

Lines changed: 74 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
2-
from conans import ConanFile, CMake, tools
3-
from conans.errors import ConanInvalidConfiguration
4-
import functools
1+
from conan import ConanFile
2+
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, check_min_vs
3+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
4+
from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, copy, rm, rmdir, save
5+
from conan.tools.build import check_min_cppstd
6+
from conan.tools.scm import Version
7+
from conan.errors import ConanInvalidConfiguration
58
import os
69
import textwrap
710

8-
required_conan_version = ">=1.45.0"
11+
required_conan_version = ">=1.52.0"
912

1013

1114
class Antlr4CppRuntimeConan(ConanFile):
@@ -15,6 +18,7 @@ class Antlr4CppRuntimeConan(ConanFile):
1518
topics = ("antlr", "parser", "runtime")
1619
url = "https://github.com/conan-io/conan-center-index"
1720
license = "BSD-3-Clause"
21+
settings = "os", "compiler", "build_type", "arch"
1822
options = {
1923
"shared": [True, False],
2024
"fPIC": [True, False],
@@ -23,133 +27,112 @@ class Antlr4CppRuntimeConan(ConanFile):
2327
"shared": False,
2428
"fPIC": True,
2529
}
26-
settings = "os", "compiler", "build_type", "arch"
27-
generators = "cmake", "pkg_config"
2830
short_paths = True
2931

30-
compiler_required_cpp17 = {
31-
"Visual Studio": "16",
32+
@property
33+
def _minimum_cpp_standard(self):
34+
# Antlr 4.9.3 requires C++11 while newer versions require C++17
35+
return 17 if Version(self.version) >= "4.10" else 11
36+
37+
@property
38+
def _minimum_compiler_versions_cpp17(self):
39+
return {
3240
"gcc": "7",
3341
"clang": "5",
3442
"apple-clang": "9.1"
35-
}
36-
37-
38-
@property
39-
def _source_subfolder(self):
40-
return "source_subfolder"
43+
}
4144

42-
@property
43-
def _build_subfolder(self):
44-
return "build_subfolder"
45+
def _check_minimum_compiler_version_cpp17(self):
46+
compiler = self.info.settings.compiler
47+
min_compiler_version = self._minimum_compiler_versions_cpp17.get(str(compiler), False)
48+
if min_compiler_version and Version(compiler.version) < min_compiler_version:
49+
raise ConanInvalidConfiguration(f"{self.ref} requires C++17, which your compiler does not support.")
4550

4651
def export_sources(self):
47-
self.copy("CMakeLists.txt")
48-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
49-
self.copy(patch["patch_file"])
52+
export_conandata_patches(self)
5053

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

5558
def configure(self):
5659
if self.options.shared:
57-
del self.options.fPIC
60+
try:
61+
del self.options.fPIC
62+
except Exception:
63+
pass
64+
65+
def layout(self):
66+
cmake_layout(self, src_folder="src")
5867

5968
def requirements(self):
69+
# As of 4.11, antlr4-cppruntime no longer requires libuuid.
70+
# Reference: [C++] Remove libuuid dependency (https://github.com/antlr/antlr4/pull/3787)
71+
# Note that the above PR points that libuuid can be removed from 4.9.3, 4.10 and 4.10.1 as well.
72+
# We have patched the CMakeLists.txt to drop the dependency on libuuid from aforementioned antlr versions.
6073
self.requires("utfcpp/3.2.1")
61-
if self.settings.os in ("FreeBSD", "Linux"):
62-
self.requires("libuuid/1.0.3")
6374

6475
def validate(self):
65-
if str(self.settings.arch).startswith("arm"):
66-
raise ConanInvalidConfiguration("arm architectures are not supported")
67-
# Need to deal with missing libuuid on Arm.
68-
# So far ANTLR delivers macOS binary package.
69-
70-
compiler = self.settings.compiler
71-
compiler_version = tools.Version(self.settings.compiler.version)
72-
antlr_version = tools.Version(self.version)
73-
74-
if compiler == "Visual Studio" and compiler_version < "16":
75-
raise ConanInvalidConfiguration("library claims C2668 'Ambiguous call to overloaded function'")
76-
# Compilation of this library on version 15 claims C2668 Error.
77-
# This could be Bogus error or malformed Antl4 libary.
78-
# Version 16 compiles this code correctly.
79-
80-
if antlr_version >= "4.10":
81-
# Antlr4 for 4.9.3 does not require C++17 - C++11 is enough.
82-
# for newest version we need C++17 compatible compiler here
83-
84-
if self.settings.get_safe("compiler.cppstd"):
85-
tools.check_min_cppstd(self, "17")
86-
87-
minimum_version = self.compiler_required_cpp17.get(str(self.settings.compiler), False)
88-
if minimum_version:
89-
if compiler_version < minimum_version:
90-
raise ConanInvalidConfiguration("{} requires C++17, which your compiler does not support.".format(self.name))
91-
else:
92-
self.output.warn("{} requires C++17. Your compiler is unknown. Assuming it supports C++17.".format(self.name))
93-
94-
if is_msvc(self) and antlr_version == "4.10":
95-
raise ConanInvalidConfiguration("{} Antlr4 4.10 version is broken on msvc - Use 4.10.1 or above.".format(self.name))
96-
97-
def build_requirements(self):
98-
if self.settings.os in ("FreeBSD", "Linux"):
99-
self.build_requires("pkgconf/1.7.4")
76+
# Compilation of this library on version 15 claims C2668 Error.
77+
# This could be Bogus error or malformed Antlr4 library.
78+
# Guard: The minimum MSVC version is 16 or 1920 (which already supports C++17)
79+
check_min_vs(self, "192")
80+
81+
# Check the minimum C++ standard
82+
min_cppstd = self._minimum_cpp_standard
83+
if self.info.settings.compiler.cppstd:
84+
check_min_cppstd(self, min_cppstd)
85+
# Check the minimum compiler version
86+
if min_cppstd == 17:
87+
self._check_minimum_compiler_version_cpp17()
10088

10189
def source(self):
102-
tools.get(**self.conan_data["sources"][self.version],
103-
destination=self._source_subfolder, strip_root=True)
90+
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)
10491

105-
def _patch_sources(self):
106-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
107-
tools.patch(**patch)
108-
109-
@functools.lru_cache(1)
110-
def _configure_cmake(self):
111-
cmake = CMake(self)
112-
cmake.definitions["ANTLR4_INSTALL"] = True
113-
cmake.definitions["WITH_LIBCXX"] = self.settings.compiler.get_safe("libcxx") == "libc++"
114-
cmake.definitions["ANTLR_BUILD_CPP_TESTS"] = False
92+
def generate(self):
93+
tc = CMakeToolchain(self)
94+
tc.variables["ANTLR4_INSTALL"] = True
95+
tc.variables["WITH_LIBCXX"] = self.settings.compiler.get_safe("libcxx") == "libc++"
96+
tc.variables["ANTLR_BUILD_CPP_TESTS"] = False
11597
if is_msvc(self):
116-
cmake.definitions["WITH_STATIC_CRT"] = is_msvc_static_runtime(self)
117-
cmake.definitions["WITH_DEMO"] = False
118-
cmake.configure(build_folder=self._build_subfolder)
119-
return cmake
98+
tc.cache_variables["WITH_STATIC_CRT"] = is_msvc_static_runtime(self)
99+
tc.variables["WITH_DEMO"] = False
100+
tc.generate()
101+
tc = CMakeDeps(self)
102+
tc.generate()
120103

121104
def build(self):
122-
self._patch_sources()
123-
cmake = self._configure_cmake()
105+
apply_conandata_patches(self)
106+
cmake = CMake(self)
107+
cmake.configure(build_script_folder="runtime/Cpp")
124108
cmake.build()
125109

126110
def package(self):
127-
self.copy("LICENSE.txt", src=self._source_subfolder, dst="licenses")
128-
cmake = self._configure_cmake()
111+
copy(self, "LICENSE.txt", src=os.path.join(self.source_folder), dst=os.path.join(self.package_folder, "licenses"))
112+
cmake = CMake(self)
129113
cmake.install()
130114
if self.options.shared:
131-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime-static.*")
132-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.a")
115+
rm(self, "*antlr4-runtime-static.*", os.path.join(self.package_folder, "lib"))
116+
rm(self, "*antlr4-runtime.a", os.path.join(self.package_folder, "lib"))
133117
else:
134-
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.dll")
135-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "antlr4-runtime.lib")
136-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.so*")
137-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.dll*")
138-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.*dylib")
139-
tools.rmdir(os.path.join(self.package_folder, "share"))
118+
rm(self, "*.dll", os.path.join(self.package_folder, "bin"))
119+
rm(self, "antlr4-runtime.lib", os.path.join(self.package_folder, "lib"))
120+
rm(self, "*antlr4-runtime.so*", os.path.join(self.package_folder, "lib"))
121+
rm(self, "*antlr4-runtime.dll*", os.path.join(self.package_folder, "lib"))
122+
rm(self, "*antlr4-runtime.*dylib", os.path.join(self.package_folder, "lib"))
123+
rmdir(self, os.path.join(self.package_folder, "share"))
140124

141125
# FIXME: this also removes lib/cmake/antlr4-generator
142126
# This cmake config script is needed to provide the cmake function `antlr4_generate`
143-
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
127+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
144128

145129
# TODO: to remove in conan v2 once cmake_find_package* generatores removed
146130
self._create_cmake_module_alias_targets(
147131
os.path.join(self.package_folder, self._module_file_rel_path),
148132
{"antlr4_shared" if self.options.shared else "antlr4_static": "antlr4-cppruntime::antlr4-cppruntime"}
149133
)
150134

151-
@staticmethod
152-
def _create_cmake_module_alias_targets(module_file, targets):
135+
def _create_cmake_module_alias_targets(self, module_file, targets):
153136
content = ""
154137
for alias, aliased in targets.items():
155138
content += textwrap.dedent(f"""\
@@ -158,7 +141,7 @@ def _create_cmake_module_alias_targets(module_file, targets):
158141
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
159142
endif()
160143
""")
161-
tools.save(module_file, content)
144+
save(self, module_file, content)
162145

163146
@property
164147
def _module_file_rel_path(self):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--- runtime/Cpp/runtime/src/FlatHashSet.h
2+
+++ runtime/Cpp/runtime/src/FlatHashSet.h
3+
@@ -48,9 +48,9 @@
4+
using FlatHashSet = absl::flat_hash_set<Key, Hash, Equal, Allocator>;
5+
#else
6+
template <typename Key,
7+
- typename Hash = typename std::unordered_set<Key>::hasher,
8+
- typename Equal = typename std::unordered_set<Key>::key_equal,
9+
- typename Allocator = typename std::unordered_set<Key>::allocator_type>
10+
+ typename Hash = std::hash<Key>,
11+
+ typename Equal = std::equal_to<Key>,
12+
+ typename Allocator = std::allocator<Key>>
13+
using FlatHashSet = std::unordered_set<Key, Hash, Equal, Allocator>;
14+
#endif
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--- runtime/Cpp/runtime/src/FlatHashMap.h
2+
+++ runtime/Cpp/runtime/src/FlatHashMap.h
3+
@@ -48,9 +48,9 @@
4+
using FlatHashMap = absl::flat_hash_map<Key, Value, Hash, Equal, Allocator>;
5+
#else
6+
template <typename Key, typename Value,
7+
- typename Hash = typename std::unordered_map<Key, Value>::hasher,
8+
- typename Equal = typename std::unordered_map<Key, Value>::key_equal,
9+
- typename Allocator = typename std::unordered_map<Key, Value>::allocator_type>
10+
+ typename Hash = std::hash<Key>,
11+
+ typename Equal = std::equal_to<Key>,
12+
+ typename Allocator = std::allocator<std::pair<const Key, Value>>>
13+
using FlatHashMap = std::unordered_map<Key, Value, Hash, Equal, Allocator>;
14+
#endif
15+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- runtime/Cpp/CMakeLists.txt
2+
+++ runtime/Cpp/CMakeLists.txt
3+
@@ -41,10 +41,6 @@
4+
CMAKE_POLICY(SET CMP0054 OLD)
5+
endif()
6+
7+
-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
8+
- find_package(PkgConfig REQUIRED)
9+
- pkg_check_modules(UUID REQUIRED uuid)
10+
-endif()
11+
if(APPLE)
12+
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
13+
endif()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--- runtime/Cpp/runtime/CMakeLists.txt
2+
+++ runtime/Cpp/runtime/CMakeLists.txt
3+
@@ -69,10 +69,7 @@
4+
gtest_discover_tests(antlr4_tests)
5+
endif()
6+
7+
-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
8+
- target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
9+
- target_link_libraries(antlr4_static ${UUID_LIBRARIES})
10+
-elseif(APPLE)
11+
+if(APPLE)
12+
target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
13+
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
14+
endif()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- runtime/Cpp/CMakeLists.txt
2+
+++ runtime/Cpp/CMakeLists.txt
3+
@@ -39,10 +39,6 @@
4+
CMAKE_POLICY(SET CMP0054 OLD)
5+
endif()
6+
7+
-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
8+
- find_package(PkgConfig REQUIRED)
9+
- pkg_check_modules(UUID REQUIRED uuid)
10+
-endif()
11+
if(APPLE)
12+
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
13+
endif()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--- runtime/Cpp/runtime/CMakeLists.txt
2+
+++ runtime/Cpp/runtime/CMakeLists.txt
3+
@@ -75,10 +75,7 @@
4+
endif()
5+
endif()
6+
7+
-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
8+
- target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
9+
- target_link_libraries(antlr4_static ${UUID_LIBRARIES})
10+
-elseif(APPLE)
11+
+if(APPLE)
12+
target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
13+
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
14+
endif()
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(test_package CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
6-
74
find_package(antlr4-runtime REQUIRED CONFIG)
85

96
add_executable(${PROJECT_NAME} test_package.cpp)
@@ -12,4 +9,4 @@ if(TARGET antlr4_shared)
129
else()
1310
target_link_libraries(${PROJECT_NAME} PRIVATE antlr4_static)
1411
endif()
15-
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
12+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

0 commit comments

Comments
 (0)