rust-lang / rust-lang/cargo

Allow applying static code-generation to the published package (i.e. `package.rs`)

Open
#12,552 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request Command-package Command-publish S-needs-design
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

Cases not covered:

  • Local development of a package that uses build.rs or 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.