Skip to content

Add fe build --from-metadata to rebuild from a metadata.json input#1513

Open
cburgdorf wants to merge 1 commit into
argotorg:masterfrom
cburgdorf:from_metadata
Open

Add fe build --from-metadata to rebuild from a metadata.json input#1513
cburgdorf wants to merge 1 commit into
argotorg:masterfrom
cburgdorf:from_metadata

Conversation

@cburgdorf

Copy link
Copy Markdown
Collaborator

fe build --emit metadata produces a complete, deterministic recompilation input, but the reverse step existed only as a test helper. External toolchains (foundry-compilers, Sourcify-style verifiers) need it as a CLI feature: one invocation, JSON in, artifacts out.

fe build --from-metadata <PATH|-> (- reads stdin) materializes the recorded project (regenerated fe.toml per settings.ingots[] entry, sources routed by namespace) into a temporary directory and runs the normal ingot build on it:

  • default target is the settings.compilationTarget contract; --contract overrides
  • optimizer level comes from settings.optimizer.level; an explicit -O wins with a stderr warning that the bytecode deviates
  • compiler.version mismatch warns on stderr without aborting
  • artifacts follow --emit into --out-dir, defaulting to ./out
  • invalid input (bad JSON, language != "Fe", missing sources/ingots) exits 1; combining with [path], --ingot, --standalone, or --report is a clap conflict (exit 2)

The reconstruction lives in crates/fe/src/metadata_input.rs and validates untrusted input (no path traversal out of the temp dir). The round-trip tests now exercise the CLI feature directly; the test helper is removed. New tests cover stdin, target selection, the -O and version warnings, and the error cases.

@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cf21e4478

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fe/src/metadata_input.rs Outdated
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2851b32faf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fe/src/metadata_input.rs Outdated
`fe build --emit metadata` produces a complete, deterministic
recompilation input, but the reverse step existed only as a test helper.
External toolchains (foundry-compilers, Sourcify-style verifiers) need
it as a CLI feature: one invocation, JSON in, artifacts out.

`fe build --from-metadata <PATH|->` (`-` reads stdin) materializes the
recorded project (regenerated fe.toml per settings.ingots[] entry,
sources routed by namespace) into a temporary directory and runs the
normal ingot build on it:

- default target is the settings.compilationTarget contract;
  --contract overrides
- optimizer level comes from settings.optimizer.level; an explicit -O
  wins with a stderr warning that the bytecode deviates
- compiler.version mismatch warns on stderr without aborting
- artifacts follow --emit into --out-dir, defaulting to ./out
- invalid input (bad JSON, language != "Fe", missing sources/ingots)
  exits 1; combining with [path], --ingot, --standalone, or --report
  is a clap conflict (exit 2)

The reconstruction lives in crates/fe/src/metadata_input.rs and
validates untrusted input (no path traversal out of the temp dir). The
round-trip tests now exercise the CLI feature directly; the test
helper is removed. New tests cover stdin, target selection, the -O
and version warnings, and the error cases.
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@cburgdorf cburgdorf marked this pull request as ready for review July 8, 2026 18:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ccec5d164

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fe/src/build.rs
Comment on lines +337 to +339
if let Some(version) = metadata["compiler"]["version"].as_str() {
let running = env!("CARGO_PKG_VERSION");
if version != running {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Warn when compiler.commit differs

When metadata includes a compiler.commit from a different Fe build but the same CARGO_PKG_VERSION, this version-only check treats it as a match and emits no warning. The metadata writer records compiler.commit specifically to distinguish non-release builds that share the package version, so verifiers can silently rebuild with a different compiler revision and get mismatched bytecode without a diagnostic; please compare the recorded commit with FE_GIT_HASH when it is present.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant