Skip to content

Commit ec016d9

Browse files
authored
Merge pull request #13 from dhil/wasmfx-merge
Merge with upstream
2 parents 9aeec21 + 74e4aab commit ec016d9

File tree

9 files changed

+68
-181
lines changed

9 files changed

+68
-181
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/
2020
# [Optional] Uncomment this line to install global node packages.
2121
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
2222

23-
RUN cd /opt && curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz \
23+
RUN cd /opt && curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz \
2424
| tar -xz
25-
ENV WASI_SDK_PATH=/opt/wasi-sdk-20.0
25+
ENV WASI_SDK_PATH=/opt/wasi-sdk-22.0
2626

27-
RUN echo 'alias clang=/opt/wasi-sdk-20.0/bin/clang' >> /etc/bash.bashrc
28-
RUN echo 'alias clang++=/opt/wasi-sdk-20.0/bin/clang++' >> /etc/bash.bashrc
27+
RUN echo 'alias clang=/opt/wasi-sdk-22.0/bin/clang' >> /etc/bash.bashrc
28+
RUN echo 'alias clang++=/opt/wasi-sdk-22.0/bin/clang++' >> /etc/bash.bashrc

.github/actions/install-wasi-sdk/action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ runs:
55
using: composite
66
steps:
77
- run: |
8-
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz -L | tar xzvf -
9-
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-20.0" >> $GITHUB_ENV
8+
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz -L | tar xzvf -
9+
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-22.0" >> $GITHUB_ENV
1010
if: runner.os == 'Linux'
1111
shell: bash
1212
- run: |
13-
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz -L | tar xzvf -
14-
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-20.0" >> $GITHUB_ENV
13+
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-macos.tar.gz -L | tar xzvf -
14+
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-22.0" >> $GITHUB_ENV
1515
if: runner.os == 'macOS'
1616
shell: bash
1717
- run: |
18-
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0.m-mingw.tar.gz -L | tar xzvf -
19-
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-20.0+m" >> $GITHUB_ENV
18+
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0.m-mingw64.tar.gz -L | tar xzvf -
19+
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-22.0+m" >> $GITHUB_ENV
2020
if: runner.os == 'Windows'
2121
shell: bash
2222
- name: Setup `wasm-tools`

.github/workflows/main.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ jobs:
8080
echo $LOCALAPPDATA'\Microsoft\dotnet' >> $GITHUB_PATH
8181
echo $LOCALAPPDATA'\Microsoft\dotnet\tools' >> $GITHUB_PATH
8282
$LOCALAPPDATA/Microsoft/dotnet/dotnet --info
83-
echo nativeaot-llvm requires emscripten for its version of clang as wasi-sdk 20 does not work see https://github.com/WebAssembly/wasi-sdk/issues/326
84-
curl.exe -OL https://github.com/emscripten-core/emsdk/archive/refs/heads/main.zip
85-
unzip main.zip
86-
cd emsdk-main
87-
./emsdk.bat install 3.1.47
88-
./emsdk.bat activate 3.1.47
8983
if : matrix.os == 'windows-latest'
9084
9185
- run: ci/download-teavm.sh
@@ -103,14 +97,8 @@ jobs:
10397
- uses: acifani/setup-tinygo@v2
10498
with:
10599
tinygo-version: 0.31.0
106-
- name: All but Windows, cargo test --workspace
107-
if : matrix.os != 'windows-latest'
100+
- name: cargo test --workspace
108101
run: cargo test --workspace
109-
- name: Windows, set EMSDK and run cargo test
110-
if : matrix.os == 'windows-latest'
111-
run: |
112-
source ./emsdk-main/emsdk_env.sh
113-
cargo test --workspace
114102

115103
check:
116104
name: Check

crates/csharp/README.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// generate the c# and the component meta module
1+
## generate the c# and the component module
22

3-
cargo run c-sharp --string-encoding utf8 --out-dir testing-csharp tests/codegen/floats.wit
3+
The following will generate the c# code given a wit file:
44

