Skip to content

Commit 3b7420e

Browse files
authored
Referencing golem-wit as a rust crate (#266)
* Referencing golem-wit as a rust crate * Format
1 parent d4c9b59 commit 3b7420e

File tree

10 files changed

+58
-14
lines changed

10 files changed

+58
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ target/
66
.idea/
77
./golem-worker-executor/data/
88
./golem-worker-executor-base/data/
9+
./golem-worker-executor-base/golem-wit/
910
zig-cache/
1011
dump.rdb
1112
./test-templates/*.wat

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "golem-wit"]
2-
path = golem-wit
3-
url = https://github.com/golemcloud/golem-wit
41
[submodule "golem-cli"]
52
path = golem-cli
63
url = https://github.com/golemcloud/golem-cli

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

golem-wit

Lines changed: 0 additions & 1 deletion
This file was deleted.

golem-worker-executor-base/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fs-set-times = "0.20.1"
4242
futures = { workspace = true }
4343
futures-util = { workspace = true }
4444
gethostname = "0.4.3"
45+
golem-wit = "0.1.0"
4546
http = { workspace = true }
4647
http_02 = { package = "http", version = "0.2.11" }
4748
http-body = "1.0.0" # keep in sync with wasmtime
@@ -88,6 +89,10 @@ serde_json = { workspace = true }
8889
tracing-subscriber = { workspace = true }
8990
warp = { workspace = true }
9091

92+
[build-dependencies]
93+
cargo_metadata = "0.18.1"
94+
symlink = "0.1.0"
95+
9196
[[test]]
9297
name = "integration"
9398
path = "tests/lib.rs"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use cargo_metadata::MetadataCommand;
2+
use std::path::Path;
3+
use symlink::{remove_symlink_dir, symlink_dir};
4+
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
6+
let golem_wit_root = find_package_root("golem-wit");
7+
let target_root = Path::new("./golem-wit");
8+
if target_root.exists() {
9+
let _ = remove_symlink_dir(target_root);
10+
}
11+
println!(
12+
"Creating symlink from {} to {}",
13+
golem_wit_root,
14+
target_root.display()
15+
);
16+
symlink_dir(golem_wit_root, target_root)?;
17+
Ok(())
18+
}
19+
20+
fn find_package_root(name: &str) -> String {
21+
let metadata = MetadataCommand::new()
22+
.manifest_path("./Cargo.toml")
23+
.exec()
24+
.unwrap();
25+
let package = metadata.packages.iter().find(|p| p.name == name).unwrap();
26+
package.manifest_path.parent().unwrap().to_string()
27+
}

golem-worker-executor-base/src/preview2/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
wasmtime::component::bindgen!({
16-
path: "../golem-wit/wit",
16+
path: "golem-wit/wit",
1717
interfaces: "
1818
import golem:api/host;
1919

test-templates/build-components.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "zig" ]; then
107107
echo "Turning the module into a WebAssembly Component..."
108108
target="../$subdir.wasm"
109109
target_wat="../$subdir.wat"
110-
wasm-tools component new zig-out/bin/main.wasm -o "$target" --adapt ../../golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
110+
wasm-tools component new zig-out/bin/main.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
111111
wasm-tools print "$target" >"$target_wat"
112112

113113
popd || exit
@@ -131,7 +131,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "tinygo" ]; then
131131
target="../$subdir.wasm"
132132
target_wat="../$subdir.wat"
133133
wasm-tools component embed ./wit main.wasm --output main.embed.wasm
134-
wasm-tools component new main.embed.wasm -o "$target" --adapt ../../golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm
134+
wasm-tools component new main.embed.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm
135135
wasm-tools print "$target" >"$target_wat"
136136

137137
popd || exit
@@ -152,7 +152,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "grain" ]; then
152152
echo "Turning the module into a WebAssembly Component..."
153153
target="../$subdir.wasm"
154154
target_wat="../$subdir.wat"
155-
wasm-tools component new main.gr.wasm -o "$target" --adapt ../../golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
155+
wasm-tools component new main.gr.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
156156
wasm-tools print "$target" >"$target_wat"
157157

158158
popd || exit
@@ -199,7 +199,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "java" ]; then
199199
echo "Turning the module into a WebAssembly Component..."
200200
target="../$subdir.wasm"
201201
target_wat="../$subdir.wat"
202-
wasm-tools component new target/generated/wasm/teavm-wasm/classes.wasm -o "$target" --adapt ../../golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm
202+
wasm-tools component new target/generated/wasm/teavm-wasm/classes.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm
203203
wasm-tools print "$target" >"$target_wat"
204204

205205
popd || exit
@@ -220,7 +220,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "dotnet" ]; then
220220
echo "Turning the module into a WebAssembly Component..."
221221
target="../$subdir.wasm"
222222
target_wat="../$subdir.wat"
223-
wasm-tools component new bin/Release/net7.0/$subdir.wasm -o "$target" --adapt ../../golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
223+
wasm-tools component new bin/Release/net7.0/$subdir.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
224224
wasm-tools print "$target" >"$target_wat"
225225

226226
popd || exit
@@ -242,7 +242,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "swift" ]; then
242242
echo "Turning the module into a WebAssembly Component..."
243243
target="../$subdir.wasm"
244244
target_wat="../$subdir.wat"
245-
wasm-tools component new main.opt.wasm -o "$target" --adapt ../../golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
245+
wasm-tools component new main.opt.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier3/wasi_snapshot_preview1.wasm
246246
wasm-tools print "$target" >"$target_wat"
247247

248248
popd || exit
@@ -264,7 +264,7 @@ if [ "$single_lang" = "false" ] || [ "$lang" = "c" ]; then
264264
echo "Turning the module into a WebAssembly Component..."
265265
target="../$subdir.wasm"
266266
target_wat="../$subdir.wat"
267-
wasm-tools component new main.wasm -o "$target" --adapt ../../golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm
267+
wasm-tools component new main.wasm -o "$target" --adapt ../../golem-worker-executor-base/golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm
268268
wasm-tools print "$target" >"$target_wat"
269269

270270
popd || exit

test-templates/js-1/componentize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const jsSource = await readFile('main.js', 'utf8');
77
const { component } = await componentize(jsSource, {
88
witPath: resolve('wit'),
99
enableStdout: true,
10-
preview2Adapter: '../../golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm'
10+
preview2Adapter: '../../golem-worker-executor-base/golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm'
1111
});
1212

1313
await writeFile('out/component.wasm', component);

test-templates/js-2/componentize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const jsSource = await readFile('main.js', 'utf8');
77
const { component } = await componentize(jsSource, {
88
witPath: resolve('wit'),
99
enableStdout: true,
10-
preview2Adapter: '../../golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm',
10+
preview2Adapter: '../../golem-worker-executor-base/golem-wit/adapters/tier2/wasi_snapshot_preview1.wasm',
1111
debug: true
1212
});
1313

0 commit comments

Comments
 (0)