mirror of
https://github.com/bazel-contrib/rules_foreign_cc
synced 2024-11-28 08:43:26 +00:00
3cbd0a9938
* Add meson support * Modify zlib to be detected via pkgconfig in dependent rules * Modify zlib and expat to be linked to shared libs in dependent rules * Add example usage of Meson rule This commit adds the glib library to the "examples" build. glib requires pcre2, so pcre and libgit2 (a dependent of pcre) have been updated/modified * Add example usage of meson_with_requirements macro This commit adds mesa to the "examples" build. This commit also changes the "examples" build to use the hermetic python toolchain provided by rules_foreign_cc. As such, the python toolchain built by rules_foreign_cc is no longer used, as it cannot be used in workspace rules, .e.g pip_parse(). As such, the python2 build has been removed from the examples as python2 is end-of-life. Until Bazel 4.2.0, the built-in android toolchain required Python 2. As such the minimum supported version has been upversioned to 4.2.0. Note that the BAZEL_VC env var was removed from CI as mesa requires MSVC 2019. * Set visibility for each target in foreign_cc_rule_variant * Apply formatting changes * Get meson examples working with bzlmod Note that a newer version of pkgconfig than that installed in ubuntu 20 must be used to build libxau, therefore the built_pkgconfig_toolchain is now registered
137 lines
4.6 KiB
Python
137 lines
4.6 KiB
Python
"""A module defining the various toolchain definitions for `rules_foreign_cc`"""
|
|
|
|
load(":built_toolchains.bzl", _built_toolchains = "built_toolchains")
|
|
load(":prebuilt_toolchains.bzl", _prebuilt_toolchains = "prebuilt_toolchains")
|
|
|
|
# Re-expose the built toolchains macro
|
|
built_toolchains = _built_toolchains
|
|
|
|
# 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(
|
|
"@rules_foreign_cc//toolchains:preinstalled_cmake_toolchain",
|
|
"@rules_foreign_cc//toolchains:preinstalled_make_toolchain",
|
|
"@rules_foreign_cc//toolchains:preinstalled_ninja_toolchain",
|
|
"@rules_foreign_cc//toolchains:preinstalled_meson_toolchain",
|
|
"@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",
|
|
)
|
|
|
|
def _current_toolchain_impl(ctx):
|
|
toolchain = ctx.toolchains[ctx.attr._toolchain]
|
|
|
|
if toolchain.data.target:
|
|
return [
|
|
toolchain,
|
|
platform_common.TemplateVariableInfo(toolchain.data.env),
|
|
DefaultInfo(
|
|
files = toolchain.data.target.files,
|
|
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")),
|
|
],
|
|
)
|
|
|
|
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")),
|
|
],
|
|
)
|
|
|
|
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")),
|
|
],
|
|
)
|