2021-02-16 15:41:58 +00:00
|
|
|
"""A module defining the various toolchain definitions for `rules_foreign_cc`"""
|
|
|
|
|
2021-03-02 16:32:31 +00:00
|
|
|
load(":built_toolchains.bzl", _built_toolchains = "built_toolchains")
|
2021-02-16 15:41:58 +00:00
|
|
|
load(":prebuilt_toolchains.bzl", _prebuilt_toolchains = "prebuilt_toolchains")
|
|
|
|
|
2021-03-02 16:32:31 +00:00
|
|
|
# Re-expose the built toolchains macro
|
|
|
|
built_toolchains = _built_toolchains
|
|
|
|
|
2021-02-16 15:41:58 +00:00
|
|
|
# Re-expose the prebuilt toolchains macro
|
|
|
|
prebuilt_toolchains = _prebuilt_toolchains
|
|
|
|
|
|
|
|
# buildifier: disable=unnamed-macro
|
|
|
|
def preinstalled_toolchains():
|
|
|
|
"""Register toolchains for various build tools expected to be installed on the exec host"""
|
|
|
|
native.register_toolchains(
|
2022-04-07 15:44:38 +00:00
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_cmake_toolchain",
|
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_make_toolchain",
|
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_ninja_toolchain",
|
2023-06-09 10:29:12 +00:00
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_meson_toolchain",
|
2022-11-09 11:54:39 +00:00
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_autoconf_toolchain",
|
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_automake_toolchain",
|
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_m4_toolchain",
|
|
|
|
"@rules_foreign_cc//toolchains:preinstalled_pkgconfig_toolchain",
|
2021-02-16 15:41:58 +00:00
|
|
|
)
|
2022-03-14 14:06:22 +00:00
|
|
|
|
|
|
|
def _current_toolchain_impl(ctx):
|
|
|
|
toolchain = ctx.toolchains[ctx.attr._toolchain]
|
|
|
|
|
|
|
|
if toolchain.data.target:
|
|
|
|
return [
|
|
|
|
toolchain,
|
|
|
|
platform_common.TemplateVariableInfo(toolchain.data.env),
|
|
|
|
DefaultInfo(
|
2022-11-02 22:02:55 +00:00
|
|
|
files = toolchain.data.target.files,
|
2022-03-14 14:06:22 +00:00
|
|
|
runfiles = toolchain.data.target.default_runfiles,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
return [
|
|
|
|
toolchain,
|
|
|
|
platform_common.TemplateVariableInfo(toolchain.data.env),
|
|
|
|
DefaultInfo(),
|
|
|
|
]
|
|
|
|
|
|
|
|
# These rules exist so that the current toolchain can be used in the `toolchains` attribute of
|
|
|
|
# other rules, such as genrule. It allows exposing a <tool>_toolchain after toolchain resolution has
|
|
|
|
# happened, to a rule which expects a concrete implementation of a toolchain, rather than a
|
|
|
|
# toochain_type which could be resolved to that toolchain.
|
|
|
|
#
|
|
|
|
# See https://github.com/bazelbuild/bazel/issues/14009#issuecomment-921960766
|
|
|
|
current_cmake_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:cmake_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:cmake_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
current_make_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:make_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:make_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
current_ninja_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:ninja_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:ninja_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2023-06-09 10:29:12 +00:00
|
|
|
current_meson_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:meson_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:meson_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-03-14 14:06:22 +00:00
|
|
|
current_autoconf_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:autoconf_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:autoconf_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
current_automake_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:automake_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:automake_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
current_m4_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:m4_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:m4_toolchain")),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
current_pkgconfig_toolchain = rule(
|
|
|
|
implementation = _current_toolchain_impl,
|
|
|
|
attrs = {
|
|
|
|
"_toolchain": attr.string(default = str(Label("//toolchains:pkgconfig_toolchain"))),
|
|
|
|
},
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
toolchains = [
|
|
|
|
str(Label("//toolchains:pkgconfig_toolchain")),
|
|
|
|
],
|
|
|
|
)
|