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

antlr4-cppruntime: Upgrade to 4.11.0/4.11.1 #12902

Merged
merged 29 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
52b220e
antlr4-cppruntime: Upgrade to 4.11.1.
0xFireWolf Sep 11, 2022
4c5e97d
antlr4-cppruntime: No longer requires libuuid as of 4.11.
0xFireWolf Sep 11, 2022
b53e35b
antlr4-cppruntime: The minimum version of GCC is now 8.
0xFireWolf Sep 12, 2022
fadf33c
antlr4-cppruntime: Revert the minimum version of GCC to 7.
0xFireWolf Sep 12, 2022
4aa3e2d
antlr4-cppruntime: Add the patches that fix the compiler errors repor…
0xFireWolf Sep 12, 2022
66985e4
antlr4-cppruntime: Remove the trailing space at the end of each patch…
0xFireWolf Sep 12, 2022
5770555
antlr4-cppruntime: Fix the version key in conandata.yml.
0xFireWolf Sep 12, 2022
a73153d
antlr4-cppruntime: CI seems to be stuck.
0xFireWolf Sep 13, 2022
163445f
Prepare for Conan 2.0
uilianries Sep 22, 2022
98bdbc5
Fix the comparisons.
0xFireWolf Sep 22, 2022
b71ca7c
Retrigger the CI.
0xFireWolf Sep 22, 2022
fccf201
antlr4-cppruntime: Add patch files that drop the `libuuid` dependency…
0xFireWolf Sep 30, 2022
6ce28ef
antlr4-cppruntime: Register patch files for 4.9.3, 4.10 and 4.10.1.
0xFireWolf Sep 30, 2022
e3bbcf8
antlr4-cppruntime: Remove the requirement of `libuuid/1.0.3` and its …
0xFireWolf Sep 30, 2022
1824688
antlr4-cppruntime: Enable ARM builds on all supported versions.
0xFireWolf Sep 30, 2022
15015b3
antlr4-cppruntime: Remove `PkgConfigDeps` from the Conan file since `…
0xFireWolf Sep 30, 2022
e4bc403
antlr4-cppruntime: `_create_cmake_module_alias_targets` should not be…
0xFireWolf Oct 6, 2022
4ad831b
antlr4-cppruntime: Simplify the implementation and fix the typos in `…
0xFireWolf Oct 6, 2022
6424471
antlr4-cppruntime: Restore the CMake wrapper otherwise antlr's runtim…
0xFireWolf Oct 6, 2022
7873f98
antlr4-cppruntime: Use the new function `check_min_vs()`` to handle b…
0xFireWolf Oct 7, 2022
66c2489
antlr4-cppruntime: Remove the dead releases, 4.10.0 and 4.11.0.
0xFireWolf Oct 7, 2022
b3d2803
antlr4-cppruntime: Add the metadata for each patch for better record …
0xFireWolf Oct 7, 2022
88e1f23
antlr4-cppruntime: Remove `VirtualBuildEnv` since there is no more bu…
0xFireWolf Oct 7, 2022
507c818
antlr4-cppruntime: Fix the minimum version of the MSVC compiler; shou…
0xFireWolf Oct 8, 2022
c95429c
antlr4-cppruntime: Set `WITH_STATIC_CRT` in CMakeToolchain's cached v…
0xFireWolf Oct 7, 2022
c0d9336
antlr4-cppruntime: Remove the `CMakeLists.txt` wrapper with the new c…
0xFireWolf Oct 7, 2022
6eab2f1
antlr4-cppruntime: Simplify the implementation of `validate()`.
0xFireWolf Oct 8, 2022
9f95ef0
antlr4-cppruntime: Remove 4.10 and 4.11 from `config.yml`.
0xFireWolf Oct 8, 2022
d9cc6f5
antlr4-cppruntime: Remove `Visual Studio` and `msvc` from the C++17 d…
0xFireWolf Oct 9, 2022
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/antlr4-cppruntime/all/CMakeLists.txt

This file was deleted.

33 changes: 29 additions & 4 deletions recipes/antlr4-cppruntime/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@ sources:
"4.9.3":
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.9.3.tar.gz"
sha256: "efe4057d75ab48145d4683100fec7f77d7f87fa258707330cadd1f8e6f7eecae"
"4.10":
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.10.tar.gz"
sha256: "39b2604fc75fa77323bd7046f2fb750c818cf11fcce2cd6cca06b6697f60ffbb"
"4.10.1":
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.10.1.tar.gz"
sha256: "a320568b738e42735946bebc5d9d333170e14a251c5734e8b852ad1502efa8a2"
"4.11.1":
url: "https://github.com/antlr/antlr4/archive/refs/tags/4.11.1.tar.gz"
sha256: "81f87f03bb83b48da62e4fc8bfdaf447efb9fb3b7f19eb5cbc37f64e171218cf"
patches:
"4.9.3":
- patch_file: "patches/0001-update-cmakelist.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-update-DropLibuuid-4.9.3-1.patch"
0xFireWolf marked this conversation as resolved.
Show resolved Hide resolved
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#1) which is not used since 4.9."
patch_type: "backport"
patch_source: "https://github.com/antlr/antlr4/pull/3787"
- patch_file: "patches/0004-update-DropLibuuid-4.9.3-2.patch"
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#2) which is not used since 4.9."
patch_type: "backport"
patch_source: "https://github.com/antlr/antlr4/pull/3787"
"4.10.1":
- patch_file: "patches/0004-update-DropLibuuid-4.10.x-1.patch"
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#1) which is not used since 4.9."
patch_type: "backport"
patch_source: "https://github.com/antlr/antlr4/pull/3787"
- patch_file: "patches/0004-update-DropLibuuid-4.10.x-2.patch"
patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#2) which is not used since 4.9."
patch_type: "backport"
patch_source: "https://github.com/antlr/antlr4/pull/3787"
"4.11.1":
- patch_file: "patches/0002-update-FlatHashSet.patch"
patch_description: "Fix the compiler errors reported by GCC 7 due to the new type FlatHashSet introduced in 4.11."
patch_type: "portability"
patch_source: "https://github.com/antlr/antlr4/pull/3885"
- patch_file: "patches/0003-update-FlatHashMap.patch"
patch_description: "Fix the compiler errors reported by GCC 7 due to the new type FlatHashMap introduced in 4.11."
patch_type: "portability"
patch_source: "https://github.com/antlr/antlr4/pull/3885"
165 changes: 74 additions & 91 deletions recipes/antlr4-cppruntime/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
from conan import ConanFile
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, check_min_vs
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, copy, rm, rmdir, save
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
import os
import textwrap

required_conan_version = ">=1.45.0"
required_conan_version = ">=1.52.0"


class Antlr4CppRuntimeConan(ConanFile):
Expand All @@ -15,6 +18,7 @@ class Antlr4CppRuntimeConan(ConanFile):
topics = ("antlr", "parser", "runtime")
url = "https://github.com/conan-io/conan-center-index"
license = "BSD-3-Clause"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -23,133 +27,112 @@ class Antlr4CppRuntimeConan(ConanFile):
"shared": False,
"fPIC": True,
}
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "pkg_config"
short_paths = True

compiler_required_cpp17 = {
"Visual Studio": "16",
@property
def _minimum_cpp_standard(self):
# Antlr 4.9.3 requires C++11 while newer versions require C++17
return 17 if Version(self.version) >= "4.10" else 11

@property
def _minimum_compiler_versions_cpp17(self):
return {
"gcc": "7",
"clang": "5",
"apple-clang": "9.1"
}


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

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

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass

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

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

def validate(self):
if str(self.settings.arch).startswith("arm"):
raise ConanInvalidConfiguration("arm architectures are not supported")
# Need to deal with missing libuuid on Arm.
# So far ANTLR delivers macOS binary package.

compiler = self.settings.compiler
compiler_version = tools.Version(self.settings.compiler.version)
antlr_version = tools.Version(self.version)

if compiler == "Visual Studio" and compiler_version < "16":
raise ConanInvalidConfiguration("library claims C2668 'Ambiguous call to overloaded function'")
# Compilation of this library on version 15 claims C2668 Error.
# This could be Bogus error or malformed Antl4 libary.
# Version 16 compiles this code correctly.

if antlr_version >= "4.10":
# Antlr4 for 4.9.3 does not require C++17 - C++11 is enough.
# for newest version we need C++17 compatible compiler here

if self.settings.get_safe("compiler.cppstd"):
tools.check_min_cppstd(self, "17")

minimum_version = self.compiler_required_cpp17.get(str(self.settings.compiler), False)
if minimum_version:
if compiler_version < minimum_version:
raise ConanInvalidConfiguration("{} requires C++17, which your compiler does not support.".format(self.name))
else:
self.output.warn("{} requires C++17. Your compiler is unknown. Assuming it supports C++17.".format(self.name))

if is_msvc(self) and antlr_version == "4.10":
raise ConanInvalidConfiguration("{} Antlr4 4.10 version is broken on msvc - Use 4.10.1 or above.".format(self.name))

def build_requirements(self):
if self.settings.os in ("FreeBSD", "Linux"):
self.build_requires("pkgconf/1.7.4")
# Compilation of this library on version 15 claims C2668 Error.
# This could be Bogus error or malformed Antlr4 library.
# Guard: The minimum MSVC version is 16 or 1920 (which already supports C++17)
check_min_vs(self, "192")

# Check the minimum C++ standard
min_cppstd = self._minimum_cpp_standard
if self.info.settings.compiler.cppstd:
check_min_cppstd(self, min_cppstd)
# Check the minimum compiler version
if min_cppstd == 17:
self._check_minimum_compiler_version_cpp17()

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

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["ANTLR4_INSTALL"] = True
cmake.definitions["WITH_LIBCXX"] = self.settings.compiler.get_safe("libcxx") == "libc++"
cmake.definitions["ANTLR_BUILD_CPP_TESTS"] = False
def generate(self):
tc = CMakeToolchain(self)
tc.variables["ANTLR4_INSTALL"] = True
tc.variables["WITH_LIBCXX"] = self.settings.compiler.get_safe("libcxx") == "libc++"
tc.variables["ANTLR_BUILD_CPP_TESTS"] = False
if is_msvc(self):
cmake.definitions["WITH_STATIC_CRT"] = is_msvc_static_runtime(self)
cmake.definitions["WITH_DEMO"] = False
cmake.configure(build_folder=self._build_subfolder)
return cmake
tc.cache_variables["WITH_STATIC_CRT"] = is_msvc_static_runtime(self)
tc.variables["WITH_DEMO"] = False
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder="runtime/Cpp")
0xFireWolf marked this conversation as resolved.
Show resolved Hide resolved
cmake.build()

def package(self):
self.copy("LICENSE.txt", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE.txt", src=os.path.join(self.source_folder), dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
if self.options.shared:
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime-static.*")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.a")
rm(self, "*antlr4-runtime-static.*", os.path.join(self.package_folder, "lib"))
rm(self, "*antlr4-runtime.a", os.path.join(self.package_folder, "lib"))
else:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.dll")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "antlr4-runtime.lib")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.so*")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.dll*")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.*dylib")
tools.rmdir(os.path.join(self.package_folder, "share"))
rm(self, "*.dll", os.path.join(self.package_folder, "bin"))
rm(self, "antlr4-runtime.lib", os.path.join(self.package_folder, "lib"))
rm(self, "*antlr4-runtime.so*", os.path.join(self.package_folder, "lib"))
rm(self, "*antlr4-runtime.dll*", os.path.join(self.package_folder, "lib"))
rm(self, "*antlr4-runtime.*dylib", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "share"))

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

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

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent(f"""\
Expand All @@ -158,7 +141,7 @@ def _create_cmake_module_alias_targets(module_file, targets):
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""")
tools.save(module_file, content)
save(self, module_file, content)

@property
def _module_file_rel_path(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- runtime/Cpp/runtime/src/FlatHashSet.h
+++ runtime/Cpp/runtime/src/FlatHashSet.h
@@ -48,9 +48,9 @@
using FlatHashSet = absl::flat_hash_set<Key, Hash, Equal, Allocator>;
#else
template <typename Key,
- typename Hash = typename std::unordered_set<Key>::hasher,
- typename Equal = typename std::unordered_set<Key>::key_equal,
- typename Allocator = typename std::unordered_set<Key>::allocator_type>
+ typename Hash = std::hash<Key>,
+ typename Equal = std::equal_to<Key>,
+ typename Allocator = std::allocator<Key>>
using FlatHashSet = std::unordered_set<Key, Hash, Equal, Allocator>;
#endif

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- runtime/Cpp/runtime/src/FlatHashMap.h
+++ runtime/Cpp/runtime/src/FlatHashMap.h
@@ -48,9 +48,9 @@
using FlatHashMap = absl::flat_hash_map<Key, Value, Hash, Equal, Allocator>;
#else
template <typename Key, typename Value,
- typename Hash = typename std::unordered_map<Key, Value>::hasher,
- typename Equal = typename std::unordered_map<Key, Value>::key_equal,
- typename Allocator = typename std::unordered_map<Key, Value>::allocator_type>
+ typename Hash = std::hash<Key>,
+ typename Equal = std::equal_to<Key>,
+ typename Allocator = std::allocator<std::pair<const Key, Value>>>
using FlatHashMap = std::unordered_map<Key, Value, Hash, Equal, Allocator>;
#endif

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- runtime/Cpp/CMakeLists.txt
+++ runtime/Cpp/CMakeLists.txt
@@ -41,10 +41,6 @@
CMAKE_POLICY(SET CMP0054 OLD)
endif()

-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(UUID REQUIRED uuid)
0xFireWolf marked this conversation as resolved.
Show resolved Hide resolved
-endif()
if(APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- runtime/Cpp/runtime/CMakeLists.txt
+++ runtime/Cpp/runtime/CMakeLists.txt
@@ -69,10 +69,7 @@
gtest_discover_tests(antlr4_tests)
endif()

-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
- target_link_libraries(antlr4_static ${UUID_LIBRARIES})
-elseif(APPLE)
+if(APPLE)
target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- runtime/Cpp/CMakeLists.txt
+++ runtime/Cpp/CMakeLists.txt
@@ -39,10 +39,6 @@
CMAKE_POLICY(SET CMP0054 OLD)
endif()

-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(UUID REQUIRED uuid)
-endif()
if(APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- runtime/Cpp/runtime/CMakeLists.txt
+++ runtime/Cpp/runtime/CMakeLists.txt
@@ -75,10 +75,7 @@
endif()
endif()

-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
- target_link_libraries(antlr4_static ${UUID_LIBRARIES})
-elseif(APPLE)
+if(APPLE)
target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
endif()
5 changes: 1 addition & 4 deletions recipes/antlr4-cppruntime/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

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

find_package(antlr4-runtime REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand All @@ -12,4 +9,4 @@ if(TARGET antlr4_shared)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE antlr4_static)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
0xFireWolf marked this conversation as resolved.
Show resolved Hide resolved
Loading