Allow overriding or omitting the revision metadata stamp

Offen
#409 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
76/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
rust
Bereich
build-system, cli

Rechercherichtung

Start with src/metadata.rs and add_component_metadata in src/lib.rs to trace how the current Git revision is resolved and stamped. Then review tests/build.rs and add coverage for the requested manifest and environment precedence, omission, validation, and rebuild cases. Done when each case produces at most one revision section in the existing position, with the default behavior unchanged.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Since #383 (for #378), cargo-component always stamps the HEAD commit of the
package's git repository into the component's revision metadata section
(src/git.rs, and add_component_metadata in src/lib.rs, the
revision: git.map(...) field). There is no way to change or turn this off,
so identical sources built at different commits differ in bytes, and a build
outside git or from a source archive stamps nothing. That defeats
reproducible builds that compare or sign component bytes, and it makes the
stamp the HEAD commit even when the component's own sources did not change.

Today the only workaround is a post-build rewrite (wasm-tools strip --delete '^revision$' then wasm-tools metadata add --revision). That moves the
section to the end of the component, so its bytes differ from what
cargo-component would have produced with the same value.

Request: a setting to choose the revision, with a manifest form and an
environment form, the environment winning:

  • [package.metadata.component] revision = "<literal>" stamps the literal,
    and revision = false omits the section.
  • CARGO_COMPONENT_REVISION=<literal> stamps the literal, and an empty value
    omits the section. When set, it takes precedence over the manifest, so a
    build tool can stamp a source tree hash without editing the manifest.
  • With neither set, behavior is unchanged: the HEAD commit.

Every case yields at most one revision section, in the position
cargo-component already uses, and a literal or a disable never consults git.

We carry this in a fork (https://github.com/attackordie/cargo-component/tree/feat/revision-setting) and would be glad to send it as a PR if the shape is
acceptable: about 115 added lines in src/metadata.rs (a RevisionSetting with a
custom deserializer that accepts a non-empty string or false) and
src/lib.rs (a resolve_revision step before add_component_metadata),
plus integration tests in tests/build.rs for the default, a manifest
literal, a manifest disable, a rejected revision = true, the environment
over the manifest, an empty environment value, and a re-stamp on a fresh
rebuild.

Searched existing issues and PRs for revision, revision section, git commit
hash, deterministic, source hash and CARGO_COMPONENT_REVISION: only #378
(closed, the request that added the stamp) and #383 (merged, its
implementation) came up.

Vorherrschende Sprache
Rust
Sterne
593
Forks
68
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus bytecodealliance/cargo-component

Alle Issues in bytecodealliance/cargo-component

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.