bootstrap-toolchain/packages/zstd/conanfile.py

86 lines
2.7 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 import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.base.zstd import ZstdBase
from conf.utils import get_version, with_musl_toolchain, copy_dependency_tree
class Zstd(ZstdBase):
name = "zstd"
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
with_musl_toolchain(self, tc, "TARGET")
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(
{
"CMAKE_C_COMPILER": self.settings.compiler,
"CMAKE_CXX_COMPILER": self.settings.compiler,
"BUILD_SHARED_LIBS": False,
"ZSTD_BUILD_STATIC": True,
"ZSTD_BUILD_SHARED": False,
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_SYSROOT": sysroot,
"CMAKE_FIND_ROOT_PATH": sysroot,
},
build_script_folder=f"zstd-{self.version}/build/cmake/",
)
cmake.build()
cmake.install()