bootstrap-toolchain/packages/musl/conanfile.py

116 lines
3.5 KiB
Python

# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
from pathlib import Path
from conan import ConanFile
from conan.tools.gnu import AutotoolsToolchain, Autotools
from conan.tools.files import get
from conf.utils import copy_tree, get_version
class Musl(ConanFile):
name = "musl"
settings = "os", "arch", "build_type", "compiler"
version = get_version("musl")
options = {
"stage": [1, 2],
}
default_options = {"stage": 1}
def build_requirements(self):
self.requires(
f"kernel-headers/{get_version('kernel')}@{self.user}/{self.channel}"
)
if self.options.stage == 1:
self.tool_requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}"
)
else:
self.tool_requires(
f"clang/{get_version('llvm')}@{self.user}/{self.channel}"
)
@property
def target(self):
return os.environ["TARGET"]
def source(self):
get(
self,
f"https://git.musl-libc.org/cgit/musl/snapshot/musl-{self.version}.tar.gz",
)
def generate(self):
tc = AutotoolsToolchain(self, prefix=f"{self.package_folder}/")
env = tc.environment()
clang = "clang-bootstrap" if self.options.stage == 1 else "clang"
clang_root = Path(self.dependencies.build[clang].package_folder)
tc.update_configure_args(
{
"--enable-shared": "",
"--enable-static": "",
"--disable-wrapper": "",
"--enable-optimize": "",
}
)
libcc = (
clang_root
/ "lib"
/ "clang"
/ get_version("llvm_major")
/ "lib"
/ self.target
/ "libclang_rt.builtins.a"
)
env.define(
"LIBCC",
str(libcc),
)
env.define("CC", "clang")
env.prepend_path("PATH", str(clang_root / "bin"))
# We will strip the debug data later
tc.extra_cflags = ["-g", f"--target={self.target}"]
tc.generate(env)
def build(self):
autotools = Autotools(self)
autotools.configure(
build_script_folder=f"{self.source_folder}/musl-{self.version}/"
)
autotools.make()
autotools.make(target="install")
ld_so = Path(self.package_folder) / "lib" / "ld-musl-x86_64.so.1"
ld_so.symlink_to("libc.so")
kernel_inc_dir = Path(self.dependencies[f"kernel-headers"].package_folder)
target_inc_dir = Path(self.package_folder) / "include"
for include_dir in (kernel_inc_dir / "include").iterdir():
self.output.info(f"Copying kernel headers: {include_dir.name}")
copy_tree(str(include_dir), str(target_inc_dir / include_dir.name))