5-
// to run the runtime tests with Native AOT, you need some additional set up
5+
```bash
6+
cargo run c-sharp --string-encoding utf8 --out-dir testing-csharp tests/codegen/floats.wit
7+
```
68

7-
// install emscripten
8-
curl.exe -OL https://github.com/emscripten-core/emsdk/archive/refs/heads/main.zip
9-
unzip main.zip
10-
cd .\emsdk-main\main\emsdk-main
11-
.\emsdk_env.ps1 activate 3.1.23 --permanant
9+
## Setup
10+
To run the runtime tests with Native AOT, you need some additional set up
1211

12+
```bash
1313
// install wasi-sdk and set env
14-
curl.exe -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0.m-mingw.tar.gz | tar xzvf -
15-
$env:WASI_SDK_PATH="c:\users\jstur\wasi-sdk-20.0+m\"
14+
curl.exe -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0.m-mingw64.tar.gz | tar xzvf -
15+
$env:WASI_SDK_PATH="c:\users\jstur\wasi-sdk-22.0+m\"
16+
```

crates/csharp/src/csproj.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ impl CSProjectLLVMBuilder {
104104
</ItemGroup>
105105
106106
<Target Name="CheckWasmSdks">
107-
<Error Text="Emscripten not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Emscripten and ensure the EMSDK environment variable points to the directory containing upstream/emscripten/emcc.bat"
108-
Condition="'$(EMSDK)' == ''" />
107+
<Error Text="Wasi SDK not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Wasi SDK and ensure the WASI_SDK_PATH environment variable points to the directory containing share/wasi-sysroot"
108+
Condition="'$(WASI_SDK_PATH)' == ''" />
109+
<Warning Text="The WASI SDK version is too low. Please use WASI SDK 22 or newer with a 64 bit Clang."
110+
Condition="!Exists('$(WASI_SDK_PATH)/VERSION')" />
109111
</Target>
110112
"#,
111113
);
@@ -115,7 +117,7 @@ impl CSProjectLLVMBuilder {
115117
Inputs=\"$(MSBuildProjectDirectory)/{camel}_cabi_realloc.c\"
116118
Outputs=\"$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o\"
117119
>
118-
<Exec Command=\"emcc.bat &quot;$(MSBuildProjectDirectory)/{camel}_cabi_realloc.c&quot; -c -o &quot;$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o&quot;\"/>
120+
<Exec Command=\"&quot;$(WASI_SDK_PATH)/bin/clang&quot; --target=wasm32-wasi &quot;$(MSBuildProjectDirectory)/{camel}_cabi_realloc.c&quot; -c -o &quot;$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o&quot;\"/>
119121
</Target>
120122
"
121123
));

crates/teavm-java/src/lib.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,15 +1569,15 @@ impl Bindgen for FunctionBindgen<'_, '_> {
15691569
// Note that we can only reliably use `Address.ofData` for elements with alignment <= 4 because as
15701570
// of this writing TeaVM does not guarantee 64 bit items are aligned on 8 byte boundaries.
15711571
if realloc.is_none() && size <= 4 {
1572-
results.push(format!("Address.ofData({op}).toInt()"));
1572+
results.push(format!("org.teavm.interop.Address.ofData({op}).toInt()"));
15731573
} else {
15741574
let address = self.locals.tmp("address");
15751575
let ty = ty.to_upper_camel_case();
15761576

15771577
uwrite!(
15781578
self.src,
15791579
"
1580-
Address {address} = Memory.malloc({size} * ({op}).length, {size});
1580+
org.teavm.interop.Address {address} = Memory.malloc({size} * ({op}).length, {size});
15811581
Memory.put{ty}s({address}, {op}, 0, ({op}).length);
15821582
"
15831583
);
@@ -1606,7 +1606,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
16061606
self.src,
16071607
"
16081608
{ty}[] {array} = new {ty}[{length}];
1609-
Memory.get{ty_upper}s(Address.fromInt({address}), {array}, 0, ({array}).length);
1609+
Memory.get{ty_upper}s(org.teavm.interop.Address.fromInt({address}), {array}, 0, ({array}).length);
16101610
"
16111611
);
16121612

@@ -1622,14 +1622,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
16221622
);
16231623

