Skip to content

Commit

Permalink
Rewrite swift_binary_test.bzl using new skylark cc toolchain api
Browse files Browse the repository at this point in the history
This is a part of the bazelbuild/bazel#4571 effort.

RELNOTES: None
PiperOrigin-RevId: 204754855
  • Loading branch information
Googler authored and allevato committed Jul 31, 2018
1 parent 3afd176 commit 05b0ece
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions swift/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ filegroup(
# We should be depending on a filegroup here that represents this file
# and its dependencies, but it doesn't exist yet.
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
"@bazel_tools//tools/build_defs/cc:action_names_test_files",
],
visibility = [
"@build_bazel_rules_swift//swift:__pkg__",
Expand Down
17 changes: 17 additions & 0 deletions swift/internal/swift_binary_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ load(":providers.bzl", "SwiftBinaryInfo", "SwiftToolchainInfo")
load(":utils.bzl", "expand_locations", "get_optionally")
load("@bazel_skylib//:lib.bzl", "dicts", "partial")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "CPP_LINK_EXECUTABLE_ACTION_NAME")

def _swift_linking_rule_impl(ctx, is_test):
"""The shared implementation function for `swift_{binary,test}`.
Expand Down Expand Up @@ -116,6 +117,22 @@ def _swift_linking_rule_impl(ctx, is_test):
features,
False,
))
elif hasattr(cc_common, "get_command_line"):
feature_configuration = cc_common.configure_features(
cc_toolchain = cpp_toolchain,
requested_features = ctx.features + ["static_linking_mode"],
unsupported_features = ctx.disabled_features,
)
variables = cc_common.create_link_build_variables(
feature_configuration = feature_configuration,
cc_toolchain = cpp_toolchain,
)
link_cpp_toolchain_flags = cc_common.get_command_line(
feature_configuration = feature_configuration,
action_name = CPP_LINK_EXECUTABLE_ACTION_NAME,
variables = variables,
)
link_args.add_all(link_cpp_toolchain_flags)

register_link_action(
actions = ctx.actions,
Expand Down

0 comments on commit 05b0ece

Please sign in to comment.