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

0.49.2 causes optional features to be enabled when they shouldn't be #2788

Closed
frxstrem opened this issue Aug 13, 2024 · 1 comment · Fixed by #2789
Closed

0.49.2 causes optional features to be enabled when they shouldn't be #2788

frxstrem opened this issue Aug 13, 2024 · 1 comment · Fixed by #2789

Comments

@frxstrem
Copy link

When bumping from 0.48.0 to 0.49.2, default features are enabled for targets that should not have them enabled, but optional dependencies that those features depend on are not.

My reproduction setup is a simple Rust binary with a single dependency, rstest 0.22.0 with default-features = false. It depends on rstest-macros, which also has default-features = false. The dependency is vendored with mode = "remote".

To vendor the packages, I am running the following command:

CARGO_BAZEL_REPIN=1 bazel run @@//:crates_vendor

When I rerun this command after bumping from 0.48.0 to 0.49.2, it produces the following changes:

diff --git a/crates/BUILD.rstest_macros-0.22.0.bazel b/crates/BUILD.rstest_macros-0.22.0.bazel
index 3df2355..a1ffb3f 100644
--- a/crates/BUILD.rstest_macros-0.22.0.bazel
+++ b/crates/BUILD.rstest_macros-0.22.0.bazel
@@ -29,6 +29,11 @@ rust_proc_macro(
             "WORKSPACE.bazel",
         ],
     ),
+    crate_features = [
+        "async-timeout",
+        "crate-name",
+        "default",
+    ],
     crate_root = "src/lib.rs",
     edition = "2021",
     rustc_flags = [
@@ -98,6 +103,11 @@ cargo_build_script(
         include = ["**/*.rs"],
         allow_empty = True,
     ),
+    crate_features = [
+        "async-timeout",
+        "crate-name",
+        "default",
+    ],
     crate_name = "build_script_build",
     crate_root = "build.rs",
     data = glob(

Since rstest and rstest-macros are both defined with default-features = false, these features should not be enabled. (This can be seen by looking at the Cargo.lock file, where they are not present.

Furthermore, the crate-name feature of rstest-macros depends on the proc-macro-crate package, which is not specified as a dependency in the generated BUILD.rstest_macros-0.22.0.bazel file, which causes the build to fail.

Expand error message
INFO: Invocation ID: 82f7b5ee-5ea7-415e-b262-aea406e9d480
INFO: Analyzed target //:hello_world (0 packages loaded, 2 targets configured).
ERROR: /private/var/tmp/_bazel/55bb84ce8634c54cea85dd8427296db4/external/crates_vendor__rstest_macros-0.22.0/BUILD.bazel:14:16: Compiling Rust proc-macro rstest_macros v0.22.0 (27 files) [for tool] failed: (Exit 1): process_wrapper failed: error executing Rustc command (from target @@crates_vendor__rstest_macros-0.22.0//:rstest_macros) bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_rust~/util/process_wrapper/process_wrapper --env-file ... (remaining 85 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error[E0432]: unresolved import `proc_macro_crate`
 --> external/crates_vendor__rstest_macros-0.22.0/src/render/crate_resolver.rs:6:13
  |
6 |         use proc_macro_crate::FoundCrate;
  |             ^^^^^^^^^^^^^^^^ use of undeclared crate or module `proc_macro_crate`

error[E0433]: failed to resolve: use of undeclared crate or module `proc_macro_crate`
 --> external/crates_vendor__rstest_macros-0.22.0/src/render/crate_resolver.rs:9:15
  |
9 |         match proc_macro_crate::crate_name("rstest").expect("rstest is present in `Cargo.toml` qed")
  |               ^^^^^^^^^^^^^^^^ use of undeclared crate or module `proc_macro_crate`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
Target //:hello_world failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.794s, Critical Path: 0.68s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

The workspace looks something like this (simplified significantly, but still reproducible):

Expand
src/
  main.rs
BUILD.bazel
Cargo.lock
Cargo.toml
MODULE.bazel
MODULE.bazel.lock
WORKSPACE
Cargo.toml
[package]
name = "bazel-test"
version = "0.1.0"
edition = "2021"

[dependencies]
rstest = { version = "0.22.0", default-features = false }
MODULE.bazel
bazel_dep(name = "rules_rust", version = "0.49.2")
WORKSPACE
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies")

rules_rust_dependencies()


load("//crates:defs.bzl", "crate_repositories")

crate_repositories()
BUILD.bazel
load("@rules_rust//crate_universe:defs.bzl", "crates_vendor")
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//crates:defs.bzl", "all_crate_deps")

crates_vendor(
    name = "crates_vendor",
    cargo_lockfile = "//:Cargo.lock",
    manifests = ["//:Cargo.toml"],
    mode = "remote",
    vendor_path = "crates",
)

rust_binary(
    name = "hello_world",
    srcs = ["src/main.rs"],
    deps = all_crate_deps(),
)
@illicitonion
Copy link
Collaborator

Sorry about this, and thanks for the report! Should be fixed in #2789 which I will release when merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants