Allow applying static code-generation to the published package (i.e. `package.rs`)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Problem
When code-generation happens within build.rs or proc macros,
- Arbitrary code is being run on the developer's machine
- The generated code is harder to audit
- Code-generator needs to be built by all dependents when the result is the same
Proposed Solution
A package.rs that runs like build.rs during local development but the output gets captured on cargo publish and it, along with its dependencies, are dropped
If this were combined with a .crate differ on crates.io, it would be easy for dependents (or even package maintainers) to audit the results.
Notes
Past discussions
Alternatives
- code-gen via snapshot testing which has more process overhead which is unappealing for high-churn code-gen
Cases not covered:
- Local development of a package that uses
build.rsor a proc macro still has to deal with arbitrary code execution and not easily seeing what gets generated
Complications
- Knowing which dependencies can be stripped
- Inability for dependents to control versions of the code-generator to get the result of bug fixes, requiring a new release
- proc-macros that have tight coupling between the macro and the package that re-exports it
- Capturing proc-macro expansion
- Not subject to feature flags
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the linked Internals and Zulip discussions, then trace Cargo's existing build.rs and cargo publish flows. Define how package.rs output and dependencies would be captured or removed, including the listed proc-macro, feature-flag, and dependency-version complications; done means a settled design for the proposed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, release
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100