-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The macros utilise bazel "transitions" to set the `make` toolchain used in the configure_make(), cmake() or make() rules to a given make variant toolchain, e.g. preinstalled_nmake. Note that the msvc constraint was removed from the `exec_compatible_with` attribute of `preinstalled_nmake_toolchain` as the condition is not actually met even when building with msvc. See bazelbuild/bazel#7730. This will be tested in PR#729
- Loading branch information
Showing
8 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
"""Public entry point to all Foreign CC rules and supported APIs.""" | ||
|
||
load(":boost_build.bzl", _boost_build = "boost_build") | ||
load(":cmake.bzl", _cmake = "cmake") | ||
load(":configure.bzl", _configure_make = "configure_make") | ||
load(":make.bzl", _make = "make") | ||
load(":cmake.bzl", _cmake = "cmake", _cmake_variant = "cmake_variant") | ||
load(":configure.bzl", _configure_make = "configure_make", _configure_make_variant = "configure_make_variant") | ||
load(":make.bzl", _make = "make", _make_variant = "make_variant") | ||
load(":ninja.bzl", _ninja = "ninja") | ||
|
||
boost_build = _boost_build | ||
cmake = _cmake | ||
cmake_variant = _cmake_variant | ||
configure_make = _configure_make | ||
configure_make_variant = _configure_make_variant | ||
make_variant = _make_variant | ||
make = _make | ||
ninja = _ninja |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""This file contains rules for configuration transitions""" | ||
|
||
load("//foreign_cc:providers.bzl", "ForeignCcDepsInfo") | ||
|
||
def _extra_toolchains_transition_impl(settings, attrs): | ||
return {"//command_line_option:extra_toolchains": attrs.extra_toolchains + settings["//command_line_option:extra_toolchains"]} | ||
|
||
_extra_toolchains_transition = transition( | ||
implementation = _extra_toolchains_transition_impl, | ||
inputs = ["//command_line_option:extra_toolchains"], | ||
outputs = ["//command_line_option:extra_toolchains"], | ||
) | ||
|
||
def _extra_toolchains_transitioned_foreign_cc_target_impl(ctx): | ||
# Return the providers from the transitioned foreign_cc target | ||
return [ | ||
ctx.attr.target[DefaultInfo], | ||
ctx.attr.target[CcInfo], | ||
ctx.attr.target[ForeignCcDepsInfo], | ||
ctx.attr.target[OutputGroupInfo], | ||
] | ||
|
||
extra_toolchains_transitioned_foreign_cc_target = rule( | ||
doc = "A rule for adding extra toolchains to consider when building the given target", | ||
implementation = _extra_toolchains_transitioned_foreign_cc_target_impl, | ||
cfg = _extra_toolchains_transition, | ||
attrs = { | ||
"extra_toolchains": attr.string_list( | ||
doc = "Additional toolchains to consider", | ||
mandatory = True, | ||
), | ||
"target": attr.label( | ||
doc = "The target to build after considering the extra toolchains", | ||
providers = [ForeignCcDepsInfo], | ||
mandatory = True, | ||
), | ||
"_allowlist_function_transition": attr.label( | ||
default = "@bazel_tools//tools/allowlists/function_transition_allowlist", | ||
), | ||
}, | ||
incompatible_use_toolchain_transition = True, | ||
) | ||
|
||
def make_variant(name, rule, toolchain, **kwargs): | ||
""" Wrapper macro around foreign cc rules to force usage of the given make variant toolchain. | ||
Args: | ||
name: The target name | ||
rule: The configure_make() or make() rule to instantiate | ||
toolchain: The desired make variant toolchain to use, e.g. @rules_foreign_cc//toolchains:preinstalled_nmake_toolchain | ||
**kwargs: Remaining keyword arguments | ||
""" | ||
|
||
make_variant_target_name = name + "_" | ||
|
||
tags = kwargs["tags"] if "tags" in kwargs else [] | ||
|
||
rule( | ||
name = make_variant_target_name, | ||
tags = tags + ["manual"], | ||
**kwargs | ||
) | ||
|
||
extra_toolchains_transitioned_foreign_cc_target( | ||
name = name, | ||
extra_toolchains = [toolchain], | ||
target = make_variant_target_name, | ||
tags = tags, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters