-
Notifications
You must be signed in to change notification settings - Fork 13
Include well-known source input dependencies for Rust compilation #51
Conversation
tl;dr: yes, but we should make it an optional (opt-out) thing to include the cargo file until we have means to measure the impact of such a change. We need it for the time being until
I think we generally need a way to measure these things :) the impact is sometimes rather surprising
We can't really assume this. There are codebases which do not use cargo, i.e. rust as part of C or C++ project.
🎉
Not entirly sure we'd have to repeat it, or if that hack would have to be part of the scale codec created code? Either way, this is a hack and I can see non-parity crates refusing to do such treachery.
For stable we have to do something in the meantime, 💯
The issue really is limited to renames combined with proc macro crates, right? So it should be rather limited I would assume (this is not a proof, prove me wrong!)?
I tried this before which seems quite similar mozilla/sccache#719 and it was closed, so I would not bother to do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Hm, that's a fair point, I guess you could technically Unfortunately, I verified that using the unnamed const trick, the included file ends up in the
Yes, the only reason in the first place for requiring Cargo.toml in our case is to detect renames via |
I wonder, taking a brief look, title says, about |
That's a fair question - in general, dependencies' lockfiles are ignored and only the lockfile of the primary package or the workspace is used. The lockfile is used as part of the dependency resolution, which happens on the client side - with dependencies resolved, the corresponding crate compilation requests are sent from the client to the build servers, so there's no need to transfer Cargo.lock anywhere for the build to happen/succeed. |
a84bf69
to
e8b9f8f
Compare
I guess this needs a sanity check beforehand if the file exists at all |
152f078
to
27eadba
Compare
Fixed in 27eadba |
27eadba
to
8aaf775
Compare
.map(|(_, value)| Path::new(value)); | ||
const KNOWN_AUX_DEP_FILES: &[(Option<&str>, &str)] = &[ | ||
(None, "Cargo.toml"), | ||
(Some("libp2p_wasm_ext"), "src/websockets.js"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those part of the includes = []
set in the manifest? But on the other handside there might be other rather large files as well 🧐 - I guess it's good as is.
We might want to consider to allow easy modification via env var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be included in the packaged and uploaded .crate
file to crates.io - otherwise, regular builds wouldn't be possible. The libp2p-wasm-ext
has no include
/exclude
, so by default it includes everything in directory IIRC.
Here's a list of files in the package:
xanewok@faerun-dev:~/repos/rust-libp2p/transports/wasm-ext (master)$ cargo package --list
.cargo_vcs_info.json
CHANGELOG.md
Cargo.toml
Cargo.toml.orig
src/lib.rs
src/websockets.js
We might want to consider to allow easy modification via env var?
Do you mean unconditionally including Cargo.toml for every package?
We have to include src/websockets.js
for libp2p-wasm-ext
, otherwise we can't ever build it via sccache-dist
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be included in the packaged and uploaded
.crate
file to crates.io - otherwise, regular builds wouldn't be possible. Thelibp2p-wasm-ext
has noinclude
/exclude
, so by default it includes everything in directory IIRC.
Here's a list of files in the package:xanewok@faerun-dev:~/repos/rust-libp2p/transports/wasm-ext (master)$ cargo package --list .cargo_vcs_info.json CHANGELOG.md Cargo.toml Cargo.toml.orig src/lib.rs src/websockets.js
I think that status quo of inclusion logic is good as is :)
We might want to consider to allow easy modification via env var?
Do you mean unconditionally including Cargo.toml for every package?
We have to includesrc/websockets.js
forlibp2p-wasm-ext
, otherwise we can't ever build it viasccache-dist
.
I meant more on the extensability front/generalization i.e. what if another crate pops up in the need of file? We want to have rather quick turnaround, so a CACHEPOT_EXTRA=$crate:$resource_path,..
might be something for a follow up PR (#idea) and I have a feeling that even with the deps tracking this might be a quick fix before it's going to be adopted in the ecosystem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that - yeah, that's definitely a good idea. I was thinking of introducing it in a configuration file but env var sounds easy/quicker for now 👍
@Xanewok all my comments can be addressed in a followup as needed, this is good for now and remedies a roadblock 👍 |
Awesome, thank you for your review! 🙏 |
This is a somewhat minor hack to fix compilation in the distributed scenario, where a package needs to read its own manifest file.
For more context, Cargo already packs the manifest and other
[package.include]
d files in the.crate
archive and in respective the.cargo/registry/src/<registry>/<package-id>
directory, however sccache relies only on the explicit dep-info created by rustc for a regular crate compilation. While technically correct for a "barebones" Rust crate, the packages compiled and distributed by Cargo may also implicitly depend on the additional, aforementioned packed files.This unconditionally marks
Cargo.toml
as the input for the Rust compilation, sincea) every Cargo package is known to have that file present in its crate archive/build environment
b) the manifest file is a relatively small text file so the overhead of packing it and transmitting it over the wire should be negligible
c) we don't use non-Cargo Rust crates (:warning: I need to test if it hard errors if there's not a Cargo.toml present for some crate)
d) this is 99% enough to get Substrate compiling
Alternatives
a) Use the
include_bytes!
with unnamed const trick:This works on stable but includes a file in the compilation output which may or may not be stripped; This would have to be repeated for every crate that uses
parity-scale-codec
(...that's too many)b) Wait for rust-lang/rust#84029 to land and use it in the nightly toolchain setting. That's the most straightforward solution but we'd only support the nightly toolchain and the time-to-stabilise might prove to be too long if we want to use sccache using a Rust stable toolchain.
c) Remove the rename-detection feature in
parity-scale-codec-derive
(breaking change but not sure if include that in stability guarantees) and migrate every crate that usesparity-scale-codec
to import it directly, without renaming tocodec
via Cargo.toml (or other names). This imposes a churn and there's not a reliable/elegant way to prevent someone from breaking the build as this issue only pops up when usingsccache
I'm 50-50 whether we should upstream this patch; ideally the crate developers should use rust-lang/rust#84029 directly when it lands on stable but always including the Cargo.toml manifest seems like it gives some degree of out-of-box support for Cargo packages without that big of a runtime cost.
EDIT: This now also includes the
src/websockets.js
forlibp2p-wasm-ext
which is needed for Substrate compilation and in general introduces a hard-coded list which additional files should be included based on its crate name (as a reasonable heuristic). In the future we might move that off to a separate configurable knob in the client configuration file if that seems like a better place for this kind of feature.