bazelbuild / bazelbuild/rules_rust

Persistent worker for Rust rules

Open
#412 14 comments 10 reactions 0 assignees View on GitHub
enhancement needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

Hello,

I have a simple [persistent worker](https://github.com/nikhilm/rustc-worker) for Bazel that I've been playing with on some small projects.

Would the Rust rules be interested in integrating this? Since rustc does not support Java/TypeScript/Scala like "Compiler as an API", this really only takes advantage of in-crate incremental compilation introduced in rust 1.24. This is achieved by passing `--codegen=incremental=/path/to/dir`. The directory is named using a combination of `hash(path to rustc wrapper)` and the workspace name, with the goal of:
1. Being shared across multiple worker instances when they are spawned by Bazel. This is why one cannot use something like the `tempdir` crate (would be deleted each time a worker shut down) or just a randomly named temp file (would not be shared across worker processes).
2. Not being shared across workspaces.
3. Not being shared across compiler updates. This should probably actually depend on the path to rustc itself, instead of the wrapper. I can fix that.

The questions I have are:
1. Is this kind of cache sharing sound design? I don't know enough of Bazel internals nor rustc internals to have high confidence in answering yes to this.
2. Since this project is itself in Rust, how would something like this be integrated into the rules? Options:
1. Use pre-built binaries built with Cargo. (What I'm doing now for simplicity.)
2. Re-write in C++.
3. Have certain _internal_ switches to the Rust rules to build the worker itself using the rustc wrapper directly.

If this all sounds reasonable, I can send relevant PRs.
In particular, it would also be nice to have the worker and the current process wrapper combine their functionality so that an additional process spawn is saved (Go from `worker -> process wrapper -> rustc` to `worker -> rustc`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.