Skip to content

Commit

Permalink
Add support for MoonBit (#1020)
Browse files Browse the repository at this point in the history
* feat: initial commit for moonbit

* feat(moonbit): use teavm-java as reference

* feat(moonbit): convert some types

* feat(moonbit): type enum/variant + cleanup result/tuple

* feat(moonbit): type record

* fix(moonbit): interface generation

* feat(moonbit): clean up interface generator

* feat(moonbit): add test and start bindgen

* feat(moonbit): wip, bindgen

* fix(moonbit): array api

* feat(moonbit): adjust test output

* feat(moonbit): partial support for lower/lift enum/variant

* fix(moonbit): variant cases

* misc(moonbit): small rewrites

* feat(moonbit): add exportation

* fix(moonbit): cleanup return area

* feat(moonbit): reorganize generated directory structure

fix(moonbit): char conversion and previous bug

* feat(moonbit): lower / lift string

* fix(moonbit): typo

* feat(moonbit): fix qualifier and cleanup directory structure

* fix(moonbit): attemp to fix qualifier issue

* fix(moonbit): misimplemented instructions

* refactor(moonbit): flag representation

* fix(moonbit): variant and tuple and release all tests

* feat(moonbit): add resource support

* fix(moonbit): generation for Option and others

* refactor(moonbit): improve generated code

* fix(moonbit): add keywords

* refactor(moonbit): merge contructor name and type name

* fix(moonbit): forgotten import

* fix(moonbit): forgotten keywords

* refactor(moonbit): move exportations

* refactor(moonbit): reorganize files and fix imports

* refactor(moonbit): move exportations to gen

* fix(moonbit): flag support

* fix(moonbit): world type import/export

* fix(moonbit): qualifier related issues

* refactor(moonbit): cleanup to make logic clear and robust

* fix(moonbit): configuration mistake

* cleanup: remove warnings

* fix(moonbit): configuration and local conflicts

* fix(moonbit): separate export and import types

* fix(moonbit): pass all tests

* fix(moonbit): add resource-drop, cabi-realloc and order imports and docs

* misc(moonbit): modify naming convention

* feat(moonbit): add derive show option

* misc(moonbit): update generated package name and generate doc

* fix(moonbit): string length should be char number

* misc(moonbit): naming convention

* ci(moonbit): add test ci for moonbit

* misc(moonbit): change representation for u16

* fix: abi change

* misc(moonbit): moon-bit -> moonbit

* feat(moonbit): derive eq

* misc(moonbit): avoid builtin type names

* feat(moonbit): lower and lift string

* misc(moonbit): adjust heap start address

* feat(moonbit): lower lift bytes

* feat(moonbit): wip add core f32 support

* fix(moonbit): keyword update

* fix(moonbit): reserve space

* misc(moonbit): replace inline wasm with builtin functions

* feat(moonbit): lift/lower array

* ci(moonbit): use powershell for windows installation

* misc(moonbit): fix preamble

* misc(moonbit): add todo for future work

* refactor(moonbit): split stub file

* fix(moonbit): allocate return area for exportation functions

* misc(moonbit): add documentation

* misc(moonbit): ignore stub file option

* fix(moonbit): ci check

* fix(moonbit): separate ffi
  • Loading branch information
peter-jerry-ye authored Aug 16, 2024
1 parent 0d18c6b commit ea1f14e
Show file tree
Hide file tree
Showing 9 changed files with 2,760 additions and 1 deletion.
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
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 ea1f14e

Please sign in to comment.