The last piece of work really required to get off ...
# development
b
The last piece of work really required to get off the ground with the Pants-compiles-its-engine would be incremental compilation. 🧠 šŸŒ§ļø in 🧵
My current thinking could be to leverage https://github.com/mozilla/sccache (see also https://doc.rust-lang.org/cargo/guide/build-cache.html#shared-cache). The idea being we stick this in a named cache. The one big gotcha would be (form this doc)
The local storage only supports a single sccache server at a time. Multiple concurrent servers will race and cause spurious build failures.
So we'd need to do something similar to what we do for mypy. So I think the only missing piece is how a
shell_command
gets its hands on a named cache. I'm thinking we maybe do it in a hidden field or plugin, since there's implciations of opening this up I don't want to have to explore yet.
w
i don’t think that
sccache
is for incremental compilation: only for per-crate compilation
b
I can try it again, but my last test showed it did allow us to bypass re-compiling all of our dependencies in a sandbox
w
right: that’s a per-crate compilation cache, rather than a cache of incremental compilation (which is intra-crate)
b
Maybe "incremental" wasn't the right word, then? Are you saying that there'd be no benefit to
sccache
? Or that unlocking this "incremental" compilation would be better than using
sccache
?
w
example: when compiling the
engine
crate in
MODE=debug
for the first time, it takes ~2 mins on my machine: the second time it takes about 6 seconds
there would be a benefit to
sccache
at the per-crate level: it just doesn’t cache incremental compilation for single crates.
b
I'm not sure I completely follow šŸ˜… It seems though like we'd want
sccache
for better 3rdparty and
incremental
for our own code?
w
right
but i raise it, because i expect that the only way to have incremental compilation would be to stash (a portion of) the
target
directory… at which point
sccache
might no longer be necessary.
b
OK, so either way seems like we need a named cache šŸ™‚ Then the question is just if the incremental compilation cache is named-caches-safe šŸ™‚
w
i know that they use file locking, but replies to this question suggest that some of the portions of the directory are not safe for sharing (the final outputs): https://stackoverflow.com/questions/58669482/is-it-okay-to-use-a-single-shared-directory-as-cargos-target-directory-for-all
…but similar to the
mypy
cache, it’s possible that you could have the named cache exist at a path that was dependent on the project being built
b
But seems like concurrent runs for a single workspace is OK
w
yea
Ah but features seem to be the issue. There's also this, which I don't grok: https://docs.rs/cargo-hakari/latest/cargo_hakari/about/index.html
w
yea. i think that a project-specific directory would be a good defense.
b
Which is technically free if we just don't expose our little named cache to anything but this specific purpose šŸ˜›
So, all of this now centers around: How can I get a little named cache for myself just for this specific purpose in a
shell_command
šŸ˜›
w
which i think is definitely a useful feature, and also presents more subtlety than we might have imagined at first. the named cache setting would have to be an enum
ā€œper_targetā€, ā€œper_buildrootā€, ā€œglobalā€ā€¦
b
Well, specifically I'm interested in a hack, so that we dont have to make these kinds of decisions now šŸ™‚
I'm thinking we maybe do it in a hidden field or plugin, since there's implciations of opening this up I don't want to have to explore yet.
b
I’ve been iterating on some rust code and quickly had like 50GB of artifacts in my target/debug directory (https://github.com/pantsbuild/pants/issues/9823). So, I’d be a bit concerned about a slightly-hidden truly append-only cache quickly expanding to consume the universe, and it being non-obvious how to resolve it, eg conventional rust tools/knowledge doesn’t apply (although conventional pants knowledge does) Thus, focusing on sccache for crate-level caching seems like a good path forward, because it can impose a max size on the cache and manage it itself. We can work out how to get cargo’s incremental compilation going in future (I hope we’ll keep
./cargo …
working outside the sandbox so we can keep the incrementality when building/testing rust directly)
I’d suggest a field that’s public/documented but labelled
experimental
in the name, somehow, and it’s up to users to use it right (but we keep it experimental to reserve the right to make it easier to use correctly). Potentially just takes a string with a couple of basic substitutions, eg
experimental_cache_dir="{buildroot_id}/rust-sccache"
would end up as a per-buildroot dir.
w
@broad-processor-92400 : There is a ticket about reifying the
named_caches
a bit more... that same concern applies to ~everything in there.
I.e., exposing it to a
pants gc
goal
šŸ‘ 1
g
There's also this, which I don't grok: https://docs.rs/cargo-hakari/latest/cargo_hakari/about/index.html
It generates a crate which gathers all things that have features, and then makes everyone depend on that. So just fixes the issue of different feature-flags on different
-p crate
invocations leading to unnecessary compilation times. Also, does this mean that proper rust support is in the works too? :o
b
Not from me, nope šŸ™‚
g
Ah, hmm. So what does
Pants-compiles-its-engine
mean then? šŸ˜› Just a more narrow support for that specific use-case?
g
Hah, right. A bit more narrow.
b
Not sure how
cargo
invokes
sccache
, but we maybe looking at a red herring:
The sccache command will spawn a server process if one is not already running,
There's also this:
Incrementally compiled crates cannot be cached. By default, in the debug profile Cargo will use incremental compilation for workspace members and path dependencies. You can disable incremental compilation.
So... here' what I'm thinking
For compiling the engine, we take a two-pronged approach: • If
MODE=debug
. It's all local tools, incremental, and completely out of Pants ā—¦ We still use the Pants sandbox fingerprint for the metadata though. We can make sure the
MODE
makes it in that fingerprint • Otherwise, it's all Pants (leveraging
sccache
) ā—¦ This benefits CI, and people who aren't banging on the engine (because they're likely setting
MODE
anyways)
Welp, looks like
sccache
is caching the path to the
cc
compiler, which in this case would be the binary shim in the sandbox for the previous run. Fun stuff
Oh and
cargo
as well 😵
😵 1