Comments (1)
Here's a repro for the issue (tested with bazel 7.2.1):
-
WORKSPACE
:# Copyright 2024 Google LLC. # SPDX-License-Identifier: Apache-2.0 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_rust", integrity = "sha256-35cwdTOaqqu4y+aXgIUU2C2PAKMz4+uyJ7/UMIGCmFs=", url = "https://github.com/bazelbuild/rules_rust/releases/download/0.47.1/rules_rust-v0.47.1.tar.gz", ) load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") rules_rust_dependencies() rust_register_toolchains( edition = "2021", versions = ["1.78.0"], extra_target_triples = ["x86_64-unknown-none"], ) # rust_library requires a C++ toolchain supporting x86_64-unknown-none. http_archive( name = "aspect_gcc_toolchain", sha256 = "3341394b1376fb96a87ac3ca01c582f7f18e7dc5e16e8cf40880a31dd7ac0e1e", strip_prefix = "gcc-toolchain-0.4.2", url = "https://github.com/aspect-build/gcc-toolchain/archive/refs/tags/0.4.2.tar.gz", ) load("@aspect_gcc_toolchain//toolchain:repositories.bzl", "gcc_toolchain_dependencies") gcc_toolchain_dependencies() load("@aspect_gcc_toolchain//toolchain:defs.bzl", "ARCHS", "gcc_register_toolchain") gcc_register_toolchain( name = "gcc_toolchain_x86_64_unknown_none", extra_ldflags = ["-nostdlib"], target_arch = ARCHS.x86_64, target_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:none"], ) load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository") # anyhow builds: bazel build --platforms=//:x86_64-unknown-none --@rules_rust//:no_std=alloc @anyhow_crate_index//:anyhow crates_repository( name = "anyhow_crate_index", cargo_lockfile = "//:anyhow.lock", lockfile = "//:anyhow-lock.json", packages = { "anyhow": crate.spec(default_features = False, version = "1.0"), }, rust_version = "1.78.0", supported_platform_triples = ["x86_64-unknown-linux-gnu", "x86_64-unknown-none"], ) load("@anyhow_crate_index//:defs.bzl", anyhow_crate_repositories = "crate_repositories") anyhow_crate_repositories() # prost-types builds: bazel build --platforms=//:x86_64-unknown-none --@rules_rust//:no_std=alloc @broken_crate_index//:prost-types # anyhow now fails to build: bazel build --platforms=//:x86_64-unknown-none --@rules_rust//:no_std=alloc @broken_crate_index//:anyhow crates_repository( name = "broken_crate_index", cargo_lockfile = "//:broken.lock", lockfile = "//:broken-lock.json", packages = { "anyhow": crate.spec(default_features = False, version = "1.0"), "prost-types": crate.spec(default_features = False, version = "0.12"), }, rust_version = "1.78.0", supported_platform_triples = ["x86_64-unknown-linux-gnu", "x86_64-unknown-none"], ) load("@broken_crate_index//:defs.bzl", broken_crate_repositories = "crate_repositories") broken_crate_repositories()
-
BUILD
:# Copyright 2024 Google LLC. # SPDX-License-Identifier: Apache-2.0 platform( name = "x86_64-unknown-none", constraint_values = [ "@platforms//cpu:x86_64", "@platforms//os:none", ], )
Repro steps:
$ touch {anyhow,broken}{.lock,-lock.json} && CARGO_BAZEL_REPIN=1 bazel sync
$ bazel build --platforms=//:x86_64-unknown-none --@rules_rust//:no_std=alloc @anyhow_crate_index//:anyhow @broken_crate_index//:prost-types # succeeds
$ bazel build --platforms=//:x86_64-unknown-none --@rules_rust//:no_std=alloc @broken_crate_index//:anyhow # fails
...
error[E0463]: can't find crate for `std`
--> external/broken_crate_index__anyhow-1.0.86/src/lib.rs:251:1
|
251 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
|
= note: the `x86_64-unknown-none` target may not support the standard library
prost-types
depends on prost-derive
, which is a proc macro (i.e. provides compile-time codegen rules). prost-derive
depends on anyhow
with the std
feature -- which is okay because the usage only happens at compile time. But crates_repository
merges features across all dependencies -- including those reached via proc macros -- resulting in the std
feature being added to @broken_crate_index//:anyhow
(compare the anyhow
entries in anyhow-lock.json
and broken-lock.json
).
This is similar to #205, but in addition to building proc macros for the host platform, I believe dependencies of proc macros (or at least their features) also need to be isolated between the host and target platforms.
from rules_rust.
Related Issues (20)
- Support allow/forbid of unsafe code HOT 3
- Leftover rust-analyzer specs can cause generation to fail
- Dependency vendoring broken in 0.49.1 HOT 4
- bzlmod uses nightly by default
- Optional dependencies not respected in bzlmod
- Aliases not working rust-analyzer when rust_test for crate is defined HOT 3
- New wasi targets are invalid HOT 1
- custom proc macro crate not found in a cargo workspace setup HOT 3
- bindgen dependencies aren't setup correctly when using rules_rust with bzlmod HOT 2
- 0.49.2 causes optional features to be enabled when they shouldn't be HOT 1
- How do I access a `clippy` binary for running in my IDE
- Equivalent Method to Specify `--target=wasm32-unknown-emscripten`
- rust-analyzer via bazel documentation
- prost_toolchain.proto_compiler missing files_to_run? HOT 1
- Support for `--incompatible_use_plus_in_repo_names`
- Diesel Migration Panics HOT 2
- crates_universe vendor doesnt support additive_build_file?
- Regression: rust_prost_toolchain generates incorrect aliases on Linux / X86 HOT 3
- successful test being marked as failed
- Prost: Alias Proto Libraries cause crash
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_rust.