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

[mold] Add latest version 1.4.1 #12703

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 7 additions & 0 deletions recipes/mold/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
3 changes: 3 additions & 0 deletions recipes/mold/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.4.1":
url: "https://github.com/rui314/mold/archive/refs/tags/v1.4.1.tar.gz"
sha256: "394036d299c50f936ff77ce9c6cf44a5b24bfcabf65ae7db9679f89c11a70b3f"
"1.3.1":
url: "https://github.com/rui314/mold/archive/refs/tags/v1.3.1.tar.gz"
sha256: "d436e2d4c1619a97aca0e28f26c4e79c0242d10ce24e829c1b43cfbdd196fd77"
55 changes: 46 additions & 9 deletions recipes/mold/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from conan.tools.scm import Version
from conan.tools import files
from conan.errors import ConanInvalidConfiguration
from conans import AutoToolsBuildEnvironment
from conans import AutoToolsBuildEnvironment, CMake

import os
import functools

required_conan_version = ">=1.47.0"

Expand All @@ -17,7 +19,7 @@ class MoldConan(ConanFile):

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

generators = "make"
generators = "make", "cmake", "cmake_find_package"

def validate(self):
if self.settings.build_type == "Debug":
Expand All @@ -41,11 +43,15 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
if Version(self.version) > "1.4.0":
self.copy("CMakeLists.txt")

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")
Expand All @@ -64,26 +70,57 @@ def _patch_sources(self):
files.replace_in_file(self, "source_subfolder/Makefile", "MOLD_LDFLAGS += -lmimalloc", "MOLD_LDFLAGS += -L{} -lmimalloc".format(
self.deps_cpp_info["mimalloc"].lib_paths[0]))

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["MOLD_USE_SYSTEM_MIMALLOC"] = True
cmake.definitions["MOLD_USE_SYSTEM_TBB"] = True
cmake.definitions["MOLD_USE_MOLD"] = False
cmake.configure()
return cmake

def build_requirements(self):
self.tool_requires("cmake/3.23.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")
self.requires("xxhash/0.8.1")

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'])
if Version(self.version) < "1.4":
self._patch_sources()
with files.chdir(self, self._source_subfolder):
autotools = AutoToolsBuildEnvironment(self)
autotools.make(target="mold", args=['SYSTEM_TBB=1', 'SYSTEM_MIMALLOC=1'])
else:
# Error out if ZLIB is not found, we want to be predictable
files.replace_in_file(self, "source_subfolder/CMakeLists.txt", "find_package(ZLIB QUIET)", "find_package(ZLIB REQUIRED)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move this to a proper helper function once we agree on the topics mentioned on the PR description

# Since we introduce a conan wrapper, CMAKE_SOURCE_DIR points to a dir above. mold_SOURD_DIR is an equivalent to the intended behavior
files.replace_in_file(self, "source_subfolder/CMakeLists.txt", "${CMAKE_SOURCE_DIR}/update-git-hash.py", "${mold_SOURCE_DIR}/update-git-hash.py")
# This is a bug upstream. You can't assing definitions to a target you don't build. It has been addressed on main but not released.
files.replace_in_file(self, "source_subfolder/CMakeLists.txt", "target_compile_definitions(mimalloc INTERFACE USE_SYSTEM_MIMALLOC)", "target_compile_definitions(mold PRIVATE USE_SYSTEM_MIMALLOC)")
# Use conan's xxhash
files.replace_in_file(self, "source_subfolder/CMakeLists.txt", "target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS})", "target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS})\nfind_package(xxHash REQUIRED)\ntarget_link_libraries(xxHash::xxhash)")
files.replace_in_file(self, "source_subfolder/mold.h", '#include "third-party/xxhash/xxhash.h"', '#include "xxhash.h"')

cmake = self._configure_cmake()
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)
if Version(self.version) < "1.4":
self.copy("mold", src=self._source_subfolder, dst="bin", keep_path=False)
else:
cmake = self._configure_cmake()
cmake.install()
files.rmdir(self, os.path.join(self.package_folder, "share"))

def package_id(self):
del self.info.settings.compiler
Expand Down
2 changes: 2 additions & 0 deletions recipes/mold/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"1.4.1":
folder: all
"1.3.1":
folder: all