Add enumeration of allowed files for I/O at compile-time per-crate #13113
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-triage
Status: This issue is waiting on initial triage.
Problem
Hermetic builds in Cargo have been under the radar for a couple years (see #9506) -- this is intended to help move toward that direction.
When trying to produce hermetic builds, it is often necessary to enumerate the set of input files (for example, in the case of Bazel, the popular
rules_rust
rules set to help build Rust code requires specifying bothsrcs
files as well asdata
files in order to setup the private sandbox directory). It is possible to generate almost all of the configuration needed to produce a "almost-hermetic build" from a crate'sCargo.toml
+ workspace manifest + workspace lock file -- one gap is that there is currently no standard way of specifying the set of required files before compilation.This can also probably be extended to eventually cover file and network I/O more extensively later.
Proposed Solution
Manifest Format Changes
This proposes adding a new type of section to the crate manifest called
[resources]
, a similar section to the workspace manifest called[workspace.resources]
, as well as a new key to the[package]
section calledresource-mode
of typeString
. Here is an example manifest set:and here's what a workspace might look like:
This is intentionally meant to be similar to the
[dependencies]
section to also allow access to[resources]
to be feature-gated as well as be compatible with[target.cfg()]
syntax. In addition, it also allows for calculation ofchecksum
for inclusion in theCargo.lock
:And this is useful for extension later to remote resources or even local system library resources which are dynamically-linked to.
Behavior + Backward Compatibility
When
resource-mode = "checked"
, it means thatcargo
would emit a warning if a resource has a changed checksum -- this can be useful for when you are usinginclude_dir!
orinclude_bytes!
and want to make sure the included content is consistent.For backwards-compatibility, existing crates would have the key-value of
resource-mode = "none"
. This means that there would be no change to existing behavior.Notes
For the manifest above, it would be possible to generate viable Starlark manifest files for at least Bazel. For example, for a given static Rust crate compilation target, you could generate the rule:
And additional workspace-level, cross-crate used resources could be given first-class priority without having to compile them into a crate.
The text was updated successfully, but these errors were encountered: