2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-27 02:43:28 +00:00
rules_foreign_cc/toolchains/native_tools/tool_access.bzl
jheaff1 3cbd0a9938
Add meson support (#986)
* 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
2023-06-09 11:29:12 +01:00

66 lines
2.3 KiB
Python

"""A module defining convienence methoods for accessing build tools from
rules_foreign_cc toolchains
"""
def access_tool(toolchain_type_, ctx):
"""A helper macro for getting the path to a build tool's executable
Args:
toolchain_type_ (Label): The name of the toolchain type
ctx (ctx): The rule's context object
Returns:
ToolInfo: A provider containing information about the toolchain's executable
"""
tool_toolchain = ctx.toolchains[toolchain_type_]
if tool_toolchain:
return tool_toolchain.data
fail("No toolchain found for " + toolchain_type_)
def get_autoconf_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:autoconf_toolchain"), ctx)
def get_automake_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:automake_toolchain"), ctx)
def get_cmake_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:cmake_toolchain"), ctx)
def get_m4_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:m4_toolchain"), ctx)
def get_make_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:make_toolchain"), ctx)
def get_ninja_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:ninja_toolchain"), ctx)
def get_meson_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:meson_toolchain"), ctx)
def get_pkgconfig_data(ctx):
return _access_and_expect_label_copied(Label("//toolchains:pkgconfig_toolchain"), ctx)
def _access_and_expect_label_copied(toolchain_type_, ctx):
tool_data = access_tool(toolchain_type_, ctx)
if tool_data.target:
# This could be made more efficient by changing the
# toolchain to provide the executable as a target
cmd_file = tool_data
for f in tool_data.target.files.to_list():
if f.path.endswith("/" + tool_data.path):
cmd_file = f
break
return struct(
target = tool_data.target,
env = tool_data.env,
# as the tool will be copied into tools directory
path = "$EXT_BUILD_ROOT/{}".format(cmd_file.path),
)
else:
return struct(
target = None,
env = tool_data.env,
path = tool_data.path,
)