Skip to content

Commit c662616

Browse files
AndreyMlashkintogeprince-chrismcfriendlyanonuilianries
authored
(#11536) implement mold/1.3.1 recipe
* implement mold recipe * fix linter errors * linter fixes * linter fixes * make CI lint happy * add test recipe * add zlib requirement * use only gcc version higher than 8 * override LD variable * use zlib from conan * add forgotten patch * make linter happy * increase gcc version requirement * hardcode zlib patch * remove patches * add openssl dependency * remove options * increase clang version requirements * forbid apple-clang with version less 11 * disable macos arm builds * point LD to mold * Apply suggestions from code review Co-authored-by: toge <[email protected]> * implement review notes * Update recipes/mold/all/test_package/conanfile.py Co-authored-by: Chris Mc <[email protected]> * disable clang 12 * add libc to package id * remove package ID * drop gcc 10 support * Apply suggestions from code review Co-authored-by: friendlyanon <[email protected]> * use xxhash from conan * substitute includes to the right place * Update recipes/mold/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * Apply suggestions from code review Co-authored-by: Uilian Ries <[email protected]> * Update recipes/mold/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * use compiler for package id * Update recipes/mold/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * substitute conan mimaloc and tbb as system libs * prohibit debug builds * Apply suggestions from code review Co-authored-by: Chris Mc <[email protected]> * vorbid libstdc for mold * add check for compiler to exclude apple-clang * use std=c++2a for apple clang * increase minimal apple-clang requirement * Update recipes/mold/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * remove zlib * Update recipes/mold/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> Co-authored-by: toge <[email protected]> Co-authored-by: Chris Mc <[email protected]> Co-authored-by: friendlyanon <[email protected]> Co-authored-by: Uilian Ries <[email protected]>
1 parent f474eb6 commit c662616

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

recipes/mold/all/conandata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
"1.3.1":
3+
url: "https://github.com/rui314/mold/archive/refs/tags/v1.3.1.tar.gz"
4+
sha256: "d436e2d4c1619a97aca0e28f26c4e79c0242d10ce24e829c1b43cfbdd196fd77"

recipes/mold/all/conanfile.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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"])
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from conans import ConanFile, tools
3+
from conan.tools.build import cross_building
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "build_type", "compiler"
7+
8+
def test(self):
9+
if not cross_building(self):
10+
self.run("mold -v", run_environment=True)

recipes/mold/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"1.3.1":
3+
folder: all

0 commit comments

Comments
 (0)