16241624
if realloc.is_none() {
1625-
results.push(format!("Address.ofData({bytes}).toInt()"));
1625+
results.push(format!("org.teavm.interop.Address.ofData({bytes}).toInt()"));
16261626
} else {
16271627
let address = self.locals.tmp("address");
16281628

16291629
uwrite!(
16301630
self.src,
16311631
"
1632-
Address {address} = Memory.malloc({bytes}.length, 1);
1632+
org.teavm.interop.Address {address} = Memory.malloc({bytes}.length, 1);
16331633
Memory.putBytes({address}, {bytes}, 0, {bytes}.length);
16341634
"
16351635
);
@@ -1648,7 +1648,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
16481648
self.src,
16491649
"
16501650
byte[] {bytes} = new byte[{length}];
1651-
Memory.getBytes(Address.fromInt({address}), {bytes}, 0, {length});
1651+
Memory.getBytes(org.teavm.interop.Address.fromInt({address}), {bytes}, 0, {length});
16521652
"
16531653
);
16541654

@@ -1724,7 +1724,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
17241724
{body}
17251725
{array}.add({result});
17261726
}}
1727-
Memory.free(Address.fromInt({address}), ({length}) * {size}, {align});
1727+
Memory.free(org.teavm.interop.Address.fromInt({address}), ({length}) * {size}, {align});
17281728
"
17291729
);
17301730

@@ -1829,7 +1829,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
18291829
{
18301830
uwriteln!(
18311831
self.src,
1832-
"Memory.free(Address.fromInt({address}), {size}, {align});"
1832+
"Memory.free(org.teavm.interop.Address.fromInt({address}), {size}, {align});"
18331833
);
18341834
}
18351835

