refactor: extract filesystem-free core into crates/core - #70
Conversation
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.
|
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
left a comment
There was a problem hiding this comment.
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.
| /// [`WitSource`] (for inputs) or to the output directory (for generated code). | ||
| #[derive(Clone, Debug)] | ||
| pub struct File { | ||
| pub path: String, |
There was a problem hiding this comment.
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.
|
Ah jeez, you know what? The split is already upstream. I'm going to rework this |
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-corecrate.src/utils.rsandsrc/cmd_bindings.rsbecome thin filesystem wrappers over it.WIT inputs reach the core as
(path, contents)pairs, soutils::parse_witnow reads the filesystem intoWitSources and delegates. Resolution usesResolve::push_groupsrather thanpush_path: aSourceMapholds 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-providercrate instead of the 52 KB binary checked in atsrc/wasi_snapshot_preview1.reactor.wasm, so updating it is a version bump. The committed copy was provider 46 whiletests/had already moved to wasmtime 47, so this also corrects that drift.gofmtmoves 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/wasip2output 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-bindgenversion stamp was left stale by the bump in #69.