Skip to content

refactor: extract filesystem-free core into crates/core - #70

Draft
ricochet wants to merge 1 commit into
bytecodealliance:mainfrom
ricochet:refactor-extract-core
Draft

refactor: extract filesystem-free core into crates/core#70
ricochet wants to merge 1 commit into
bytecodealliance:mainfrom
ricochet:refactor-extract-core

Conversation

@ricochet

@ricochet ricochet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Pulls the parts of componentize-go that are pure byte transformations: WIT resolution, Go bindings generation, WIT metadata embedding, and component encoding into a new componentize-go-core crate. src/utils.rs and src/cmd_bindings.rs become thin filesystem wrappers over it.

WIT inputs reach the core as (path, contents) pairs, so utils::parse_wit now reads the filesystem into WitSources and delegates. Resolution uses Resolve::push_groups rather than push_path: a SourceMap holds exactly one package, so dependency packages are parsed separately and topologically sorted gainst the root.

The preview1 adapter is sourced from wasmtime's wasi-preview1-component-adapter-provider crate instead of the 52 KB binary checked in at src/wasi_snapshot_preview1.reactor.wasm, so updating it is a version bump. The committed copy was provider 46 while tests/ had already moved to wasmtime 47, so this also corrects that drift.

gofmt moves out of bindings generation and into the native driver, applied to the emitted files. Generation no longer shells out, which is what will let the core compile without a process API.

examples/wasip2 output has an identical import/export surface and identical size before and after; the remaining byte differences are internal to the newer adapter.

Also refreshes three checked-in fixture bindings whose wit-bindgen version stamp was left stale by the bump in #69.

Pulls the parts of componentize-go that are pure byte transformations: WIT
resolution, Go bindings generation, WIT metadata embedding, and component
encoding into a new `componentize-go-core` crate. `src/utils.rs` and
`src/cmd_bindings.rs` become thin filesystem wrappers over it.

WIT inputs reach the core as `(path, contents)` pairs, so `utils::parse_wit`
now reads the filesystem into `WitSource`s and delegates. Resolution uses
`Resolve::push_groups` rather than `push_path`: a `SourceMap` holds exactly one
package, so dependency packages are parsed separately and topologically sorted
against the root.

Two things move as a consequence:

- The preview1 adapter is sourced from wasmtime's
  `wasi-preview1-component-adapter-provider` crate instead of the 52 KB binary
  checked in at `src/wasi_snapshot_preview1.reactor.wasm`, so updating it is a
  version bump. The committed copy was provider 46 while `tests/` had already
  moved to wasmtime 47, so this also corrects that drift.

- `gofmt` moves out of bindings generation and into the native driver, applied
  to the emitted files. Generation no longer shells out, which is what will let
  the core compile without a process API.

`examples/wasip2` output has an identical import/export surface and
identical size before and after; the remaining byte differences are
internal to the newer adapter.

Also refreshes three checked-in fixture bindings whose `wit-bindgen` version
stamp was left stale by the bump in bytecodealliance#69.
@ricochet

Copy link
Copy Markdown
Contributor Author

Sort of an aside, but I'd like to make it so that the bindings are already gofmt compliant so that we don't have to run that at all.

@dicej dicej left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for doing this! I agree that this is a more flexible and portable way to structure the code.

I'd be interested to see if we could eventually upstream parts like push_source and read_wit_source into wit-parser given that those are generally useful and not specific to componentize-go.

Sort of an aside, but I'd like to make it so that the bindings are already gofmt compliant so that we don't have to run that at all.

That's a noble goal, but I expect it would require a non-trivial amount of additional bookkeeping in wit-bindgen-go. I'm not sure it would be worth the effort, but happy to be proven wrong.

Comment thread crates/core/src/lib.rs
/// [`WitSource`] (for inputs) or to the output directory (for generated code).
#[derive(Clone, Debug)]
pub struct File {
pub path: String,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: would it make sense to use std::path::Path here, given that it's meant to represent a filesystem path? That might make some of the string operations in push_source unnecessary, or at least more structured.

@ricochet

Copy link
Copy Markdown
Contributor Author

Ah jeez, you know what? The split is already upstream. I'm going to rework this

@ricochet
ricochet marked this pull request as draft July 31, 2026 18:31
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.

2 participants