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

Crate universe #1842

Closed
wants to merge 12 commits into from
Closed

Crate universe #1842

wants to merge 12 commits into from

Conversation

matts1
Copy link
Contributor

@matts1 matts1 commented Feb 20, 2023

Add support for crate universe with bzlmod to rules_rust.

Please ignore all commits by @cameron-martin as they're being reviewed seperately in github.com//pull/1528.

I'll change this from a draft PR into a real PR once his PR is merged.

@matts1
Copy link
Contributor Author

matts1 commented Feb 20, 2023

@gburgessiv FYI

)

for toolchain in mod.tags.toolchain:
repo_name = "%s_rust_toolchains" % mod.name
Copy link
Contributor

@cameron-martin cameron-martin Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you're making it so that the whole module graph can create and register its own toolchains, but isn't the set of available toolchains a global thing? I was under the impression that if all modules are allowed to register toolchains, toolchain resolution would pick the first valid one from this global set of toolchains and prevent the top-level module from controlling which version is used. That's why I originally made it so that only the top-level module can define toolchains, but maybe I'm misunderstanding how this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not particularly familiar with toolchains, so you could definitely be right. I was making the assumption that each module registered its own toolchains, and that, like use_repo, each module had its own visibility into the set of toolchains, and specifically used ones that they defined themselves?

Eg. I saw that your toolchain definition has the tag "edition". Since editions are specifically not backwards compatible, something designed for a 2018 edition might fail if compiled with a toolchain that specifies the 2021 edition.

@Wyverald Could you confirm how register_toolchain works? Is it global or per-module?

cameron-martin and others added 12 commits March 17, 2023 15:17
This is a rough proof of concept of making rules_rust load dependencies via bzlmod. Currently it can only compile and run rust crates, and cannot load crates from Cargo.toml.

There is one new module, `examples/bzlmod/hello_world`, that depends on the root `rules_rust` module. This example can be built and run using:

```
cd examples/bzlmod/hello_world
bazel run //:hello_world
```

A "hub" repository for toolchains is defined, and can be registered using:

```
register_toolchains("@rust_toolchains//:all")
```
When multiple modules each define different toolchain configurations, at
the moment, an arbitrary one wins and defines all the toolchains.

This change allows each different module to define as many different
toolchains as they want, each with a different set of configuration. If
the configuration is the same between modules, they will share their
toolchains.
This is required for bootstrapping cargo_bazel.
@matts1 matts1 closed this Mar 30, 2023
@matts1
Copy link
Contributor Author

matts1 commented Mar 30, 2023

Superceded by #1910

@cameron-martin cameron-martin mentioned this pull request Mar 31, 2023
@matts1 matts1 deleted the crate_universe branch November 10, 2023 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants