Skip to content

Commit c86b26e

Browse files
authored
Merge pull request #24 from dhil/wasmfx-merge
Merge with upstream
2 parents 3f4883f + ca1cc40 commit c86b26e

File tree

18 files changed

+2801
-7
lines changed

18 files changed

+2801
-7
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
fail-fast: false
5959
matrix:
6060
os: [ubuntu-latest, macos-latest, windows-latest]
61-
lang: [c, rust, teavm-java, go, csharp]
61+
lang: [c, rust, teavm-java, go, csharp, moonbit]
6262
runs-on: ${{ matrix.os }}
6363
steps:
6464
- uses: actions/checkout@v4
@@ -84,6 +84,16 @@ jobs:
8484
$LOCALAPPDATA/Microsoft/dotnet/dotnet --info
8585
if: matrix.os == 'windows-latest' && matrix.lang == 'csharp'
8686
87+
- run: |
88+
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
89+
echo "$HOME/.moon/bin" >> $GITHUB_PATH
90+
if: matrix.os != 'windows-latest' && matrix.lang == 'moonbit'
91+
- run: |
92+
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; irm https://cli.moonbitlang.com/install/powershell.ps1 | iex
93+
"C:\Users\runneradmin\.moon\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
94+
shell: powershell
95+
if: matrix.os == 'windows-latest' && matrix.lang == 'moonbit'
96+
8797
- run: ci/download-teavm.sh
8898
if: matrix.lang == 'teavm-java'
8999
- uses: actions/setup-java@v4
@@ -149,6 +159,7 @@ jobs:
149159
- run: cargo build --no-default-features --features go
150160
- run: cargo build --no-default-features --features csharp
151161
- run: cargo build --no-default-features --features markdown
162+
- run: cargo build --no-default-features --features moonbit
152163

153164
# Feature combos of the `wit-bindgen` crate
154165
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.30.0' }
4545
wit-bindgen-go = { path = 'crates/go', version = '0.30.0' }
4646
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.30.0' }
4747
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.30.0' }
48+
wit-bindgen-moonbit = { path = 'crates/moonbit', version = '0.30.0' }
4849
wit-bindgen = { path = 'crates/guest-rust', version = '0.30.0', default-features = false }
4950

5051
[[bin]]
@@ -57,6 +58,7 @@ wit-bindgen-core = { workspace = true }
5758
wit-bindgen-rust = { workspace = true, features = ['clap'], optional = true }
5859
wit-bindgen-c = { workspace = true, features = ['clap'], optional = true }
5960
wit-bindgen-markdown = { workspace = true, features = ['clap'], optional = true }
61+
wit-bindgen-moonbit = { workspace = true, features = ['clap'], optional = true }
6062
wit-bindgen-teavm-java = { workspace = true, features = ['clap'], optional = true }
6163
wit-bindgen-go = { workspace = true, features = ['clap'], optional = true }
6264
wit-bindgen-csharp = { workspace = true, features = ['clap'], optional = true }
@@ -71,6 +73,7 @@ default = [
7173
'teavm-java',
7274
'go',
7375
'csharp',
76+
'moonbit',
7477
]
7578
c = ['dep:wit-bindgen-c']
7679
rust = ['dep:wit-bindgen-rust']
@@ -79,6 +82,7 @@ teavm-java = ['dep:wit-bindgen-teavm-java']
7982
go = ['dep:wit-bindgen-go']
8083
csharp = ['dep:wit-bindgen-csharp']
8184
csharp-mono = ['csharp']
85+
moonbit = ['dep:wit-bindgen-moonbit']
8286

8387
[dev-dependencies]
8488
heck = { workspace = true }

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ wasm-tools component new main.embed.wasm --adapt wasi_snapshot_preview1.command.
381381
wasm-tools validate main.component.wasm --features component-model
382382
```
383383

384+
### Guest: MoonBit
385+
386+
MoonBit can be compiled to WebAssembly using [its toolchain](https://moonbitlang.com/download):
387+
388+
```sh
389+
moon build --target wasm # -g to keep symbols
390+
```
391+
392+
The generarted core wasm will be found under `target/wasm/release/build/gen/gen.wasm` by default. Then you can use `wasm-tools` to componentize the module:
393+
394+
```
395+
wasm-tools component embed wit target/wasm/release/build/gen/gen.wasm -o target/gen.wasm
396+
wasm-tools component new target/gen.wasm -o target/gen.component.wasm
397+
```
398+
399+
When using `wit-bindgen moonbit`, you may use `--derive-show` or `--derive-eq` to derive `Show` or `Eq` for all types.
400+
401+
You will find the files to be modified with the name `**/stub.mbt`.
402+
384403
### Guest: Other Languages
385404

386405
Other languages such as JS, Ruby, Python, etc, are hoped to be supported one day

ci/publish.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const CRATES_TO_PUBLISH: &[&str] = &[
2424
"wit-bindgen-csharp",
2525
"wit-bindgen-teavm-java",
2626
"wit-bindgen-markdown",
27+
"wit-bindgen-moonbit",
2728
"wit-bindgen-rust-macro",
2829
"wit-bindgen-rt",
2930
"wit-bindgen",

crates/c/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ impl WorldGenerator for C {
416416

417417
uwriteln!(h_str, "#include <stdint.h>");
418418
uwriteln!(h_str, "#include <stdbool.h>");
419+
uwriteln!(h_str, "#include <stddef.h>");
419420
for include in self.h_includes.iter() {
420421
uwriteln!(h_str, "#include {include}");
421422
}

crates/moonbit/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "wit-bindgen-moonbit"
3+
authors = ["YE Zihang <[email protected]>"]
4+
version = { workspace = true }
5+
edition = { workspace = true }
6+
repository = { workspace = true }
7+
license = { workspace = true }
8+
homepage = 'https://github.com/bytecodealliance/wit-bindgen'
9+
description = """
10+
MoonBit bindings generator for WIT and the component model, typically used
11+
through the `wit-bindgen-cli` crate.
12+
"""
13+
14+
[dependencies]
15+
anyhow = { workspace = true }
16+
wit-bindgen-core = { workspace = true }
17+
wit-component = { workspace = true }
18+
wasm-metadata = { workspace = true }
19+
heck = { workspace = true }
20+
clap = { workspace = true, optional = true }
21+
22+
[dev-dependencies]
23+
test-helpers = { path = '../test-helpers' }

0 commit comments

Comments
 (0)