Skip to content

Commit eaf42f6

Browse files
authored
Update dev container & testing documentation. (#1353)
The previous devcontainer has been broken since: #1192
1 parent fc0bff6 commit eaf42f6

File tree

5 files changed

+71
-102
lines changed

5 files changed

+71
-102
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/python-3/.devcontainer/base.Dockerfile
1+
FROM mcr.microsoft.com/devcontainers/rust
22

3-
# [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
4-
ARG VARIANT="3.10-bullseye"
5-
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
6-
7-
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
8-
ARG NODE_VERSION="none"
9-
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
10-
11-
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
12-
# COPY requirements.txt /tmp/pip-tmp/
13-
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
14-
# && rm -rf /tmp/pip-tmp
15-
16-
# [Optional] Uncomment this section to install additional OS packages.
17-
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18-
# && apt-get -y install --no-install-recommends <your-package-list-here>
19-
20-
# [Optional] Uncomment this line to install global node packages.
21-
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
22-
23-
RUN cd /opt && curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz \
24-
| tar -xz
25-
ENV WASI_SDK_PATH=/opt/wasi-sdk-22.0
26-
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
3+
COPY .devcontainer/setup.sh /tmp/setup.sh
4+
RUN chmod +x /tmp/setup.sh
5+
USER vscode
6+
RUN /tmp/setup.sh

.devcontainer/devcontainer.json

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,11 @@
1-
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2-
// https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/python-3
1+
// For format details, see https://aka.ms/devcontainer.json.
32
{
4-
"name": "Dev",
5-
"build": {
6-
"dockerfile": "Dockerfile",
7-
"context": "..",
8-
"args": {
9-
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
10-
// Append -bullseye or -buster to pin to an OS version.
11-
// Use -bullseye variants on local on arm64/Apple Silicon.
12-
"VARIANT": "3.9",
13-
// Options
14-
"NODE_VERSION": "16"
15-
}
16-
},
17-
18-
// Set *default* container specific settings.json values on container create.
19-
"settings": {
20-
"python.defaultInterpreterPath": "/usr/local/bin/python",
21-
"python.linting.enabled": true,
22-
"python.linting.pylintEnabled": true,
23-
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
24-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
25-
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
26-
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
27-
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
28-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
29-
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
30-
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
31-
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
32-
},
33-
34-
// Add the IDs of extensions you want installed when the container is created.
35-
"extensions": [
36-
"ms-python.python",
37-
"ms-python.vscode-pylance"
38-
],
39-
40-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
41-
// "forwardPorts": [],
42-
43-
// Use 'postCreateCommand' to run commands after the container is created.
44-
"postCreateCommand": "bash .devcontainer/finalize.sh",
45-
46-
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
47-
"remoteUser": "vscode",
48-
"features": {
49-
"rust": "latest"
50-
}
3+
"name": "Dev",
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
"context": ".."
7+
},
8+
9+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
10+
"remoteUser": "vscode"
5111
}

.devcontainer/finalize.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

.devcontainer/setup.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
set -e
3+
cd $HOME
4+
5+
# Wasmtime: Used as default test runner.
6+
curl https://wasmtime.dev/install.sh -sSf | bash
7+
8+
# Rust: Install additional targets not present in the docker base image.
9+
rustup target add wasm32-wasip2
10+
11+
# C/C++
12+
WASI_SDK_PATH="$HOME/wasi-sdk-25.0"
13+
mkdir -p "$WASI_SDK_PATH"
14+
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
15+
echo "export WASI_SDK_PATH=$WASI_SDK_PATH" >> ~/.bashrc
16+
echo "alias clang=$WASI_SDK_PATH/bin/clang" >> ~/.bashrc
17+
echo "alias clang++=$WASI_SDK_PATH/bin/clang++" >> ~/.bashrc
18+
19+
# .NET
20+
DOTNET_PATH="$HOME/.dotnet"
21+
mkdir -p "$DOTNET_PATH"
22+
curl -sSL https://dot.net/v1/dotnet-install.sh -o $DOTNET_PATH/dotnet-install.sh
23+
chmod +x $DOTNET_PATH/dotnet-install.sh
24+
$DOTNET_PATH/dotnet-install.sh --channel 9.0 --install-dir $DOTNET_PATH
25+
echo "export PATH=$DOTNET_PATH:\$PATH" >> ~/.bashrc
26+
27+
# Moonbit
28+
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
29+
echo 'export PATH="$HOME/.moon/bin:$PATH"' >> ~/.bashrc

tests/README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
# Testing wit-bindgen
22

3-
There are a few pre-requisites to testing the project. You only need the language compilers that you wish to run test against.
3+
## Setup
4+
### Dev container
5+
There are a few pre-requisites to testing the project. The easiest way to get
6+
started is by using the dev container part of this repository. That contains all
7+
the required toolchains in a single Docker container.
8+
9+
### Manual installation
10+
Alternatively, you can install the required tools by hand. You only need the
11+
language compilers that you wish to run test against.
412

513
- WASI SDK
614
- 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-22/wasi-sdk-22.0-linux.tar.gz`
8-
- 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.
15+
- `curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz`
16+
- 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.
917
- Compilers for the target language:
10-
- Rust - wasi target: `rustup target add wasm32-wasip1`
11-
- Java - TeaVM-WASI `ci/download-teamvm.sh`
12-
- C - [Clang](https://clang.llvm.org/)
18+
- Rust - wasi target: `rustup target add wasm32-wasip2`
19+
- C - [Clang](https://clang.llvm.org/) (You can also use the one shipped with WASI SDK)
1320
- C# - [Dotnet 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
21+
- [MoonBit](https://www.moonbitlang.com/download/)
1422

15-
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:
23+
## Test structure
24+
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:
1625

1726
```
1827
cargo test --workspace
@@ -55,11 +64,11 @@ Use `git submodule init` + `git submodule update` before running the tests.
5564

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

58-
You can run all `codegen` tests in rust with the following command:
67+
You can run the `codegen` tests for all languages with the following command:
5968

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

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

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

101+
You can run the `runtime` tests for all languages with the following command:
102+
103+
```sh
104+
cargo run test \
105+
--languages rust,c,cpp,csharp,moonbit \
106+
--artifacts target/artifacts \
107+
--rust-wit-bindgen-path ./crates/guest-rust \
108+
tests/runtime
109+
```
110+
93111
## Testing Layout
94112

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

0 commit comments

Comments
 (0)