-
Notifications
You must be signed in to change notification settings - Fork 105
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
How to combine features, platform and dependencies ? #326
Comments
Hey, hope this hasn't been a blocker for you. I'm not entirely sure how to solve this. Have you had more time to think about the idea you had?
Very interested in how this might be solved 😄 |
No I didn't find a good enough idea to translate this behavior into bazel, except maybe creating a custom function that generate the features & dependencies list instead of using select. (I'll see if it's doable after vacations, I'm new to bazel & starlack so I don't know if it's doable and how). Currently in my "test" project I call cargo from bazel (far to be optimal :-(, because everything (code + deps) is rebuild each time) genrule(
name = "wasm",
srcs = glob([
"Cargo.*",
"src/*.rs",
]),
outs = ["game.wasm"],
cmd_bash = """
pushd game
cargo build --features web --target wasm32-unknown-unknown --release
popd
cp game/target/wasm32-unknown-unknown/release/game.wasm $@
""",
) |
Could I get you to move this issue to rules_rust 🙏? I think it represents either a gap in functionality or a lack of clarity in how features are expected to interact with dependencies. If there's an expected pattern for these situation then I don't think it'll be too difficult to update |
Oooooh, I think I see what's going on here. That is an interesting one for sure. When rendered, the rust_library(
name = "winit",
srcs = glob(["**/*.rs"]),
aliases = {
"@raze__web_sys__0_3_45//:web_sys": "web_sys",
},
crate_features = [
"default",
"mio",
"mio-extras",
"parking_lot",
"percent-encoding",
"sctk",
"wasm-bindgen",
"wayland",
"wayland-client",
"web-sys",
"web_sys",
"x11",
"x11-dl",
],
crate_root = "src/lib.rs",
crate_type = "lib",
data = [],
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-raze",
"manual",
],
version = "0.24.0",
# buildifier: leave-alone
deps = [
"@raze__bitflags__1_2_1//:bitflags",
"@raze__instant__0_1_9//:instant",
"@raze__lazy_static__1_4_0//:lazy_static",
"@raze__libc__0_2_81//:libc",
"@raze__log__0_4_11//:log",
"@raze__raw_window_handle__0_3_3//:raw_window_handle",
] + selects.with_or({
# cfg(target_arch = "wasm32")
(
"@io_bazel_rules_rust//rust/platform:wasm32-unknown-unknown",
"@io_bazel_rules_rust//rust/platform:wasm32-wasi",
): [
"@raze__wasm_bindgen__0_2_68//:wasm_bindgen",
"@raze__web_sys__0_3_45//:web_sys",
],
"//conditions:default": [],
}),
) Now I'm wondering if this can be solved with what @davidB was saying in the first post, a I think my earlier comment is irrelevant now. But I'm not sure how best to solve this and would love some input here. How does cargo handle this? |
I did some search, and read the interesting thread Add cargo_crate repository rule · Issue #2 · bazelbuild/rules_rust . And I didn't found a response to the following question (that is also valid for a full mono-repo) :
Until we'll be able to identify a target that correspond to a package with features X,Y; we'll not be able to include it into a "cleany" because:
If you have pointer, idea, I'm interested in |
If I understand correctly https://github.com/google/cargo-raze/blob/master/impl/src/rendering/templates/partials/build_script.template every features are enabled by only dependencies from "default" features are included. Maybe a bug ? |
Maybe I misunderstand this but when cargo resolves a build graph and finds that there are multiple dependents that require different features of a specific dependencies, the dependency is built once with all those features enabled. Other use cases can be found here: https://doc.rust-lang.org/cargo/reference/unstable.html#features |
It looks like that list is from a cargo-raze/impl/src/planning/subplanners.rs Line 388 in 00fc4bb
|
Not all the features but the addition of features set requested, and cargo can choose to build a transitive crate several times, it allows to have several version of a the same crate in the dependency graph (vs other dependency resolver) About the code resolved dependency graph, I'll take a deeper look, but cargo-raze seems to use cargo-metadata that do the resolution based on the list of requested top level features (so once again only have one deps for all features set on transitive deps will not work) extract from cargo_metadata doc: let _metadata = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.features(CargoOpt::AllFeatures)
.exec()
.unwrap(); Maybe I'm wrong, I don't know the internal of cargo-raze (I'll look into), just intuition based on the output. |
It currently does use a list of crates for it's generation. There's #282 which tracks work on updating |
I'll take a look to this issue, |
This is something I've been meaning to dig into deeper after I opened bazelbuild/rules_rust#405. But in my experience with Bazel, I believe that statement is true in general. The way around this is likely related to transitions and some wrapper rule for your targets. But I may not be aware of better ways of doing this. |
I bumped into this with
Now I don't think this is possible to do with current cargo raze, so I did a quick hack showing how this could look like: Any chances to add these kinds of escape hatches to cargo raze? I'd presume this would be useful for features too. |
Hi,
I used crates where the same dependencies is defined with different "feature" for different target platform.
eg in
Cargo.toml
of bevy_winitbecome
So it failed because:
on bazel side because winit is listed twice:
on runtime (I guess because expected features will not be enabled)
If anyone have a immediate solution, please share. Else I would like to know/discuss how this kind of behavior could be translated into bazel (and later implemented into cargo-raze, I could try to make a PR) ?
select
into the generation ofcrate_features
?The text was updated successfully, but these errors were encountered: