facebook / facebook/buck2

Feature: act as Make job server when executing locally

オープン
#653 コメント 0 件 リアクション 7 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Rust
スター
4.4k
フォーク
394
PR マージ指標
30日以内にマージされた PR はありません

説明

If you are building a lot of rust crates locally, they are all going to spin up at least a bunch of LLVM threads, and in future (or with nightly) they will [also spin up a bunch of threads](https://github.com/rust-lang/rust/issues/113349) for the rustc frontend. This is a bit of an issue because buck2 will saturate its own job queue's frontier (e.g. 8 concurrent builds with `-j8`) and then each of those `rustc` invocations will try to use as many threads as it can. You can often saturate N cores by passing `-j` with N/2 or so. Which means in the usual case of `-jN`, you are really scheduling about N^2 threads at once, which is surely not great.

There is an existing protocol for limiting the parallelism of individual build actions: the GNU Make jobserver: https://www.gnu.org/software/make/manual/html_node/Job-Slots.html. Rustc and I presume a number of other build tools are able to use the jobserver if you provide the environment variable (e.g. `MAKEFLAGS=--jobserver-auth=...`), and do the pipe IO / windows IPC serving. This is what tools like `cargo` do, and of course `make` itself. Ultimately all the participating processes share a single semaphore.

See [here](https://github.com/rust-lang/rust/blob/587af910459fe408f03e004d264fdf218203849d/compiler/rustc_interface/src/util.rs#L123) for where rustc acquires and releases jobserver tokens.

The jobserver crate has a type `Client` that also acts as a server. If you call `Client::new` when starting a build, pass in the buck2 CLI's `-j` flag, and use its methods to attach the environment variables to local execution processes, you are basically done.

https://docs.rs/jobserver/latest/jobserver/struct.Client.html#method.new

I am sure Meta will not care about this, given you scale your builds horizontally as parallel as you like, but it would be pretty helpful for OSS builds.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start with the jobserver crate's Client::new documentation and the linked rustc_interface/src/util.rs section to understand token acquisition. Trace Buck2's local execution path and its -j handling, then attach the jobserver environment to local processes. Done means local rustc and other participating tools share the configured parallelism limit.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
build-system
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。