Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/python-3/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/devcontainers/rust

# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

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

RUN echo 'alias clang=/opt/wasi-sdk-22.0/bin/clang' >> /etc/bash.bashrc
RUN echo 'alias clang++=/opt/wasi-sdk-22.0/bin/clang++' >> /etc/bash.bashrc
COPY .devcontainer/setup.sh /tmp/setup.sh
RUN chmod +x /tmp/setup.sh
USER vscode
RUN /tmp/setup.sh
58 changes: 9 additions & 49 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,11 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/python-3
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "Dev",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.9",
// Options
"NODE_VERSION": "16"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash .devcontainer/finalize.sh",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"rust": "latest"
}
"name": "Dev",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
16 changes: 0 additions & 16 deletions .devcontainer/finalize.sh

This file was deleted.

29 changes: 29 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
set -e
cd $HOME

# Wasmtime: Used as default test runner.
curl https://wasmtime.dev/install.sh -sSf | bash

# Rust: Install additional targets not present in the docker base image.
rustup target add wasm32-wasip2

# C/C++
WASI_SDK_PATH="$HOME/wasi-sdk-25.0"
mkdir -p "$WASI_SDK_PATH"
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz | tar -xz -C "$WASI_SDK_PATH" --strip-components=1
echo "export WASI_SDK_PATH=$WASI_SDK_PATH" >> ~/.bashrc
echo "alias clang=$WASI_SDK_PATH/bin/clang" >> ~/.bashrc
echo "alias clang++=$WASI_SDK_PATH/bin/clang++" >> ~/.bashrc

# .NET
DOTNET_PATH="$HOME/.dotnet"
mkdir -p "$DOTNET_PATH"
curl -sSL https://dot.net/v1/dotnet-install.sh -o $DOTNET_PATH/dotnet-install.sh
chmod +x $DOTNET_PATH/dotnet-install.sh
$DOTNET_PATH/dotnet-install.sh --channel 9.0 --install-dir $DOTNET_PATH
echo "export PATH=$DOTNET_PATH:\$PATH" >> ~/.bashrc

# Moonbit
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
echo 'export PATH="$HOME/.moon/bin:$PATH"' >> ~/.bashrc
38 changes: 28 additions & 10 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Testing wit-bindgen

There are a few pre-requisites to testing the project. You only need the language compilers that you wish to run test against.
## Setup
### Dev container
There are a few pre-requisites to testing the project. The easiest way to get
started is by using the dev container part of this repository. That contains all
the required toolchains in a single Docker container.

### Manual installation
Alternatively, you can install the required tools by hand. You only need the
language compilers that you wish to run test against.

- WASI SDK
- Download from wasi-sdk releases page. If you're using Windows, you need the one with mingw in its name.
- `curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz`
- 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.
- `curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz`
- 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.
- Compilers for the target language:
- Rust - wasi target: `rustup target add wasm32-wasip1`
- Java - TeaVM-WASI `ci/download-teamvm.sh`
- C - [Clang](https://clang.llvm.org/)
- Rust - wasi target: `rustup target add wasm32-wasip2`
- C - [Clang](https://clang.llvm.org/) (You can also use the one shipped with WASI SDK)
- C# - [Dotnet 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
- [MoonBit](https://www.moonbitlang.com/download/)

There are two suites of tests: [codegen](#testing-wit-bindgen---codegen) and [runtime](#testing-wit-bindgen---runtime). To run all possible tests, across all supported languages, ensure the dependency above are installed then run:
## Test structure
There are two suites of tests: [codegen](#testing-wit-bindgen---codegen) and [runtime](#testing-wit-bindgen---runtime). To run all possible tests, across all supported languages, ensure the dependencies above are installed then run:

```
cargo test --workspace
Expand Down Expand Up @@ -55,11 +64,11 @@ Use `git submodule init` + `git submodule update` before running the tests.

The tests are generated by a macro `codegen_tests` in [crates/test-helpers](../crates/test-helpers/).

You can run all `codegen` tests in rust with the following command:
You can run the `codegen` tests for all languages with the following command:

```sh
cargo run test \
--languages rust \
--languages rust,c,cpp,csharp,moonbit \
--artifacts target/artifacts \
--rust-wit-bindgen-path ./crates/guest-rust \
tests/codegen
Expand All @@ -77,7 +86,6 @@ wasm and executed on hosts. The code compiled-to-wasm can be one of:

* `wasm.rs` - compiled with Rust to WebAssembly
* `wasm.c` - compiled with Clang
* `wasm.java` - compiled with TeaVM-WASI
* `wasm.cs` - compiled with NativeAOT and Mono

Existence of these files indicates that the language should be supported for the
Expand All @@ -90,6 +98,16 @@ Each of these hosts can also be omitted if the host doesn't implement the test
or something like that. Otherwise for each host that exists when the host's
crate generator crate is tested it will run all these tests.

You can run the `runtime` tests for all languages with the following command:

```sh
cargo run test \
--languages rust,c,cpp,csharp,moonbit \
--artifacts target/artifacts \
--rust-wit-bindgen-path ./crates/guest-rust \
tests/runtime
```

## Testing Layout

If you're adding a test, all you should generally have to do is edit files in
Expand Down
Loading