@@ -1838,7 +1838,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
18381838
self.src,
18391839
"
18401840
for ({}Cleanup cleanup : cleanupList) {{
1841-
Memory.free(Address.fromInt(cleanup.address), cleanup.size, cleanup.align);
1841+
Memory.free(org.teavm.interop.Address.fromInt(cleanup.address), cleanup.size, cleanup.align);
18421842
}}
18431843
",
18441844
self.gen.gen.qualifier()
@@ -1862,85 +1862,85 @@ impl Bindgen for FunctionBindgen<'_, '_> {
18621862
Instruction::I32Load { offset }
18631863
| Instruction::PointerLoad { offset }
18641864
| Instruction::LengthLoad { offset } => results.push(format!(
1865-
"Address.fromInt(({}) + {offset}).getInt()",
1865+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getInt()",
18661866
operands[0]
18671867
)),
18681868

18691869
Instruction::I32Load8U { offset } => results.push(format!(
1870-
"(((int) Address.fromInt(({}) + {offset}).getByte()) & 0xFF)",
1870+
"(((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getByte()) & 0xFF)",
18711871
operands[0]
18721872
)),
18731873

18741874
Instruction::I32Load8S { offset } => results.push(format!(
1875-
"((int) Address.fromInt(({}) + {offset}).getByte())",
1875+
"((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getByte())",
18761876
operands[0]
18771877
)),
18781878

18791879
Instruction::I32Load16U { offset } => results.push(format!(
1880-
"(((int) Address.fromInt(({}) + {offset}).getShort()) & 0xFFFF)",
1880+
"(((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getShort()) & 0xFFFF)",
18811881
operands[0]
18821882
)),
18831883

18841884
Instruction::I32Load16S { offset } => results.push(format!(
1885-
"((int) Address.fromInt(({}) + {offset}).getShort())",
1885+
"((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getShort())",
18861886
operands[0]
18871887
)),
18881888

18891889
Instruction::I64Load { offset } => results.push(format!(
1890-
"Address.fromInt(({}) + {offset}).getLong()",
1890+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getLong()",
18911891
operands[0]
18921892
)),
18931893

18941894
Instruction::F32Load { offset } => results.push(format!(
1895-
"Address.fromInt(({}) + {offset}).getFloat()",
1895+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getFloat()",
18961896
operands[0]
18971897
)),
18981898

18991899
Instruction::F64Load { offset } => results.push(format!(
1900-
"Address.fromInt(({}) + {offset}).getDouble()",
1900+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getDouble()",
19011901
operands[0]
19021902
)),
19031903

19041904
Instruction::I32Store { offset }
19051905
| Instruction::PointerStore { offset }
19061906
| Instruction::LengthStore { offset } => uwriteln!(
19071907
self.src,
1908-
"Address.fromInt(({}) + {offset}).putInt({});",
1908+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putInt({});",
19091909
operands[1],
19101910
operands[0]
19111911
),
19121912

19131913
Instruction::I32Store8 { offset } => uwriteln!(
19141914
self.src,
1915-
"Address.fromInt(({}) + {offset}).putByte((byte) ({}));",
1915+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putByte((byte) ({}));",
19161916
operands[1],
19171917
operands[0]
19181918
),
19191919

19201920
Instruction::I32Store16 { offset } => uwriteln!(
19211921
self.src,
1922-
"Address.fromInt(({}) + {offset}).putShort((short) ({}));",
1922+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putShort((short) ({}));",
19231923
operands[1],
19241924
operands[0]
19251925
),
19261926

19271927
Instruction::I64Store { offset } => uwriteln!(
19281928
self.src,
1929-
"Address.fromInt(({}) + {offset}).putLong({});",
1929+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putLong({});",
19301930
operands[1],
19311931
operands[0]
19321932
),
19331933

19341934
Instruction::F32Store { offset } => uwriteln!(
19351935
self.src,
1936-
"Address.fromInt(({}) + {offset}).putFloat({});",
1936+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putFloat({});",
19371937
operands[1],
19381938
operands[0]
19391939
),
19401940

19411941
Instruction::F64Store { offset } => uwriteln!(
19421942
self.src,
1943-
"Address.fromInt(({}) + {offset}).putDouble({});",
1943+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putDouble({});",
19441944
operands[1],
19451945
operands[0]
19461946
),
@@ -1950,14 +1950,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
19501950
Instruction::GuestDeallocate { size, align } => {
19511951
uwriteln!(
19521952
self.src,
1953-
"Memory.free(Address.fromInt({}), {size}, {align});",
1953+
"Memory.free(org.teavm.interop.Address.fromInt({}), {size}, {align});",
19541954
operands[0]
19551955
)
19561956
}
19571957

19581958
Instruction::GuestDeallocateString => uwriteln!(
19591959
self.src,
1960-
"Memory.free(Address.fromInt({}), {}, 1);",
1960+
"Memory.free(org.teavm.interop.Address.fromInt({}), {}, 1);",
19611961
operands[0],
19621962
operands[1]
19631963
),
@@ -2023,7 +2023,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
20232023

20242024
uwriteln!(
20252025
self.src,
2026-
"Memory.free(Address.fromInt({address}), ({length}) * {size}, {align});"
2026+
"Memory.free(org.teavm.interop.Address.fromInt({address}), ({length}) * {size}, {align});"
20272027
);
20282028
}
20292029
}

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ There are a few pre-requisites to testing the project. You only need the languag
44

55
- WASI SDK
66
- Download from wasi-sdk releases page. If you're using Windows, you need the one with mingw in its name.
7-
- `curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz`
7+
- `curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz`
88
- Create an environment variable called `WASI_SDK_PATH`` giving the path where you extracted the WASI SDK download, i.e., the directory containing `bin`/`lib`/`share`` folders.
99
- Compilers for the target language:
1010
- Go + TinyGo - https://tinygo.org/ (v0.27.0+)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package foo:bar;
2+
3+
interface my-import {
4+
record address {
5+
field: u32,
6+
attribute: bool,
7+
}
8+
}
9+
10+
world bindings {
11+
import my-import;
12+
13+
export init: func(baz: string);
14+
}

0 commit comments

Comments
 (0)