Skip to content

Commit

Permalink
Merge pull request #24 from dhil/wasmfx-merge
Browse files Browse the repository at this point in the history
Merge with upstream
  • Loading branch information
dhil authored Aug 16, 2024
2 parents 3f4883f + ca1cc40 commit c86b26e
Show file tree
Hide file tree
Showing 18 changed files with 2,801 additions and 7 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
lang: [c, rust, teavm-java, go, csharp]
lang: [c, rust, teavm-java, go, csharp, moonbit]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -84,6 +84,16 @@ jobs:
$LOCALAPPDATA/Microsoft/dotnet/dotnet --info
if: matrix.os == 'windows-latest' && matrix.lang == 'csharp'
- run: |
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
echo "$HOME/.moon/bin" >> $GITHUB_PATH
if: matrix.os != 'windows-latest' && matrix.lang == 'moonbit'
- run: |
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; irm https://cli.moonbitlang.com/install/powershell.ps1 | iex
"C:\Users\runneradmin\.moon\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
shell: powershell
if: matrix.os == 'windows-latest' && matrix.lang == 'moonbit'
- run: ci/download-teavm.sh
if: matrix.lang == 'teavm-java'
- uses: actions/setup-java@v4
Expand Down Expand Up @@ -149,6 +159,7 @@ jobs:
- run: cargo build --no-default-features --features go
- run: cargo build --no-default-features --features csharp
- run: cargo build --no-default-features --features markdown
- run: cargo build --no-default-features --features moonbit

# Feature combos of the `wit-bindgen` crate
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.30.0' }
wit-bindgen-go = { path = 'crates/go', version = '0.30.0' }
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.30.0' }
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.30.0' }
wit-bindgen-moonbit = { path = 'crates/moonbit', version = '0.30.0' }
wit-bindgen = { path = 'crates/guest-rust', version = '0.30.0', default-features = false }

[[bin]]
Expand All @@ -57,6 +58,7 @@ wit-bindgen-core = { workspace = true }
wit-bindgen-rust = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-c = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-markdown = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-moonbit = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-teavm-java = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-go = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-csharp = { workspace = true, features = ['clap'], optional = true }
Expand All @@ -71,6 +73,7 @@ default = [
'teavm-java',
'go',
'csharp',
'moonbit',
]
c = ['dep:wit-bindgen-c']
rust = ['dep:wit-bindgen-rust']
Expand All @@ -79,6 +82,7 @@ teavm-java = ['dep:wit-bindgen-teavm-java']
go = ['dep:wit-bindgen-go']
csharp = ['dep:wit-bindgen-csharp']
csharp-mono = ['csharp']
moonbit = ['dep:wit-bindgen-moonbit']

[dev-dependencies]
heck = { workspace = true }
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,25 @@ wasm-tools component new main.embed.wasm --adapt wasi_snapshot_preview1.command.
wasm-tools validate main.component.wasm --features component-model
```

### Guest: MoonBit

MoonBit can be compiled to WebAssembly using [its toolchain](https://moonbitlang.com/download):

```sh
moon build --target wasm # -g to keep symbols
```

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:

```
wasm-tools component embed wit target/wasm/release/build/gen/gen.wasm -o target/gen.wasm
wasm-tools component new target/gen.wasm -o target/gen.component.wasm
```

When using `wit-bindgen moonbit`, you may use `--derive-show` or `--derive-eq` to derive `Show` or `Eq` for all types.

You will find the files to be modified with the name `**/stub.mbt`.

### Guest: Other Languages

Other languages such as JS, Ruby, Python, etc, are hoped to be supported one day
Expand Down
1 change: 1 addition & 0 deletions ci/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CRATES_TO_PUBLISH: &[&str] = &[
"wit-bindgen-csharp",
"wit-bindgen-teavm-java",
"wit-bindgen-markdown",
"wit-bindgen-moonbit",
"wit-bindgen-rust-macro",
"wit-bindgen-rt",
"wit-bindgen",
Expand Down
1 change: 1 addition & 0 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ impl WorldGenerator for C {

uwriteln!(h_str, "#include <stdint.h>");
uwriteln!(h_str, "#include <stdbool.h>");
uwriteln!(h_str, "#include <stddef.h>");
for include in self.h_includes.iter() {
uwriteln!(h_str, "#include {include}");
}
Expand Down
23 changes: 23 additions & 0 deletions crates/moonbit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "wit-bindgen-moonbit"
authors = ["YE Zihang <[email protected]>"]
version = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
homepage = 'https://github.com/bytecodealliance/wit-bindgen'
description = """
MoonBit bindings generator for WIT and the component model, typically used
through the `wit-bindgen-cli` crate.
"""

[dependencies]
anyhow = { workspace = true }
wit-bindgen-core = { workspace = true }
wit-component = { workspace = true }
wasm-metadata = { workspace = true }
heck = { workspace = true }
clap = { workspace = true, optional = true }

[dev-dependencies]
test-helpers = { path = '../test-helpers' }
Loading

0 comments on commit c86b26e

Please sign in to comment.