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

Building the standard library from source #2907

Open
lylythechosenone opened this issue Sep 30, 2024 · 4 comments
Open

Building the standard library from source #2907

lylythechosenone opened this issue Sep 30, 2024 · 4 comments

Comments

@lylythechosenone
Copy link

Goals

Build libcore, liballoc, and their dependencies from source using rules_rust, preferably with bzlmod.

Reasoning

When compiling to bare-metal targets, as well as custom targets, one is required to recompile the standard library from source. Currently, this is not well-supported by rules_rust.

Prior art

In bazel-rust-cross, @colatkinson implemented this using rust_repositories, although that rule is now deprecated.
In #2068, @daivinhtran made a first attempt at this, although it was quite bulky. It also manually downloaded the rust source files.

@lylythechosenone
Copy link
Author

lylythechosenone commented Oct 1, 2024

To make this more concrete, the only thing missing is an ability to fetch the rust-src component (as it is in rustup) along with a given toolchain. This was possible with rust_repositories, but does not seem to be possible with newer versions of rules_rust. Once those sources are available, it is as simple as making rust_library targets, making a rust_stdlib_filegroup, and creating a custom toolchain.

@lylythechosenone
Copy link
Author

I have created a proof-of-concept exposing this component in lylythechosenone/rules_rust. It seems to work correctly. However, downloading rust_src is useless for most users, so it would be nice to make it optional. I'll await a contributor's response on how exactly to do that.

@lylythechosenone
Copy link
Author

After playing with this a bit, it seems like more components would be needed. rust_toolchain_repository and rust_toolchain both take an exec_triple field, and it seems like it would be quite difficult to determine the exec triple in a MODULE file. It would be nice to contain this all inside of rules_rust in a simple build_std flag on rust_toolchain_repository or register_rust_toolchains. I may make another proof-of-concept implementing this soon, but I very much want contributor input on this issue.

@illicitonion
Copy link
Collaborator

@krasimirgg I think you have experience of bootstrapping a libstd with rules_rust, right?

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

No branches or pull requests

2 participants