bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
654 stars 413 forks source link

Shard rules_rust into multiple bzlmod modules #2882

Open UebelAndre opened 3 days ago

UebelAndre commented 3 days ago

It seems to me that the MODULE.bazel file is getting a bit unwieldy and rust is having to declare dependencies for things not all users want or need. https://github.com/bazelbuild/rules_rust/blob/350d249ca2c976f92c96d63e4f89f9cf00965188/MODULE.bazel#L37-L45 https://github.com/bazelbuild/rules_rust/blob/350d249ca2c976f92c96d63e4f89f9cf00965188/MODULE.bazel#L63-L160 https://github.com/bazelbuild/rules_rust/blob/350d249ca2c976f92c96d63e4f89f9cf00965188/MODULE.bazel#L170-L180

To improve maintainability and to keep the dependency trees tight, I'm wondering if it'd be better to have different bzlmod extensions for the various packages within rules_rust. Concretely, I'm proposing that @rules_rust//bindgen become @rules_rust_bindgen and be an independent module developers can choose to include but it's dependencies would not be a part of @rules_rust.

The scope of the proposed changed:

before load after load
@rules_rust//bindgen @rules_rust_bindgen
@rules_rust//proto/protobuf @rules_rust_protobuf
@rules_rust//proto/prost @rules_rust_prost
@rules_rust//wasm_bindgen @rules_rust_wasm_bindgen

The @rules_rust//crate_universe, @rules_rust//cargo, @rules_rust//tools, and @rules_rust//util and any dependencies they may have would remain the same (in core @rules_rust).

I don't have strong opinions on changes to repo structure but I'm thinking it would be good to create an extensions directory where bindgen, proto, and wasm_bindgen could be moved into which I think would make it easier to add additional integrations down the line.

illicitonion commented 3 days ago

Sounds good to me!

I guess we would still release all of these at the same time (i.e. there would always be matching versions)? Or would we move to more granular releases of each?

I think my only concern is that we'll need to be a little careful around compatibility (e.g. if we add/remove attrs to crate_universe, we introduce compatibility hazards if people start using older rules_rust with newer bindgen or similar).

But I'm happy to do the splitting up and work out the exact details about compatibility in the future - the bzlmod ecosystem as a whole is still working out compatibility somewhat...

UebelAndre commented 3 days ago

I guess we would still release all of these at the same time (i.e. there would always be matching versions)? Or would we move to more granular releases of each?

I would keep everything at the same version and recommend folks keep them all in sync.

I think my only concern is that we'll need to be a little careful around compatibility (e.g. if we add/remove attrs to crate_universe, we introduce compatibility hazards if people start using older rules_rust with newer bindgen or similar).

Yeah, I figured this would be unlikely and we could advise folks to keep versions in sync.

But I'm happy to do the splitting up and work out the exact details about compatibility in the future - the bzlmod ecosystem as a whole is still working out compatibility somewhat...

If there are no major objections then I think it'd be good. Do you have thoughts on moving any code around? I could do some moves and add the commit to a .git-blame-ignore-revs file to keep history looking better.

illicitonion commented 3 days ago

Happy to move code around however makes sense :) Probably easier to discuss in a proposed PR?

konkers commented 3 days ago

Looks reasonable to me.