Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant/legacy cargo_build_script.bzl #2364

Merged
merged 1 commit into from
Dec 28, 2023
Merged
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
4 changes: 2 additions & 2 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
16 changes: 0 additions & 16 deletions cargo/cargo_build_script.bzl

This file was deleted.

10 changes: 5 additions & 5 deletions cargo/defs.bzl
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions cargo/features.bzl

This file was deleted.

File renamed without changes.
42 changes: 37 additions & 5 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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"
Expand Down
24 changes: 0 additions & 24 deletions cargo/private/features.bzl

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/build_script_deps/build_script_deps.bzl
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Loading