-
Notifications
You must be signed in to change notification settings - Fork 2.9k
During cargo publish, verify that src directory is not modified by the build.rs #5073
Copy link
Copy link
Closed
Labels
A-build-scriptsArea: build.rs scriptsArea: build.rs scriptsCommand-publishS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or review
Description
A common pitfall when doing build.rs code generation in Rust is to write generated files directly to /src. It may seem fine on the first blush, but it does cause problems when you use such crate as a dependency, because there's an implicit invariant that sources in .cargo/registry should be immutable. Breaking this invariant sometimes is fine, but sometimes leads to pretty bewildering bugs:
- Error during
cargo doc. abonander/mime_guess#31 - Unable to depend on larlpop from read-only vendor directory lalrpop/lalrpop#272
So, I think we, first of all, should formally declare and document that build scripts should not modify stuff outside of OUT_DIR. We can enforce this rule during pre-flight check in cargo publish, by making the directory with sources read-only before the build. That is, in this line, we should add an equivalent of chown ua-w -r dst.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-build-scriptsArea: build.rs scriptsArea: build.rs scriptsCommand-publishS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or review
Type
Fields
Give feedbackNo fields configured for issues without a type.