|
| 1 | +from conans import ConanFile, tools, AutoToolsBuildEnvironment |
| 2 | +from conans.errors import ConanInvalidConfiguration |
| 3 | +import os |
| 4 | + |
| 5 | +required_conan_version = ">=1.45.0" |
| 6 | + |
| 7 | +class MoldConan(ConanFile): |
| 8 | + name = "mold" |
| 9 | + url = "https://github.com/conan-io/conan-center-index" |
| 10 | + homepage = "https://github.com/rui314/mold/" |
| 11 | + license = "AGPL-3.0" |
| 12 | + description = ("mold is a faster drop-in replacement for existing Unix linkers. It is several times faster than the LLVM lld linker") |
| 13 | + topics = ("mold", "ld", "linkage", "compilation") |
| 14 | + |
| 15 | + settings = "os", "arch", "compiler", "build_type" |
| 16 | + |
| 17 | + generators = "make" |
| 18 | + |
| 19 | + def validate(self): |
| 20 | + if self.settings.build_type == "Debug": |
| 21 | + raise ConanInvalidConfiguration('Mold is a build tool, specify mold:build_type=Release in your build profile, see https://github.com/conan-io/conan-center-index/pull/11536#issuecomment-1195607330') |
| 22 | + if self.settings.compiler in ["gcc", "clang", "intel-cc"] and self.settings.compiler.libcxx != "libstdc++11": |
| 23 | + raise ConanInvalidConfiguration('Mold can only be built with libstdc++11; specify mold:compiler.libcxx=libstdc++11 in your build profile') |
| 24 | + if self.settings.os == "Windows": |
| 25 | + raise ConanInvalidConfiguration(f'{self.name} can not be built on {self.settings.os}.') |
| 26 | + if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "11": |
| 27 | + raise ConanInvalidConfiguration("GCC version 11 or higher required") |
| 28 | + if (self.settings.compiler == "clang" or self.settings.compiler == "apple-clang") and tools.Version(self.settings.compiler.version) < "12": |
| 29 | + raise ConanInvalidConfiguration("Clang version 12 or higher required") |
| 30 | + if self.settings.compiler == "apple-clang" and "armv8" == self.settings.arch : |
| 31 | + raise ConanInvalidConfiguration(f'{self.name} is still not supported by Mac M1.') |
| 32 | + |
| 33 | + @property |
| 34 | + def _source_subfolder(self): |
| 35 | + return "source_subfolder" |
| 36 | + |
| 37 | + @property |
| 38 | + def _build_subfolder(self): |
| 39 | + return "build_subfolder" |
| 40 | + |
| 41 | + def _get_include_path(self, dependency): |
| 42 | + include_path = self.deps_cpp_info[dependency].rootpath |
| 43 | + include_path = os.path.join(include_path, "include") |
| 44 | + return include_path |
| 45 | + |
| 46 | + def _patch_sources(self): |
| 47 | + if self.settings.compiler == "apple-clang": |
| 48 | + tools.replace_in_file("source_subfolder/Makefile", "-std=c++20", "-std=c++2a") |
| 49 | + |
| 50 | + tools.replace_in_file("source_subfolder/Makefile", "-Ithird-party/xxhash ", "-I{} -I{} -I{} -I{} -I{}".format( |
| 51 | + self._get_include_path("zlib"), |
| 52 | + self._get_include_path("openssl"), |
| 53 | + self._get_include_path("xxhash"), |
| 54 | + self._get_include_path("mimalloc"), |
| 55 | + self._get_include_path("onetbb") |
| 56 | + )) |
| 57 | + |
| 58 | + tools.replace_in_file("source_subfolder/Makefile", "MOLD_LDFLAGS += -ltbb", "MOLD_LDFLAGS += -L{} -ltbb".format( |
| 59 | + self.deps_cpp_info["onetbb"].lib_paths[0])) |
| 60 | + |
| 61 | + tools.replace_in_file("source_subfolder/Makefile", "MOLD_LDFLAGS += -lmimalloc", "MOLD_LDFLAGS += -L{} -lmimalloc".format( |
| 62 | + self.deps_cpp_info["mimalloc"].lib_paths[0])) |
| 63 | + |
| 64 | + def requirements(self): |
| 65 | + self.requires("zlib/1.2.12") |
| 66 | + self.requires("openssl/1.1.1q") |
| 67 | + self.requires("xxhash/0.8.1") |
| 68 | + self.requires("onetbb/2021.3.0") |
| 69 | + self.requires("mimalloc/2.0.6") |
| 70 | + |
| 71 | + def source(self): |
| 72 | + tools.get(**self.conan_data["sources"][self.version], |
| 73 | + destination=self._source_subfolder, strip_root=True) |
| 74 | + |
| 75 | + def build(self): |
| 76 | + self._patch_sources() |
| 77 | + with tools.chdir(self._source_subfolder): |
| 78 | + autotools = AutoToolsBuildEnvironment(self) |
| 79 | + autotools.make(target="mold", args=['SYSTEM_TBB=1', 'SYSTEM_MIMALLOC=1']) |
| 80 | + |
| 81 | + def package(self): |
| 82 | + self.copy("LICENSE", src=self._source_subfolder, dst="licenses") |
| 83 | + self.copy("mold", src=self._source_subfolder, dst="bin", keep_path=False) |
| 84 | + |
| 85 | + def package_id(self): |
| 86 | + del self.info.settings.compiler |
| 87 | + |
| 88 | + def package_info(self): |
| 89 | + bindir = os.path.join(self.package_folder, "bin") |
| 90 | + mold_location = os.path.join(bindir, "bindir") |
| 91 | + |
| 92 | + self.output.info('Appending PATH environment variable: {}'.format(bindir)) |
| 93 | + self.env_info.PATH.append(bindir) |
| 94 | + self.env_info.LD = mold_location |
| 95 | + self.buildenv_info.prepend_path("MOLD_ROOT", bindir) |
| 96 | + self.cpp_info.includedirs = [] |
| 97 | + |
| 98 | + if self.settings.os == "Linux": |
| 99 | + self.cpp_info.system_libs.extend(["m", "pthread", "dl"]) |
0 commit comments