jrandolf opened PR #14927 from jrandolf:bindgen-map-type-option to bytecodealliance:main:
This builds on #14870, so only the last commit is new here.
This adds a
map_typeoption tobindgen!to choose the Rust type used for WIT maps, such asmap_type: std::collections::HashMapormap_type: indexmap::IndexMap. It mirrors the guest-side wit-bindgen option, including itsBTreeMapdefault (see the discussion on #14837).BTreeMapis available withoutstd, so the generated code no longer depends on the features Wasmtime is built with, which fixes #14830. It also makesadditional_derivessuch asHashandOrdwork for records containing maps.This changes the signatures generated for maps, which are only usable with the component model's map feature, which is off by default.
Closes #14830
Closes #14832<details>
<summary>LLM summary of the changes</summary>Option (
component-macro/src/bindgen.rs,wit-bindgen)
map_typetakes a path to a type with<K, V>parameters, likewasmtime_cratetakes a path. Without it, maps areBTreeMap, referenced through Wasmtime's__internalre-exports so it works fromno_stdcrates.RustGenerator::map_type_pathreturns the path, and both places that print map types use it: named map types, and themap()helper for anonymous ones from #14838.- A type alias works for a
HashMapwith a custom hasher. The path is used from within generated modules, so it should be absolute, for examplecrate::MyMap.Docs
The
bindgen!docs listmap_type's options:BTreeMap(the default),std::collections::HashMapandindexmap::IndexMap.Tests
- The map snapshots from #14834 are regenerated for the
BTreeMapdefault. Only the type changes.component-macro/tests/codegen.rschecks that the default bindings compile withadditional_derives: [Hash, PartialEq, Eq, PartialOrd, Ord]on a record containing a map, and that a custom-hasher alias works asmap_type.</details>
jrandolf removed the review request for wasmtime-core-reviewers from PR #14927.
jrandolf requested wasmtime-core-reviewers for a review on PR #14927.
jrandolf requested dicej for a review on PR #14927.
jrandolf removed the review request for wasmtime-default-reviewers from PR #14927.
jrandolf requested wasmtime-default-reviewers for a review on PR #14927.
jrandolf requested fitzgen for a review on PR #14927.
github-actions[bot] added the label wasmtime:api on PR #14927.
:thumbs_up: fitzgen submitted PR review:
Looks reasonable to me, thanks
fitzgen added PR #14927 Add a map_type option to bindgen!, defaulting to BTreeMap to the merge queue
fitzgen removed PR #14927 Add a map_type option to bindgen!, defaulting to BTreeMap from the merge queue
:check: fitzgen merged PR #14927.
Last updated: Oct 31 2026 at 23:03 UTC