mirror of https://github.com/bazelbuild/rules_rust
Remove redundant/legacy cargo_build_script.bzl (#2364)
This commit is contained in:
parent
e989bd9883
commit
3545dec15a
|
@ -72,7 +72,7 @@ that anything directly accessible from this file is considered stable.
|
|||
`//rust/private/…` is not subject to the backwards compatibility policy. Content
|
||||
of this package is an implementation detail.
|
||||
|
||||
`//cargo:cargo_build_script.bzl` is subject to the backwards compatibility policy.
|
||||
`//cargo:defs.bzl` is subject to the backwards compatibility policy.
|
||||
|
||||
`//cargo`, `//util`, `//tools`, `//test`, `//examples`, `//bindgen`, `//proto`,
|
||||
`//wasm_bindgen` and any packages not mentioned by this document are by default
|
||||
|
@ -88,7 +88,7 @@ They should be added to `//rust:incompatible.bzl`.
|
|||
Bug fixes are not a breaking change by default. We'll use Common Sense (and we
|
||||
will pull in more maintainers and the community to discuss) if we see a certain
|
||||
bug fix is controversial. Incompatible changes to
|
||||
`//cargo:cargo_build_script.bzl` that make `cargo_build_script` more accurately
|
||||
`//cargo:defs.bzl` that make `cargo_build_script` more accurately
|
||||
follow cargo's behaviour are considered bug fixes.
|
||||
|
||||
## How to make a backwards incompatible change?
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
"""Legacy load locations for Cargo build script rules
|
||||
|
||||
Instead, `defs.bzl` should be used.
|
||||
"""
|
||||
|
||||
load(
|
||||
"//cargo/private:cargo_build_script.bzl",
|
||||
_cargo_dep_env = "cargo_dep_env",
|
||||
)
|
||||
load(
|
||||
"//cargo/private:cargo_build_script_wrapper.bzl",
|
||||
_cargo_build_script = "cargo_build_script",
|
||||
)
|
||||
|
||||
cargo_build_script = _cargo_build_script
|
||||
cargo_dep_env = _cargo_dep_env
|
|
@ -1,5 +1,10 @@
|
|||
"""Common definitions for the `@rules_rust//cargo` package"""
|
||||
|
||||
load(
|
||||
"//cargo/private:cargo_bootstrap.bzl",
|
||||
_cargo_bootstrap_repository = "cargo_bootstrap_repository",
|
||||
_cargo_env = "cargo_env",
|
||||
)
|
||||
load(
|
||||
"//cargo/private:cargo_build_script.bzl",
|
||||
_cargo_dep_env = "cargo_dep_env",
|
||||
|
@ -8,11 +13,6 @@ load(
|
|||
"//cargo/private:cargo_build_script_wrapper.bzl",
|
||||
_cargo_build_script = "cargo_build_script",
|
||||
)
|
||||
load(
|
||||
":cargo_bootstrap.bzl",
|
||||
_cargo_bootstrap_repository = "cargo_bootstrap_repository",
|
||||
_cargo_env = "cargo_env",
|
||||
)
|
||||
|
||||
cargo_bootstrap_repository = _cargo_bootstrap_repository
|
||||
cargo_env = _cargo_env
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
"""Public Cargo features for Bazel."""
|
||||
|
||||
# `symlink-exec-root` feature will symlink the execroot to the build script execution directory.
|
||||
#
|
||||
# This is useful for building with hermetic C++ toolchains.
|
||||
SYMLINK_EXEC_ROOT_FEATURE = "symlink-exec-root"
|
|
@ -4,16 +4,25 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
|
|||
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
|
||||
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "CPP_COMPILE_ACTION_NAME", "C_COMPILE_ACTION_NAME")
|
||||
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||
load("//cargo:features.bzl", "SYMLINK_EXEC_ROOT_FEATURE")
|
||||
load("//rust:defs.bzl", "rust_common")
|
||||
load("//rust:rust_common.bzl", "BuildInfo", "DepInfo")
|
||||
|
||||
# buildifier: disable=bzl-visibility
|
||||
load("//rust/private:rustc.bzl", "get_compilation_mode_opts", "get_linker_and_args")
|
||||
load(
|
||||
"//rust/private:rustc.bzl",
|
||||
"get_compilation_mode_opts",
|
||||
"get_linker_and_args",
|
||||
)
|
||||
|
||||
# buildifier: disable=bzl-visibility
|
||||
load("//rust/private:utils.bzl", "dedent", "expand_dict_value_locations", "find_cc_toolchain", "find_toolchain", _name_to_crate_name = "name_to_crate_name")
|
||||
load(":features.bzl", "feature_enabled")
|
||||
load(
|
||||
"//rust/private:utils.bzl",
|
||||
"dedent",
|
||||
"expand_dict_value_locations",
|
||||
"find_cc_toolchain",
|
||||
"find_toolchain",
|
||||
_name_to_crate_name = "name_to_crate_name",
|
||||
)
|
||||
|
||||
# Reexport for cargo_build_script_wrapper.bzl
|
||||
name_to_crate_name = _name_to_crate_name
|
||||
|
@ -70,6 +79,29 @@ def _pwd_flags(args):
|
|||
res.append(arg)
|
||||
return res
|
||||
|
||||
def _feature_enabled(ctx, feature_name, default = False):
|
||||
"""Check if a feature is enabled.
|
||||
|
||||
If the feature is explicitly enabled or disabled, return accordingly.
|
||||
|
||||
In the case where the feature is not explicitly enabled or disabled, return the default value.
|
||||
|
||||
Args:
|
||||
ctx: The context object.
|
||||
feature_name: The name of the feature.
|
||||
default: The default value to return if the feature is not explicitly enabled or disabled.
|
||||
|
||||
Returns:
|
||||
Boolean defining whether the feature is enabled.
|
||||
"""
|
||||
if feature_name in ctx.disabled_features:
|
||||
return False
|
||||
|
||||
if feature_name in ctx.features:
|
||||
return True
|
||||
|
||||
return default
|
||||
|
||||
def _cargo_build_script_impl(ctx):
|
||||
"""The implementation for the `cargo_build_script` rule.
|
||||
|
||||
|
@ -244,7 +276,7 @@ def _cargo_build_script_impl(ctx):
|
|||
build_script_inputs.append(dep_build_info.out_dir)
|
||||
|
||||
experimental_symlink_execroot = ctx.attr._experimental_symlink_execroot[BuildSettingInfo].value or \
|
||||
feature_enabled(ctx, SYMLINK_EXEC_ROOT_FEATURE)
|
||||
_feature_enabled(ctx, "symlink-exec-root")
|
||||
|
||||
if experimental_symlink_execroot:
|
||||
env["RULES_RUST_SYMLINK_EXEC_ROOT"] = "1"
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
"""Feature helpers."""
|
||||
|
||||
def feature_enabled(ctx, feature_name, default = False):
|
||||
"""Check if a feature is enabled.
|
||||
|
||||
If the feature is explicitly enabled or disabled, return accordingly.
|
||||
|
||||
In the case where the feature is not explicitly enabled or disabled, return the default value.
|
||||
|
||||
Args:
|
||||
ctx: The context object.
|
||||
feature_name: The name of the feature.
|
||||
default: The default value to return if the feature is not explicitly enabled or disabled.
|
||||
|
||||
Returns:
|
||||
Boolean defining whether the feature is enabled.
|
||||
"""
|
||||
if feature_name in ctx.disabled_features:
|
||||
return False
|
||||
|
||||
if feature_name in ctx.features:
|
||||
return True
|
||||
|
||||
return default
|
|
@ -1,7 +1,7 @@
|
|||
"""Analysis tests for cargo_build_script."""
|
||||
|
||||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
|
||||
load("//cargo:cargo_build_script.bzl", "cargo_build_script")
|
||||
load("//cargo:defs.bzl", "cargo_build_script")
|
||||
load("//rust:defs.bzl", "rust_library")
|
||||
|
||||
DepActionsInfo = provider(
|
||||
|
|
Loading…
Reference in New Issue