Skip to content

Add opengrm/1.3.8 #11098

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

Merged
merged 31 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9fb2e3a
Add opengrm
npuichigo Jun 9, 2022
da23b25
Update conanfile.py
npuichigo Jul 22, 2022
25d0d51
Update conanfile.py
npuichigo Jul 22, 2022
fc86155
Update conanfile.py
npuichigo Jul 22, 2022
1239383
Update conanfile.py
npuichigo Jul 22, 2022
b80be75
Update conanfile.py
npuichigo Jul 22, 2022
4132e88
Update conanfile.py
npuichigo Jul 22, 2022
49782a2
Update conanfile.py
npuichigo Jul 22, 2022
eb92567
Update conanfile.py
npuichigo Jul 22, 2022
509c7bc
Update conanfile.py
npuichigo Jul 22, 2022
3d6590d
Update conanfile.py
npuichigo Jul 22, 2022
cc56742
Update conanfile.py
npuichigo Jul 22, 2022
99035bb
Update conanfile.py
npuichigo Jul 22, 2022
774c5e3
Update conanfile.py
npuichigo Jul 22, 2022
c15a380
Update conanfile.py
npuichigo Jul 22, 2022
c8daad2
Update conanfile.py
npuichigo Jul 22, 2022
6d4ca0e
Update conanfile.py
npuichigo Jul 22, 2022
f77d041
Update conanfile.py
npuichigo Jul 23, 2022
44d74df
Update conanfile.py
npuichigo Jul 23, 2022
348dc20
Update conanfile.py
npuichigo Jul 23, 2022
4ea28a2
Update conanfile.py
npuichigo Jul 23, 2022
222ddc0
Update conanfile.py
npuichigo Jul 23, 2022
0c8c2eb
Update conanfile.py
npuichigo Jul 23, 2022
03d585c
Update conanfile.py
npuichigo Jul 23, 2022
5e8c9be
Update conanfile.py
npuichigo Jul 23, 2022
d37af09
Update conanfile.py
npuichigo Jul 23, 2022
f5237c1
Update conanfile.py
npuichigo Jul 23, 2022
c256612
Update conanfile.py
npuichigo Jul 23, 2022
c47b07b
Update conanfile.py
npuichigo Jul 23, 2022
35ae00d
Update conanfile.py
npuichigo Jul 23, 2022
54de3b7
Update conanfile.py
npuichigo Jul 23, 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
4 changes: 4 additions & 0 deletions recipes/opengrm/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.3.8":
sha256: e21c449798854f7270bb5ac723f6a8d292e149fc6bbe24fd9f345c85aabc7cd4
url: https://www.opengrm.org/twiki/pub/GRM/ThraxDownload/thrax-1.3.8.tar.gz
131 changes: 131 additions & 0 deletions recipes/opengrm/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import conan
from conan.errors import ConanInvalidConfiguration
from conan.tools.gnu import AutotoolsDeps, AutotoolsToolchain, Autotools
from conans.tools import Version, check_min_cppstd, remove_files_by_mask

import functools
import os
from pathlib import Path

required_conan_version = ">=1.49.0"


class OpenGrmConan(conan.ConanFile):
name = "opengrm"
description = "The OpenGrm Thrax tools compile grammars expressed as regular expressions and context-dependent rewrite rules into weighted finite-state transducers."
topics = ("fst", "wfst", "opengrm", "thrax")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.opengrm.org/twiki/bin/view/GRM/Thrax"
license = "Apache-2.0"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_bin": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_bin": True,
}

def requirements(self):
self.requires("openfst/1.8.2")

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

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options["openfst"].enable_grm = True

def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration("OpenGrm is only supported on linux")

if not self.options["openfst"].enable_grm:
raise ConanInvalidConfiguration("OpenGrm requires OpenFst with enable_grm enabled.")

compilers = {
"gcc": "8",
"clang": "7",
}

if self.settings.compiler.cppstd:
check_min_cppstd(self, 17)
minimum_compiler = compilers.get(str(self.settings.compiler))
if minimum_compiler:
if Version(self.settings.compiler.version) < minimum_compiler:
raise ConanInvalidConfiguration(f"{self.name} requires c++17, which your compiler does not support.")
else:
self.output.warn(f"{self.name} requires c++17, but this compiler is unknown to this recipe. Assuming your compiler supports c++17.")

# Check stdlib ABI compatibility
if self.settings.compiler == "gcc" and self.settings.compiler.libcxx != "libstdc++11":
raise ConanInvalidConfiguration(f'Using {self.name} with GCC requires "compiler.libcxx=libstdc++11"')
if self.settings.compiler == "clang" and self.settings.compiler.libcxx not in ["libstdc++11", "libc++"]:
raise ConanInvalidConfiguration(f'Using {self.name} with Clang requires either "compiler.libcxx=libstdc++11"'
' or "compiler.libcxx=libc++"')

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

@staticmethod
def _yes_no(v):
return "yes" if v else "no"

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

def generate(self):
tc = AutotoolsDeps(self)
tc.generate()
tc = AutotoolsToolchain(self)
tc.configure_args.extend([
f"--enable-bin={self._yes_no(self.options.enable_bin)}",
"LIBS=-lpthread",
])
tc.make_args.append("-j1")
tc.generate()

def build(self):
self._patch_sources()
autotools = Autotools(self)
autotools.configure(build_script_folder=self._source_subfolder)
autotools.make()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
autotools = Autotools(self)
autotools.install()

conan.tools.files.rmdir(self, Path(self.package_folder) / "share")
remove_files_by_mask(Path(self.package_folder) / "lib", "*.la")

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "OpenGrm")
self.cpp_info.set_property("cmake_target_name", "OpenGrm::OpenGrm")
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.names["cmake_find_package"] = "OpenGrm"
self.cpp_info.names["cmake_find_package_multi"] = "OpenGrm"

self.cpp_info.libs = ["thrax"]

if self.options.enable_bin:
bindir = os.path.join(self.package_folder, "bin")
self.output.info(f"Appending PATH environment var: {bindir}")
self.env_info.PATH.append(bindir)

self.cpp_info.system_libs = ["pthread", "dl", "m"]
12 changes: 12 additions & 0 deletions recipes/opengrm/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

set(CMAKE_CXX_STANDARD 17)

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

find_package(OpenGrm REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} OpenGrm::OpenGrm)
18 changes: 18 additions & 0 deletions recipes/opengrm/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pylint: skip-file
import os
from conans import ConanFile, CMake, tools


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

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
6 changes: 6 additions & 0 deletions recipes/opengrm/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <thrax/grm-manager.h>

int main() {
thrax::GrmManager grm_manager;
return 0;
}
3 changes: 3 additions & 0 deletions recipes/opengrm/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.3.8":
folder: "all"