-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit implements recognition of the `_initialize` function from WASIp1 in the componentization process of `wasm-tools component new`. This additionally corresponds to the same function in the proposed [BuildTargets.md](WebAssembly/component-model#378). This is implemented by having a small core wasm module which is just an import and a `start` section get instantiated at the end of a component to run `_initialize` before all other exports.
- Loading branch information
1 parent
0d8caf3
commit 108c37d
Showing
7 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
crates/wit-component/tests/components/initialize/component.wat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(component | ||
(core module (;0;) | ||
(type (;0;) (func)) | ||
(func (;0;) (type 0) | ||
unreachable | ||
) | ||
(func (;1;) (type 0) | ||
unreachable | ||
) | ||
(export "a" (func 0)) | ||
(export "_initialize" (func 1)) | ||
(@producers | ||
(processed-by "wit-component" "$CARGO_PKG_VERSION") | ||
(processed-by "my-fake-bindgen" "123.45") | ||
) | ||
) | ||
(core instance (;0;) (instantiate 0)) | ||
(alias core export 0 "_initialize" (core func (;0;))) | ||
(core module (;1;) | ||
(type (;0;) (func)) | ||
(import "" "" (func (;0;) (type 0))) | ||
(start 0) | ||
) | ||
(core instance (;1;) | ||
(export "" (func 0)) | ||
) | ||
(core instance (;2;) (instantiate 1 | ||
(with "" (instance 1)) | ||
) | ||
) | ||
(type (;0;) (func)) | ||
(alias core export 0 "a" (core func (;1;))) | ||
(func (;0;) (type 0) (canon lift (core func 1))) | ||
(export (;1;) "a" (func 0)) | ||
(@producers | ||
(processed-by "wit-component" "$CARGO_PKG_VERSION") | ||
) | ||
) |
5 changes: 5 additions & 0 deletions
5
crates/wit-component/tests/components/initialize/component.wit.print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package root:component; | ||
|
||
world root { | ||
export a: func(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
;; This test ensures that the `_initialize` function is hooked up to execute | ||
;; when the component is instantiated. | ||
(module | ||
(func (export "a") unreachable) | ||
(func (export "_initialize") unreachable) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package foo:foo; | ||
|
||
world module { | ||
export a: func(); | ||
} |