Skip to content

Commit

Permalink
wit-bindgen and wasm-tools update, rebuild components
Browse files Browse the repository at this point in the history
  • Loading branch information
noise64 committed Jan 13, 2025
1 parent 06a7f0b commit b2dd826
Show file tree
Hide file tree
Showing 45 changed files with 485 additions and 720 deletions.
54 changes: 36 additions & 18 deletions golem-cli/src/diagnose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl Tool {
Tool::Cargo => ToolMetadata {
short_name: "cargo",
description: "Rust package manager",
version_requirement: MinimumVersion("1.80.1"),
version_requirement: MinimumVersion("1.84.0"),
instructions:
"See the rustup step above (https://www.rust-lang.org/learn/get-started)",
},
Expand Down Expand Up @@ -343,10 +343,10 @@ impl Tool {
Tool::ComponentizePy => ToolMetadata {
short_name: "componentize-py",
description: "Tool for converting Python applications to WebAssembly components",
version_requirement: ExactVersion("0.13.5"),
version_requirement: ExactVersion("0.16.0"),
instructions: indoc! {"
Install the following specific version:
pip install componentize-py==0.13.5
pip install componentize-py==0.16.0
For more information see:
https://github.com/bytecodealliance/componentize-py
Expand All @@ -363,7 +363,7 @@ impl Tool {
Tool::GolemSdkGo => ToolMetadata {
short_name: "golem-go",
description: "Golem SDK for Go",
version_requirement: MinimumVersion("0.7.0"),
version_requirement: MinimumVersion("1.1.0"),
instructions: indoc! {"
Add latest golem-go as dependency:
go get github.com/golemcloud/golem-go
Expand All @@ -375,7 +375,7 @@ impl Tool {
Tool::GolemSdkRust => ToolMetadata {
short_name: "golem-rust",
description: "Golem SDK for Rust",
version_requirement: MinimumVersion("1.0.0"),
version_requirement: MinimumVersion("1.1.0"),
instructions: indoc! {"
Add latest golem-rust as dependency:
cargo add golem-rust
Expand All @@ -384,7 +384,7 @@ impl Tool {
Tool::GolemSdkTypeScript => ToolMetadata {
short_name: "golem-ts",
description: "Golem SDK for JavaScript and TypeScript",
version_requirement: MinimumVersion("0.2.0"),
version_requirement: MinimumVersion("1.1.0"),
instructions: indoc! {"
Add latest golem-ts as dependency:
npm install --save-dev @golemcloud/golem-ts
Expand Down Expand Up @@ -443,7 +443,7 @@ impl Tool {
Tool::Rustc => ToolMetadata {
short_name: "rustc",
description: "Rust compiler",
version_requirement: MinimumVersion("1.80.1"),
version_requirement: MinimumVersion("1.84.0"),
instructions: indoc! {"
See the rustup step above (https://www.rust-lang.org/learn/get-started),
then install latest stable rust:
Expand Down Expand Up @@ -476,7 +476,7 @@ impl Tool {
Tool::TinyGo => ToolMetadata {
short_name: "tinygo",
description: "Go compiler for WebAssembly (and embedded systems)",
version_requirement: MinimumVersion("0.33"),
version_requirement: MinimumVersion("0.35"),
instructions: indoc! {"
Install latest TinyGo:
https://tinygo.org/getting-started/install/
Expand All @@ -489,8 +489,7 @@ impl Tool {
Tool::WasiSdk => ToolMetadata {
short_name: "wasi-sdk",
description: "WebAssembly toolchain for C and C++",
// NOTE: Version is not detectable currently, from 24.0 it will be stored in a version file
version_requirement: ExactByNameVersion("WASI_SDK set"),
version_requirement: MinimumVersion("25.0"),
instructions: indoc! {"
Install WASI SDK 23.0:
https://github.com/WebAssembly/wasi-sdk
Expand All @@ -501,25 +500,25 @@ impl Tool {
Tool::WasmTools => ToolMetadata {
short_name: "wasm-tools",
description: "Tools for manipulation of WebAssembly modules",
version_requirement: ExactVersion("1.210.0"),
version_requirement: ExactVersion("1.223.0"),
instructions: indoc! {"
Install the following specific version of wasm-tools:
cargo install --force --locked wasm-tools@1.210.0
cargo install --force --locked wasm-tools@1.223.0
"},
},
Tool::WitBindgen => ToolMetadata {
short_name: "wit-bindgen",
description: "Guest language bindings generator for WIT",
version_requirement: ExactVersion("0.26.0"),
version_requirement: ExactVersion("0.37.0"),
instructions: indoc! {"
Install the following specific version of wit-bindgen:
cargo install --force --locked wit-bindgen-cli@0.26.0
cargo install --force --locked wit-bindgen-cli@0.37.0
"},
},
Tool::Zig => ToolMetadata {
short_name: "zig",
description: "Zig language tooling",
version_requirement: MinimumVersion("0.13.0"),
version_requirement: MinimumVersion("0.14.0"),
instructions: indoc! {"
Install latest version of Zig:
https://ziglang.org/learn/getting-started/#installing-zig
Expand Down Expand Up @@ -604,9 +603,28 @@ impl Tool {
Tool::Rustup => cmd_version(dir, "rustup", vec!["--version"], &version_regex),
Tool::RustTargetWasm32WasiP1 => rust_target(dir, "wasm32-wasip1"),
Tool::TinyGo => cmd_version(dir, "tinygo", vec!["version"], &version_regex),
Tool::WasiSdk => std::env::var("WASI_SDK")
.map(|_| "WASI_SDK set".to_string())
.map_err(|_| "WASI_SDK no set".to_string()),
Tool::WasiSdk => {
let wasi_sdk_path = std::env::var("WASI_SDK_PATH")
.map_err(|_| "WASI_SDK_PATH not set".to_string())?;
let wasi_sdk_version_file = Path::new(&wasi_sdk_path).join("VERSION");
let versions = std::fs::read_to_string(&wasi_sdk_version_file).map_err(|err| {
format!(
"Failed to open {}: {}",
wasi_sdk_version_file.to_string_lossy(),
err
)
})?;
versions
.lines()
.next()
.ok_or_else(|| {
format!(
"Version not found in {}",
wasi_sdk_version_file.to_string_lossy()
)
})
.map(|version| version.to_string())
}
Tool::WasmTools => cmd_version(dir, "wasm-tools", vec!["--version"], &version_regex),
Tool::WitBindgen => cmd_version(dir, "wit-bindgen", vec!["--version"], &version_regex),
Tool::Zig => cmd_version(dir, "zig", vec!["version"], &version_regex),
Expand Down
1 change: 1 addition & 0 deletions test-components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.zig-cache
2 changes: 1 addition & 1 deletion test-components/auction-example/auction/wit/auction.wit
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface api {
auction-id: auction-id,
name: string,
description: string,
limit-price: float32,
limit-price: f32,
expiration: deadline,
}

Expand Down
Binary file modified test-components/auction_registry_composed.wasm
Binary file not shown.
44 changes: 37 additions & 7 deletions test-components/build-components.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

rust_test_components=("write-stdout" "write-stderr" "read-stdin" "clocks" "shopping-cart" "file-write-read-delete" "file-service" "http-client" "directories" "environment-service" "promise" "interruption" "clock-service"
"option-service" "flags-service" "http-client-2" "stdio-cc" "failing-component" "variant-service" "key-value-service" "blob-store-service" "runtime-service" "networking" "shopping-cart-resource"
Expand All @@ -12,7 +14,9 @@ dotnet_test_components=("csharp-1")
swift_test_components=("swift-1")
c_test_components=("c-1" "large-initial-memory" "large-dynamic-memory")
python_test_components=("python-1" "py-echo")
ts_test_components=("ts-rpc")

rust_test_apps=("auction-example" "rpc" "rust-service/rpc")
ts_test_apps=("ts-rpc")

# Optional arguments:
# - rebuild: clean all projects before building them
Expand Down Expand Up @@ -107,6 +111,28 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "rust" ]; then
done
fi

if [ "$single_lang" = "false" ] || [ "$lang" = "rust" ]; then
echo "Building the Rust test apps"
for subdir in "${rust_test_apps[@]}"; do
echo "Building $subdir..."
pushd "$subdir" || exit

if [ "$update_wit" = true ] && [ -f "wit/deps.toml" ]; then
wit-deps update
fi

if [ "$rebuild" = true ]; then
golem-cli app clean
cargo clean
fi

golem-cli app -b release build
golem-cli app -b release copy

popd || exit
done
fi

if [ "$single_lang" = "false" ] || [ "$lang" = "zig" ]; then
echo "Building the Zig test components"
for subdir in "${zig_test_components[@]}"; do
Expand Down Expand Up @@ -279,7 +305,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "swift" ]; then
if [ "$rebuild" = true ]; then
rm *.wasm
fi
/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc -target wasm32-unknown-wasi main.swift -o main.wasm -sdk /Library/Developer/Toolchains/swift-wasm-5.7.3-RELEASE.xctoolchain/usr/share/wasi-sysroot/
/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc -target wasm32-unknown-wasi main.swift -o main.wasm -sdk /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/share/wasi-sysroot/
wasm-opt -Os main.wasm -o main.opt.wasm

echo "Turning the module into a WebAssembly Component..."
Expand All @@ -306,7 +332,8 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "c" ]; then
rm *.wasm
fi
wit-bindgen c --autodrop-borrows yes ./wit
~/wasi-sdk-20.0/bin/clang --sysroot ~/wasi-sdk-20.0/share/wasi-sysroot main.c c_api1.c c_api1_component_type.o -o main.wasm
# last built with wasi-sdk-0.25.0
$WASI_SDK_PATH/bin/clang --sysroot $WASI_SDK_PATH/share/wasi-sysroot main.c c_api1.c c_api1_component_type.o -o main.wasm

echo "Turning the module into a WebAssembly Component..."
target="../$subdir.wasm"
Expand Down Expand Up @@ -334,6 +361,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "python" ]; then
fi

echo "Compiling the python code into a WebAssembly Component..."
rm -rf bindings
componentize-py bindings bindings
componentize-py componentize test -o "${subdir}_full.wasm"
wasm-tools strip "${subdir}_full.wasm" -o "${subdir}.wasm"
Expand All @@ -349,8 +377,8 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "python" ]; then
fi

if [ "$single_lang" = "false" ] || [ "$lang" = "ts" ]; then
echo "Building the TS test components"
for subdir in ${ts_test_components[@]}; do
echo "Building the TS test apps"
for subdir in ${ts_test_apps[@]}; do
echo "Building $subdir..."
pushd "$subdir" || exit

Expand All @@ -359,10 +387,12 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "ts" ]; then
fi

if [ "$rebuild" = true ]; then
golem-cli app build
golem-cli app copy
golem-cli app clean
fi

golem-cli app build
golem-cli app copy

popd || exit
done
fi
Binary file modified test-components/c-1.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions test-components/c-1/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ int32_t main(void) {
return 0;
}

int32_t c_api1_run(void) {
int32_t exports_c_api1_run(void) {
printf("Hello World!\n");
return 100;
}

void c_api1_print(c_api1_string_t *s) {
void exports_c_api1_print(c_api1_string_t *s) {
char* buf = malloc(s->len + 1);
memset(buf, 0, s->len + 1);
strncpy(buf, s->ptr, s->len);
Expand Down
Binary file modified test-components/caller-composed-ts.wasm
Binary file not shown.
Binary file modified test-components/caller-ts.wasm
Binary file not shown.
Binary file modified test-components/counter-ts.wasm
Binary file not shown.
Binary file modified test-components/csharp-1.wasm
Binary file not shown.
Binary file modified test-components/grain-1.wasm
Binary file not shown.
Binary file modified test-components/java-1.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test-components/java-1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<properties>
<java.version>9</java.version>
<teavm.version>0.2.7-SNAPSHOT</teavm.version>
<teavm.version>0.2.8</teavm.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by `wit-bindgen` 0.26.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.37.0. DO NOT EDIT!
package wit.worlds;

import java.nio.charset.StandardCharsets;
Expand All @@ -17,7 +17,7 @@ private JavaExample() {}
private static int wasmExportRunExample1(int p0, int p1) {

byte[] bytes = new byte[p1];
Memory.getBytes(Address.fromInt(p0), bytes, 0, p1);
Memory.getBytes(org.teavm.interop.Address.fromInt(p0), bytes, 0, p1);

int result = wit.worlds.JavaExampleImpl.runExample1(new String(bytes, StandardCharsets.UTF_8));

Expand All @@ -26,6 +26,6 @@ private static int wasmExportRunExample1(int p0, int p1) {
}

@CustomSection(name = "component-type:JavaExample")
private static final String __WIT_BINDGEN_COMPONENT_TYPE = "0061736d0d0001000019167769742d636f6d706f6e656e742d656e636f64696e6704000739014102014102014001016173007904000c72756e2d6578616d706c65310100040115676f6c656d3a69742f6a6176612d6578616d706c6504000b1201000c6a6176612d6578616d706c65030000004d0970726f647563657273010c70726f6365737365642d6279020d7769742d636f6d706f6e656e7407302e3230392e31167769742d62696e6467656e2d746561766d2d6a61766106302e32362e30";
private static final String __WIT_BINDGEN_COMPONENT_TYPE = "0061736d0d0001000019167769742d636f6d706f6e656e742d656e636f64696e6704000739014102014102014001016173007904000c72756e2d6578616d706c65310100040015676f6c656d3a69742f6a6176612d6578616d706c6504000b1201000c6a6176612d6578616d706c65030000004d0970726f647563657273010c70726f6365737365642d6279020d7769742d636f6d706f6e656e7407302e3232332e30167769742d62696e6467656e2d746561766d2d6a61766106302e33372e30";

}
Binary file modified test-components/java-2.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test-components/java-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<properties>
<java.version>9</java.version>
<teavm.version>0.2.7-SNAPSHOT</teavm.version>
<teavm.version>0.2.8</teavm.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Loading

0 comments on commit b2dd826

Please sign in to comment.