bootstrap-toolchain/packages/zlib/conanfile.py

79 lines
2.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
from pathlib import Path
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conf.base.zlib import ZlibBase
from conf.utils import get_version, with_musl_toolchain, copy_dependency_tree
class Zlib(ZlibBase):
name = "zlib"
options = {
"stage": [1, 2],
}
default_options = {"stage": 1}
def build_requirements(self):
if self.options.stage == 1:
self.requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}",
visible=False,
)
else:
self.requires(
f"clang/{get_version('llvm')}@{self.user}/{self.channel}",
visible=False,
)
self.requires(f"musl/{get_version('musl')}@{self.user}/{self.channel}")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
self.buildenv_info.prepend_path("PATH", f"{self.build_folder}/sysroot")
with_musl_toolchain(self, tc, sysroot=f"{self.build_folder}/sysroot")
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def create_sysroot(self):
sysroot = Path(self.build_folder) / "sysroot"
sysroot.mkdir()
clang = "clang-bootstrap" if self.options.stage == 1 else "clang"
copy_dependency_tree(self, [clang, "musl"], sysroot)
def build(self):
self.create_sysroot()
sysroot = f"{self.build_folder}/sysroot"
cmake = CMake(self)
cmake.configure(
{
"BUILD_SHARED_LIBS": False,
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_SYSROOT": sysroot,
"CMAKE_FIND_ROOT_PATH": sysroot,
},
build_script_folder=f"zlib-{self.version}",
)
self.run("ninja zlibstatic")