Skip to content

Commit

Permalink
(#12881) Add mold 142 as build system changed from makefiles to cmake
Browse files Browse the repository at this point in the history
* add version 1.4.2

* add with_mimalloc option

* add validate method

* add cmake as build requrements

* use minmalloc from conan

* use minmalloc from conan

* use tbb from conan

* don't use cmake as requirement for old mold

* hotfix

* add cmake_find_package generator

* add CMakeDeps

* don't use old conans import

* Update recipes/mold/1.4.x/conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* package licenses

* make artifacts match settings

* correct package method for mold 1.3.1

* package mold binary differently for gcc and clang

* exclude windows builds

* delete unneeded CMakeLists

* Apply suggestions from code review

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* import VirtualBuildEnv

* add a newline

* Apply suggestions from code review

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* delete package id also for 1.3.1 version

* use build_requirements instead of requirements in test

* Apply suggestions from code review

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/mold/1.4.x/test_package/conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* make mold test recipe work again

* add version 1.5.1

* rename folder

* add test_v1_package

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
3 people authored Oct 6, 2022
1 parent 9cd0fcb commit 22d8d24
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 59 deletions.
4 changes: 4 additions & 0 deletions recipes/mold/1.3.1/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.3.1":
url: "https://github.com/rui314/mold/archive/refs/tags/v1.3.1.tar.gz"
sha256: "d436e2d4c1619a97aca0e28f26c4e79c0242d10ce24e829c1b43cfbdd196fd77"
104 changes: 104 additions & 0 deletions recipes/mold/1.3.1/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from conan import ConanFile
from conan.tools.scm import Version
from conan.tools import files
from conan.tools.files import copy
from conan.errors import ConanInvalidConfiguration
from conans import AutoToolsBuildEnvironment
import os

required_conan_version = ">=1.47.0"

class MoldConan(ConanFile):
name = "mold"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/rui314/mold/"
license = "AGPL-3.0"
description = ("mold is a faster drop-in replacement for existing Unix linkers. It is several times faster than the LLVM lld linker")
topics = ("mold", "ld", "linkage", "compilation")

settings = "os", "arch", "compiler", "build_type"

generators = "make"

def validate(self):
if self.settings.build_type == "Debug":
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')
if self.settings.compiler in ["gcc", "clang", "intel-cc"] and self.settings.compiler.libcxx != "libstdc++11":
raise ConanInvalidConfiguration('Mold can only be built with libstdc++11; specify mold:compiler.libcxx=libstdc++11 in your build profile')
if self.settings.os == "Windows":
raise ConanInvalidConfiguration(f'{self.name} can not be built on {self.settings.os}.')
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "10":
raise ConanInvalidConfiguration("GCC version 10 or higher required")
if (self.settings.compiler == "clang" or self.settings.compiler == "apple-clang") and Version(self.settings.compiler.version) < "12":
raise ConanInvalidConfiguration("Clang version 12 or higher required")
if self.settings.compiler == "apple-clang" and "armv8" == self.settings.arch :
raise ConanInvalidConfiguration(f'{self.name} is still not supported by Mac M1.')

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

@property
def _build_subfolder(self):
return "build_subfolder"

def _get_include_path(self, dependency):
include_path = self.deps_cpp_info[dependency].rootpath
include_path = os.path.join(include_path, "include")
return include_path

def _patch_sources(self):
if self.settings.compiler == "apple-clang" or (self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "11"):
files.replace_in_file(self, "source_subfolder/Makefile", "-std=c++20", "-std=c++2a")

files.replace_in_file(self, "source_subfolder/Makefile", "-Ithird-party/xxhash ", "-I{} -I{} -I{} -I{} -I{}".format(
self._get_include_path("zlib"),
self._get_include_path("openssl"),
self._get_include_path("xxhash"),
self._get_include_path("mimalloc"),
self._get_include_path("onetbb")
))

files.replace_in_file(self, "source_subfolder/Makefile", "MOLD_LDFLAGS += -ltbb", "MOLD_LDFLAGS += -L{} -ltbb".format(
self.deps_cpp_info["onetbb"].lib_paths[0]))

files.replace_in_file(self, "source_subfolder/Makefile", "MOLD_LDFLAGS += -lmimalloc", "MOLD_LDFLAGS += -L{} -lmimalloc".format(
self.deps_cpp_info["mimalloc"].lib_paths[0]))

def requirements(self):
self.requires("zlib/1.2.12")
self.requires("openssl/1.1.1q")
self.requires("xxhash/0.8.1")
self.requires("onetbb/2021.3.0")
self.requires("mimalloc/2.0.6")

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

def build(self):
self._patch_sources()
with files.chdir(self, self._source_subfolder):
autotools = AutoToolsBuildEnvironment(self)
autotools.make(target="mold", args=['SYSTEM_TBB=1', 'SYSTEM_MIMALLOC=1'])

def package(self):
copy(self, "LICENSE", src=self._source_subfolder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "mold", src="bin", dst=os.path.join(self.package_folder, "bin"), keep_path=False)
copy(self, "mold", src=self._source_subfolder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)

def package_id(self):
del self.info.settings.compiler

def package_info(self):
bindir = os.path.join(self.package_folder, "bin")
mold_location = os.path.join(bindir, "bindir")

self.output.info('Appending PATH environment variable: {}'.format(bindir))
self.env_info.PATH.append(bindir)
self.env_info.LD = mold_location
self.buildenv_info.prepend_path("MOLD_ROOT", bindir)
self.cpp_info.includedirs = []

if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(["m", "pthread", "dl"])
9 changes: 9 additions & 0 deletions recipes/mold/1.3.1/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from conan import ConanFile
from conan.tools.build import cross_building

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

def test(self):
if not cross_building(self):
self.run("mold -v", run_environment=True)
9 changes: 6 additions & 3 deletions recipes/mold/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.3.1":
url: "https://github.com/rui314/mold/archive/refs/tags/v1.3.1.tar.gz"
sha256: "d436e2d4c1619a97aca0e28f26c4e79c0242d10ce24e829c1b43cfbdd196fd77"
"1.4.2":
url: "https://github.com/rui314/mold/archive/refs/tags/v1.4.2.tar.gz"
sha256: "47e6c48d20f49e5b47dfb8197dd9ffcb11a8833d614f7a03bd29741c658a69cd"
"1.5.1":
url: "https://github.com/rui314/mold/archive/refs/tags/v1.5.1.tar.gz"
sha256: "ec94aa74758f1bc199a732af95c6304ec98292b87f2f4548ce8436a7c5b054a1"
95 changes: 46 additions & 49 deletions recipes/mold/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from conan import ConanFile
from conan.tools.scm import Version
from conan.tools import files
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.files import copy, get, rmdir
from conan.errors import ConanInvalidConfiguration
from conans import AutoToolsBuildEnvironment
import os

required_conan_version = ">=1.47.0"
from conan.tools.scm import Version
from conan.tools.env import VirtualBuildEnv

class MoldConan(ConanFile):
name = "mold"
Expand All @@ -16,8 +15,12 @@ class MoldConan(ConanFile):
topics = ("mold", "ld", "linkage", "compilation")

settings = "os", "arch", "compiler", "build_type"

generators = "make"
options = {
"with_mimalloc": [True, False],
}
default_options = {
"with_mimalloc": False,
}

def validate(self):
if self.settings.build_type == "Debug":
Expand All @@ -28,66 +31,57 @@ def validate(self):
raise ConanInvalidConfiguration(f'{self.name} can not be built on {self.settings.os}.')
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "10":
raise ConanInvalidConfiguration("GCC version 10 or higher required")
if (self.settings.compiler == "clang" or self.settings.compiler == "apple-clang") and Version(self.settings.compiler.version) < "12":
if self.settings.compiler in ('clang', 'apple-clang') and Version(self.settings.compiler.version) < "12":
raise ConanInvalidConfiguration("Clang version 12 or higher required")
if self.settings.compiler == "apple-clang" and "armv8" == self.settings.arch :
raise ConanInvalidConfiguration(f'{self.name} is still not supported by Mac M1.')

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

@property
def _build_subfolder(self):
return "build_subfolder"

def _get_include_path(self, dependency):
include_path = self.deps_cpp_info[dependency].rootpath
include_path = os.path.join(include_path, "include")
return include_path

def _patch_sources(self):
if self.settings.compiler == "apple-clang" or (self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "11"):
files.replace_in_file(self, "source_subfolder/Makefile", "-std=c++20", "-std=c++2a")

files.replace_in_file(self, "source_subfolder/Makefile", "-Ithird-party/xxhash ", "-I{} -I{} -I{} -I{} -I{}".format(
self._get_include_path("zlib"),
self._get_include_path("openssl"),
self._get_include_path("xxhash"),
self._get_include_path("mimalloc"),
self._get_include_path("onetbb")
))
def layout(self):
cmake_layout(self, src_folder="src")

files.replace_in_file(self, "source_subfolder/Makefile", "MOLD_LDFLAGS += -ltbb", "MOLD_LDFLAGS += -L{} -ltbb".format(
self.deps_cpp_info["onetbb"].lib_paths[0]))
def package_id(self):
del self.info.settings.compiler

files.replace_in_file(self, "source_subfolder/Makefile", "MOLD_LDFLAGS += -lmimalloc", "MOLD_LDFLAGS += -L{} -lmimalloc".format(
self.deps_cpp_info["mimalloc"].lib_paths[0]))
def build_requirements(self):
self.tool_requires("cmake/3.24.1")

def requirements(self):
self.requires("zlib/1.2.12")
self.requires("openssl/1.1.1q")
self.requires("xxhash/0.8.1")
self.requires("onetbb/2021.3.0")
self.requires("mimalloc/2.0.6")
if self.options.with_mimalloc:
self.requires("mimalloc/2.0.6")

def source(self):
files.get(self, **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 generate(self):
tc = CMakeToolchain(self)
tc.variables["MOLD_USE_MIMALLOC"] = self.options.with_mimalloc
tc.variables["MOLD_USE_SYSTEM_MIMALLOC"] = True
tc.variables["MOLD_USE_SYSTEM_TBB"] = True
tc.generate()

cd = CMakeDeps(self)
cd.generate()
tc = VirtualBuildEnv(self)
tc.generate()

def build(self):
self._patch_sources()
with files.chdir(self, self._source_subfolder):
autotools = AutoToolsBuildEnvironment(self)
autotools.make(target="mold", args=['SYSTEM_TBB=1', 'SYSTEM_MIMALLOC=1'])
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
self.copy("mold", src=self._source_subfolder, dst="bin", keep_path=False)

def package_id(self):
del self.info.settings.compiler
cmake = CMake(self)
cmake.install()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))

rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
bindir = os.path.join(self.package_folder, "bin")
mold_location = os.path.join(bindir, "bindir")
Expand All @@ -97,6 +91,9 @@ def package_info(self):
self.env_info.LD = mold_location
self.buildenv_info.prepend_path("MOLD_ROOT", bindir)
self.cpp_info.includedirs = []
self.cpp_info.libdirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.resdirs = []

if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(["m", "pthread", "dl"])
20 changes: 13 additions & 7 deletions recipes/mold/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import os
from conans import ConanFile, tools
from conan.tools.build import cross_building
from conan import ConanFile
from conan.tools.build import can_run

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

class MoldTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "VirtualBuildEnv"
test_type = "explicit"

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def test(self):
if not cross_building(self):
self.run("mold -v", run_environment=True)
if can_run(self):
self.run("mold -v")

10 changes: 10 additions & 0 deletions recipes/mold/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os
from conans import ConanFile, tools
from conan.tools.build import cross_building

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

def test(self):
if not cross_building(self):
self.run("mold -v", run_environment=True)
4 changes: 4 additions & 0 deletions recipes/mold/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
versions:
"1.3.1":
folder: 1.3.1
"1.4.2":
folder: all
"1.5.1":
folder: all

0 comments on commit 22d8d24

Please sign in to comment.