Add the sysroot package for stage1

This commit is contained in:
Sameer Rahmani 2023-04-16 17:46:04 +01:00
parent 32c98619ec
commit f6afdd76fe
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
5 changed files with 156 additions and 99 deletions

View File

@ -1,90 +0,0 @@
# 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 conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.utils import get_version, with_musl_toolchain
class ZlibBase(ConanFile):
version = get_version("zlib")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
def build_requirements(self):
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
def source(self):
get(
self,
f"https://github.com/madler/zlib/archive/v{self.version}.tar.gz",
)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
# with_musl_toolchain(self, tc)
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure(
{
"BUILD_SHARED_LIBS": False,
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
},
build_script_folder=f"zlib-{self.version}",
)
self.run("ninja zlibstatic")
def package(self):
copy(self, "*.a", self.build_folder, os.path.join(self.package_folder, "lib"))
copy(self, self.cmake_setup_file, self.recipe_folder, self.package_folder)
copy(
self,
"zconf.h",
self.build_folder,
os.path.join(self.package_folder, "include"),
)
copy(
self,
"zlib.h",
os.path.join(self.build_folder, f"zlib-{self.version}"),
os.path.join(self.package_folder, "include"),
)
copy(
self,
"zlib.pc",
self.build_folder,
os.path.join(self.package_folder, "share", "pkgconfig"),
)
def package_info(self):
self.cpp_info.set_property("cmake_build_modules", [self.cmake_setup_file])
self.cpp_info.set_property("cmake_find_mode", "module")
self.cpp_info.set_property("cmake_file_name", "ZLIB")
self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")
self.cpp_info.set_property("pkg_config_name", "zlib")
self.cpp_info.libs = ["z"]
self.cpp_info.set_property("cmake_find_package", "ZLIB")
self.cpp_info.set_property("cmake_find_package_multi", "ZLIB")

View File

@ -1 +0,0 @@
lxsameer@majin.28838:1680810906

View File

@ -32,14 +32,6 @@ class ZlibBase(ConanFile):
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
# if self.options.libc == "musl":
# self.tool_requires(
# f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}",
# visible=False,
# )
# self.requires(f"musl/{get_version('musl')}@{self.user}/{self.channel}")
def source(self):
get(
self,

View File

@ -0,0 +1,125 @@
# 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.files import get
from conan.tools.cmake import CMakeToolchain
from conf.utils import get_version, copy_template, copy_tree
class Stage1(ConanFile):
name = "stage1-sysroot"
version = get_version("llvm")
settings = "os", "arch"
exports = ("*.cmake",)
def build_requirements(self):
self.requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}"
)
self.requires(
f"zlib/{get_version('zlib')}@{self.user}/{self.channel}", visible=False
)
self.requires(
f"zstd/{get_version('zstd')}@{self.user}/{self.channel}", visible=False
)
self.requires(
f"musl/{get_version('musl')}@{self.user}/{self.channel}", visible=False
)
def build(self):
musl = self.dependencies["musl"]
clang = self.dependencies["clang-bootstrap"]
zlib = self.dependencies["zlib"]
zstd = self.dependencies["zstd"]
include_dir = Path(self.package_folder) / "include"
lib_dir = Path(self.package_folder) / "lib"
bin_dir = Path(self.package_folder) / "bin"
include_dir.mkdir(parents=True, exist_ok=True)
lib_dir.mkdir(parents=True, exist_ok=True)
bin_dir.mkdir(parents=True, exist_ok=True)
musl_include_dir = Path(musl.package_folder) / "include"
musl_lib_dir = Path(musl.package_folder) / "lib"
zstd_include_dir = Path(zstd.package_folder) / "include"
zstd_lib_dir = Path(zstd.package_folder) / "lib"
zlib_include_dir = Path(zlib.package_folder) / "include"
zlib_lib_dir = Path(zlib.package_folder) / "lib"
clang_include_dir = Path(clang.package_folder) / "include"
clang_lib_dir = Path(clang.package_folder) / "lib"
clang_bin_dir = Path(clang.package_folder) / "bin"
self.output.info(
f"Copying musl stuff: {musl_include_dir.name} -- {musl_lib_dir.name}"
)
copy_tree(musl_include_dir, include_dir)
copy_tree(musl_lib_dir, lib_dir)
copy_tree(zstd_include_dir, include_dir)
copy_tree(zstd_lib_dir, lib_dir)
copy_tree(zlib_include_dir, include_dir)
copy_tree(zlib_lib_dir, lib_dir)
self.output.info(
f"Copying clang stuff: {clang_include_dir.name} -- {clang_lib_dir.name}"
)
copy_tree(clang_include_dir, include_dir)
copy_tree(clang_lib_dir, lib_dir)
copy_tree(clang_bin_dir, bin_dir)
toolchain = f"{self.recipe_folder}/toolchain.cmake"
copy_template(
self,
toolchain,
f"{self.package_folder}/toolchain.cmake",
{"TRIPLE": os.environ["TARGET"]},
)
def package_info(self):
bindir = Path(self.package_folder) / "bin"
self.runenv_info.prepend_path(
"PATH",
str(bindir),
)
self.buildenv_info.append("sysroot", self.package_folder)
f = os.path.join(self.package_folder, "toolchain.cmake")
self.conf_info.prepend("tools.cmake.cmaketoolchain:user_toolchain", f)
self.conf_info.define("tools.build:sysroot", self.package_folder)
self.buildenv_info.define_path("SYSROOT", self.package_folder)
self.buildenv_info.define("CC", str(bindir / "clang"))
self.buildenv_info.define("CXX", str(bindir / "clang++"))
self.buildenv_info.define("AR", str(bindir / "clang"))
self.buildenv_info.define("NM", str(bindir / "llvm-nm"))
self.buildenv_info.define("RANLIB", str(bindir / "llvm-ranlib"))
self.cpp_info.includedirs = [
f"{self.package_folder}/include/c++/v1",
f"{self.package_folder}/include/",
f"{self.package_folder}/lib/clang/{get_version('llvm_major')}/include",
]

View File

@ -0,0 +1,31 @@
# 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/>.
set(CMAKE_SYSTEM_NAME Linux)
set(triple @TRIPLE@)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_ASM_COMPILER "clang")
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_ASM_COMPILER_TARGET ${triple})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)