Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
load("@rules_cc//cc:find_cc_toolchain.bzl", find_cpp_toolchain = "find_cc_toolchain")
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("//rust:defs.bzl", "rust_common")
load("//rust:rust_common.bzl", "BuildInfo", "CrateGroupInfo", "DepInfo")
Expand All @@ -21,8 +20,7 @@ load(
"dedent",
"deduplicate",
"expand_dict_value_locations",
"find_cc_toolchain",
"find_toolchain",
"get_feature_configuration",
_name_to_crate_name = "name_to_crate_name",
)

Expand Down Expand Up @@ -316,7 +314,7 @@ def _cargo_build_script_impl(ctx):
"""
script = ctx.executable.script
script_info = ctx.attr.script[CargoBuildScriptRunfilesInfo]
toolchain = find_toolchain(ctx)
toolchain = ctx.exec_groups["build_script_run"].toolchains["//rust:toolchain_type"]
out_dir = ctx.actions.declare_directory(ctx.label.name + ".out_dir")
env_out = ctx.actions.declare_file(ctx.label.name + ".env")
dep_env_out = ctx.actions.declare_file(ctx.label.name + ".depenv")
Expand Down Expand Up @@ -367,8 +365,6 @@ def _cargo_build_script_impl(ctx):

toolchain_tools = [toolchain.all_files]

cc_toolchain = find_cpp_toolchain(ctx)

env = dict({})

if ctx.attr.use_default_shell_env == -1:
Expand Down Expand Up @@ -417,7 +413,8 @@ def _cargo_build_script_impl(ctx):

# Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version).
# We hope that the linker env is sufficient for the whole cc_toolchain.
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
cc_toolchain = ctx.exec_groups["build_script_run"].toolchains["@bazel_tools//tools/cpp:toolchain_type"].cc
feature_configuration = get_feature_configuration(ctx, cc_toolchain)
linker, link_args, linker_env = get_linker_and_args(ctx, "bin", cc_toolchain, feature_configuration, None)
env.update(**linker_env)
env["LD"] = linker
Expand Down Expand Up @@ -588,7 +585,7 @@ def _cargo_build_script_impl(ctx):
mnemonic = "CargoBuildScriptRun",
progress_message = "Running Cargo build script {}".format(pkg_name),
env = env,
toolchain = None,
exec_group = "build_script_run",
use_default_shell_env = use_default_shell_env,
)

Expand Down Expand Up @@ -730,11 +727,15 @@ cargo_build_script = rule(
default = Label("//cargo/settings:incompatible_runfiles_cargo_manifest_dir"),
),
},
exec_groups = {
"build_script_run": exec_group(
toolchains = [
"//rust:toolchain_type",
"@bazel_tools//tools/cpp:toolchain_type",
],
),
},
fragments = ["cpp"],
toolchains = [
str(Label("//rust:toolchain_type")),
"@bazel_tools//tools/cpp:toolchain_type",
],
)

def _merge_env_dict(prefix_dict, suffix_dict):
Expand Down
5 changes: 3 additions & 2 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ def find_cc_toolchain(ctx, extra_unsupported_features = tuple()):
tuple: A tuple of (CcToolchain, FeatureConfiguration)
"""
cc_toolchain = find_rules_cc_toolchain(ctx)
return cc_toolchain, get_feature_configuration(ctx, cc_toolchain, extra_unsupported_features)

feature_configuration = cc_common.configure_features(
def get_feature_configuration(ctx, cc_toolchain, extra_unsupported_features = tuple()):
return cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = UNSUPPORTED_FEATURES + ctx.disabled_features +
list(extra_unsupported_features),
)
return cc_toolchain, feature_configuration

# TODO: Replace with bazel-skylib's `path.dirname`. This requires addressing some
# dependency issues or generating docs will break.
Expand Down