Creating bazel toolchains to compile for macOS.
This commit is contained in:
parent
9c3af64ae4
commit
a5fa4fb019
@ -4,7 +4,9 @@ package(default_visibility = ["//visibility:public"])
|
||||
|
||||
filegroup(name = "empty")
|
||||
|
||||
LINUX_TOOLCHAINS = {
|
||||
TOOLCHAINS = {
|
||||
"darwin-x86_64": "cc-compiler-osx-x86_64",
|
||||
"darwin-aarch_64": "cc-compiler-osx-aarch_64",
|
||||
"linux-aarch_64": "cc-compiler-linux-aarch_64",
|
||||
"linux-ppcle_64": "cc-compiler-linux-ppcle_64",
|
||||
"linux-s390_64": "cc-compiler-linux-s390_64",
|
||||
@ -14,7 +16,7 @@ LINUX_TOOLCHAINS = {
|
||||
|
||||
cc_toolchain_suite(
|
||||
name = "clang_suite",
|
||||
toolchains = LINUX_TOOLCHAINS
|
||||
toolchains = TOOLCHAINS
|
||||
)
|
||||
|
||||
[
|
||||
@ -32,13 +34,16 @@ cc_toolchain_suite(
|
||||
toolchain_config = ":" + cpu + "-config",
|
||||
toolchain_identifier = toolchain,
|
||||
)
|
||||
for cpu, toolchain in LINUX_TOOLCHAINS.items()
|
||||
for cpu, toolchain in TOOLCHAINS.items()
|
||||
]
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "linux-aarch_64-config",
|
||||
bit_flag = "-m64",
|
||||
include_flag = "-I/usr/aarch64-linux-gnu/include/c++/8/aarch64-linux-gnu/",
|
||||
cpp_flag = "-lstdc++",
|
||||
include_flag = ["-I/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/",
|
||||
"-I/usr/aarch64-linux-gnu/include/c++/10"],
|
||||
linker_path = "/usr/bin/ld",
|
||||
target_cpu = "aarch64",
|
||||
target_full_name = "aarch64-linux-gnu",
|
||||
toolchain_dir = "/usr/aarch64-linux-gnu/include",
|
||||
@ -48,7 +53,10 @@ cc_toolchain_config(
|
||||
cc_toolchain_config(
|
||||
name = "linux-ppcle_64-config",
|
||||
bit_flag = "-m64",
|
||||
include_flag = "-I/usr/powerpc64le-linux-gnu/include/c++/8/powerpc64le-linux-gnu/",
|
||||
cpp_flag = "-lstdc++",
|
||||
include_flag = ["-I/usr/powerpc64le-linux-gnu/include/c++/10/powerpc64le-linux-gnu/",
|
||||
"-I/usr/powerpc64le-linux-gnu/include/c++/10/"],
|
||||
linker_path = "/usr/bin/ld",
|
||||
target_cpu = "ppc64",
|
||||
target_full_name = "powerpc64le-linux-gnu",
|
||||
toolchain_dir = "/usr/powerpc64le-linux-gnu/include",
|
||||
@ -58,7 +66,10 @@ cc_toolchain_config(
|
||||
cc_toolchain_config(
|
||||
name = "linux-s390_64-config",
|
||||
bit_flag = "-m64",
|
||||
include_flag = "-I/usr/s390x-linux-gnu/include/c++/8/s390x-linux-gnu/",
|
||||
cpp_flag = "-lstdc++",
|
||||
include_flag = ["-I/usr/s390x-linux-gnu/include/c++/10/s390x-linux-gnu/",
|
||||
"-I/usr/s390x-linux-gnu/include/c++/10/"],
|
||||
linker_path = "/usr/bin/ld",
|
||||
target_cpu = "systemz",
|
||||
target_full_name = "s390x-linux-gnu",
|
||||
toolchain_dir = "/usr/s390x-linux-gnu/include",
|
||||
@ -68,6 +79,8 @@ cc_toolchain_config(
|
||||
cc_toolchain_config(
|
||||
name = "linux-x86_32-config",
|
||||
bit_flag = "-m32",
|
||||
cpp_flag = "-lstdc++",
|
||||
linker_path = "/usr/bin/ld",
|
||||
target_cpu = "x86_32",
|
||||
target_full_name = "i386-linux-gnu",
|
||||
toolchain_dir = "/usr/include/i386-linux-gnu",
|
||||
@ -77,8 +90,38 @@ cc_toolchain_config(
|
||||
cc_toolchain_config(
|
||||
name = "linux-x86_64-config",
|
||||
bit_flag = "-m64",
|
||||
cpp_flag = "-lstdc++",
|
||||
linker_path = "/usr/bin/ld",
|
||||
target_cpu = "x86_64",
|
||||
target_full_name = "x86_64-linux-gnu",
|
||||
toolchain_dir = "/usr/include/x86_64-linux-gnu",
|
||||
toolchain_name = "linux_x86_64",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "darwin-aarch_64-config",
|
||||
bit_flag = "-m64",
|
||||
cpp_flag = "-lc++",
|
||||
include_flag = ["-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1",
|
||||
"-I/tools/apple_sdks/xcode_13_0/macosx/usr/include"],
|
||||
linker_path = "/tools",
|
||||
sysroot = "/tools/apple_sdks/xcode_13_0/macosx",
|
||||
target_cpu = "aarch64",
|
||||
target_full_name = "aarch64-apple-macosx11.3",
|
||||
toolchain_dir = "/tools/apple_sdks/xcode_13_0/macosx",
|
||||
toolchain_name = "darwin_aarch_64",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "darwin-x86_64-config",
|
||||
bit_flag = "-m64",
|
||||
cpp_flag = "-lc++",
|
||||
include_flag = ["-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1",
|
||||
"-I/tools/apple_sdks/xcode_13_0/macosx/usr/include"],
|
||||
linker_path = "/tools",
|
||||
sysroot = "/tools/apple_sdks/xcode_13_0/macosx",
|
||||
target_cpu = "x86_64",
|
||||
target_full_name = "x86_64-apple-macosx11.3",
|
||||
toolchain_dir = "/tools/apple_sdks/xcode_13_0/macosx",
|
||||
toolchain_name = "darwin_x86_64",
|
||||
)
|
||||
|
@ -35,15 +35,15 @@ def _impl(ctx):
|
||||
),
|
||||
tool_path(
|
||||
name = "ld",
|
||||
path = "/usr/bin/ld",
|
||||
path = ctx.attr.linker_path,
|
||||
),
|
||||
tool_path(
|
||||
name = "ar",
|
||||
path = "/usr/bin/ar",
|
||||
path = "/usr/bin/llvm-ar",
|
||||
),
|
||||
tool_path(
|
||||
name = "compat-ld",
|
||||
path = "/usr/bin/ld",
|
||||
path = ctx.attr.linker_path,
|
||||
),
|
||||
tool_path(
|
||||
name = "cpp",
|
||||
@ -84,7 +84,8 @@ def _impl(ctx):
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-lstdc++",
|
||||
"-B" + ctx.attr.linker_path,
|
||||
ctx.attr.cpp_flag,
|
||||
"--target=" + ctx.attr.target_full_name,
|
||||
],
|
||||
),
|
||||
@ -92,6 +93,36 @@ def _impl(ctx):
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
sysroot_flags = feature(
|
||||
name = "sysroot_flags",
|
||||
#Only enable this if a sysroot was specified
|
||||
enabled = (ctx.attr.sysroot != ""),
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"--sysroot",
|
||||
ctx.attr.sysroot,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-isysroot" + ctx.attr.sysroot,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
compiler_flags = feature(
|
||||
name = "default_compile_flags",
|
||||
enabled = True,
|
||||
@ -107,8 +138,8 @@ def _impl(ctx):
|
||||
"--target=" + ctx.attr.target_full_name,
|
||||
"-isystem",
|
||||
ctx.attr.toolchain_dir,
|
||||
ctx.attr.include_flag,
|
||||
],
|
||||
"-fvisibility=hidden",
|
||||
] + ctx.attr.include_flag,
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -116,8 +147,8 @@ def _impl(ctx):
|
||||
)
|
||||
|
||||
return cc_common.create_cc_toolchain_config_info(
|
||||
abi_libc_version = ctx.attr.target_cpu,
|
||||
abi_version = ctx.attr.target_cpu,
|
||||
abi_libc_version = ctx.attr.abi_version,
|
||||
abi_version = ctx.attr.abi_version,
|
||||
ctx = ctx,
|
||||
compiler = "clang",
|
||||
cxx_builtin_include_directories = [
|
||||
@ -125,7 +156,7 @@ def _impl(ctx):
|
||||
"/usr/include",
|
||||
"/usr/local/lib/clang",
|
||||
],
|
||||
features = [linker_flags, compiler_flags],
|
||||
features = [linker_flags, compiler_flags, sysroot_flags],
|
||||
host_system_name = "local",
|
||||
target_cpu = ctx.attr.target_cpu,
|
||||
target_libc = ctx.attr.target_cpu,
|
||||
@ -137,8 +168,12 @@ def _impl(ctx):
|
||||
cc_toolchain_config = rule(
|
||||
implementation = _impl,
|
||||
attrs = {
|
||||
"abi_version": attr.string(default = "local"),
|
||||
"bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]),
|
||||
"include_flag": attr.string(mandatory = False),
|
||||
"cpp_flag": attr.string(mandatory = True),
|
||||
"include_flag": attr.string_list(),
|
||||
"linker_path": attr.string(mandatory = True),
|
||||
"sysroot": attr.string(mandatory = False),
|
||||
"target_cpu": attr.string(mandatory = True, values = ["aarch64", "ppc64", "systemz", "x86_32", "x86_64"]),
|
||||
"target_full_name": attr.string(mandatory = True),
|
||||
"toolchain_dir": attr.string(mandatory = True),
|
||||
|
@ -6,3 +6,5 @@ build:linux-ppcle_64 --config=cross_config --cpu=linux-ppcle_64
|
||||
build:linux-s390_64 --config=cross_config --cpu=linux-s390_64
|
||||
build:linux-x86_32 --config=cross_config --cpu=linux-x86_32
|
||||
build:linux-x86_64 --config=cross_config --cpu=linux-x86_64
|
||||
build:osx-aarch_64 --config=cross_config --cpu=darwin-aarch_64
|
||||
build:osx-x86_64 --config=cross_config --cpu=darwin-x86_64
|
||||
|
Loading…
Reference in New Issue
Block a user