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

Refactor Yggdrasil toolchain #376

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 7 additions & 5 deletions deps/ReactantExtra/BUILD
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
load("@xla//tools/toolchains/cross_compile/cc:cc_toolchain_config.bzl", "cc_toolchain_config")
# load("//toolchain:yggdrasil.bzl", "ygg_cc_toolchain")
load("//:toolchain/yggdrasil.bzl", "ygg_cc_toolchain")
licenses(["notice"])

package(
default_applicable_licenses = [],
default_visibility = ["//:__subpackages__"],
)

ygg_cc_toolchain()

cc_toolchain_suite(
name = "ygg_cross_compile_toolchain_suite",
toolchains = {
"k8": ":ygg_x86_toolchain",
"darwin": ":ygg_x86_toolchain",
"darwin_arm64": ":ygg_x86_toolchain",
"aarch64": ":ygg_aarch64_toolchain",
"k8": ":ygg_target_toolchain", # ":ygg_x86_toolchain",
"darwin": ":ygg_target_toolchain", # ":ygg_x86_toolchain",
"darwin_arm64": ":ygg_target_toolchain", # ":ygg_x86_toolchain",
"aarch64": ":ygg_target_toolchain", # ":ygg_aarch64_toolchain",
},
)

Expand Down
101 changes: 59 additions & 42 deletions deps/ReactantExtra/toolchain/yggdrasil.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ load("@xla//tools/toolchains/cross_compile/cc:cc_toolchain_config.bzl", "cc_tool
# cpu = "aarch64"
# toolchain_identifier = "ygg_aarch64"
# target_system_name = "aarch64-unknown-linux-gnu"
def ygg_cc_toolchain(cpu, toolchain_identifier, target_system_name, bb_target, bb_full_target, supports_start_end_lib = False):
def _ygg_cc_toolchain_impl(ctx):
bb_target = ctx.configuration.default_shell_env["bb_target"]
bb_full_target = ctx.configuration.default_shell_env["bb_full_target"]
cpu = ctx.configuration.default_shell_env["bb_cpu"]
toolchain_identifier = "ygg_toolchain"
target_system_name = ""
supports_start_end_lib = False

cc_toolchain(
name = "ygg_target_toolchain",
all_files = ":empty",
Expand All @@ -23,45 +30,46 @@ def ygg_cc_toolchain(cpu, toolchain_identifier, target_system_name, bb_target, b
cc_toolchain_config(
name = "ygg_target_toolchain_config",
cpu = cpu,
compiler = "compiler",
compiler = "clang",
toolchain_identifier = toolchain_identifier,
target_system_name = target_system_name,
target_libc = "",
abi_libc_version = "local",
abi_version = "local",
cxx_builtin_include_directories = [
f"/opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include",
f"/opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include-fixed",
f"/opt/{bb_target}/{bb_target}/include",
f"/opt/{bb_target}/{bb_target}/sys-root/usr/include",
f"/opt/{bb_target}/{bb_target}/include/c++/10.2.0",
f"/opt/{bb_target}/{bb_target}/include/c++/10.2.0/{bb_target}",
f"/opt/{bb_target}/{bb_target}/include/c++/10.2.0/backward",
f"/opt/{bb_target}/{bb_target}/include/c++/10.2.0/parallel"
"/opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include".format(bb_target = bb_target),
"/opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include-fixed".format(bb_target = bb_target),
"/opt/{bb_target}/{bb_target}/include".format(bb_target = bb_target),
"/opt/{bb_target}/{bb_target}/sys-root/usr/include".format(bb_target = bb_target),
"/opt/{bb_target}/{bb_target}/include/c++/10.2.0".format(bb_target = bb_target),
"/opt/{bb_target}/{bb_target}/include/c++/10.2.0/{bb_target}".format(bb_target = bb_target),
"/opt/{bb_target}/{bb_target}/include/c++/10.2.0/backward".format(bb_target = bb_target),
"/opt/{bb_target}/{bb_target}/include/c++/10.2.0/parallel".format(bb_target = bb_target),
],
tool_paths = {
"ar": f"/opt/bin/{bb_full_target}/ar",
"as": f"/opt/bin/{bb_full_target}/as",
"c++": f"/opt/bin/{bb_full_target}/c++",
"c++filt": f"/opt/bin/{bb_full_target}/c++filt",
"cc": f"/opt/bin/{bb_full_target}/cc",
"clang": f"/opt/bin/{bb_full_target}/clang",
"clang++": f"/opt/bin/{bb_full_target}/clang++",
"cpp": f"/opt/bin/{bb_full_target}/cpp",
"f77": f"/opt/bin/{bb_full_target}/f77",
"g++": f"/opt/bin/{bb_full_target}/g++",
"gcc": f"/opt/bin/{bb_full_target}/gcc",
"gfortran": f"/opt/bin/{bb_full_target}/gfortran",
"ld": f"/opt/bin/{bb_full_target}/ld",
"ld.lld": f"/opt/bin/{bb_full_target}/ld.lld",
"libtool": f"/opt/bin/{bb_full_target}/libtool",
"lld": f"/opt/bin/{bb_full_target}/lld",
"nm": f"/opt/bin/{bb_full_target}/nm",
"objcopy": f"/opt/bin/{bb_full_target}/objcopy",
"patchelf": f"/opt/bin/{bb_full_target}/patchelf",
"ranlib": f"/opt/bin/{bb_full_target}/ranlib",
"readelf": f"/opt/bin/{bb_full_target}/readelf",
"strip": f"/opt/bin/{bb_full_target}/strip",
"ar": "/opt/bin/{bb_full_target}/ar".format(bb_full_target = bb_full_target),
"as": "/opt/bin/{bb_full_target}/as".format(bb_full_target = bb_full_target),
"c++": "/opt/bin/{bb_full_target}/c++".format(bb_full_target = bb_full_target),
"c++filt": "/opt/bin/{bb_full_target}/c++filt".format(bb_full_target = bb_full_target),
"cc": "/opt/bin/{bb_full_target}/cc".format(bb_full_target = bb_full_target),
"clang": "/opt/bin/{bb_full_target}/clang".format(bb_full_target = bb_full_target),
"clang++": "/opt/bin/{bb_full_target}/clang++".format(bb_full_target = bb_full_target),
"cpp": "/opt/bin/{bb_full_target}/cpp".format(bb_full_target = bb_full_target),
"f77": "/opt/bin/{bb_full_target}/f77".format(bb_full_target = bb_full_target),
# WARN we force to use clang instead of gcc
"g++": "/opt/bin/{bb_full_target}/clang++".format(bb_full_target = bb_full_target),
"gcc": "/opt/bin/{bb_full_target}/clang".format(bb_full_target = bb_full_target),
"gfortran": "/opt/bin/{bb_full_target}/gfortran".format(bb_full_target = bb_full_target),
"ld": "/opt/bin/{bb_full_target}/ld".format(bb_full_target = bb_full_target),
"ld.lld": "/opt/bin/{bb_full_target}/ld.lld".format(bb_full_target = bb_full_target),
"libtool": "/opt/bin/{bb_full_target}/libtool".format(bb_full_target = bb_full_target),
"lld": "/opt/bin/{bb_full_target}/lld".format(bb_full_target = bb_full_target),
"nm": "/opt/bin/{bb_full_target}/nm".format(bb_full_target = bb_full_target),
"objcopy": "/opt/bin/{bb_full_target}/objcopy".format(bb_full_target = bb_full_target),
"patchelf": "/opt/bin/{bb_full_target}/patchelf".format(bb_full_target = bb_full_target),
"ranlib": "/opt/bin/{bb_full_target}/ranlib".format(bb_full_target = bb_full_target),
"readelf": "/opt/bin/{bb_full_target}/readelf".format(bb_full_target = bb_full_target),
"strip": "/opt/bin/{bb_full_target}/strip".format(bb_full_target = bb_full_target),
# from host
"llvm-cov": "/opt/x86_64-linux-musl/bin/llvm-cov",
"llvm-profdata": "/opt/x86_64-linux-musl/bin/llvm-profdata",
Expand All @@ -74,14 +82,14 @@ def ygg_cc_toolchain(cpu, toolchain_identifier, target_system_name, bb_target, b
"-Wno-free-nonheap-object",
"-fno-omit-frame-pointer",
# TODO cxx_builtin_include_directories doesn't seem to be working, so we add the INCLUDE_PATHs manually
f"-isystem /opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include",
f"-isystem /opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include-fixed",
f"-isystem /opt/{bb_target}/{bb_target}/include",
f"-isystem /opt/{bb_target}/{bb_target}/sys-root/usr/include",
f"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0",
f"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0/{bb_target}",
f"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0/backward",
f"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0/parallel",
"-isystem /opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/lib/gcc/{bb_target}/10.2.0/include-fixed".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/{bb_target}/include".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/{bb_target}/sys-root/usr/include".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0/{bb_target}".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0/backward".format(bb_target = bb_target),
"-isystem /opt/{bb_target}/{bb_target}/include/c++/10.2.0/parallel".format(bb_target = bb_target),
],
opt_compile_flags = [
"-g0",
Expand All @@ -108,10 +116,19 @@ def ygg_cc_toolchain(cpu, toolchain_identifier, target_system_name, bb_target, b
"-Wno-unused-command-line-argument",
"-Wno-gnu-offsetof-extensions",
],
builtin_sysroot = f"/opt/{bb_target}/{bb_target}/sys-root/",
builtin_sysroot = "/opt/{bb_target}/{bb_target}/sys-root/".format(bb_target = bb_target),
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
host_system_name = "linux",
# TODO gcc doesn't support it, only put it on clang (maybe even only for clang on aarch64-darwin?)
supports_start_end_lib = supports_start_end_lib,
# supports_start_end_lib = supports_start_end_lib,
)

ygg_cc_toolchain = rule(
implementation = _ygg_cc_toolchain_impl,
attrs = {
"name": attr.string(default = "ygg_cc_toolchain"),
},
executable = False,
test = False,
)
Loading