Create a dedicated WASI container (#56) · python/cpython-devcontainers@dd196b8

GitHub

Original file line numberDiff line numberDiff line change@@ -19,7 +19,7 @@ jobs:

1919# Dummy tag; version does not matter.

2020TAG: cpython-devcontainer:1.0.0-${{ github.run_id }}

2121steps:

22- - name: Checkout Push to Registry action

22+ - name: Checkout

2323uses: actions/checkout@v5

2424 - name: Set up Docker Buildx

2525uses: docker/setup-buildx-action@v3

@@ -32,6 +32,31 @@ jobs:

3232 - name: Test clang

3333run: docker run --rm ${{ env.TAG }} clang --version

343435+build_wasi_container:

36+name: Build and test (WASI container)

37+strategy:

38+fail-fast: false

39+matrix:

40+os: [ubuntu-latest, ubuntu-24.04-arm]

41+runs-on: ${{ matrix.os }}

42+env:

43+TAG: cpython-wasicontainer:1.0.0-${{ github.run_id }}

44+steps:

45+ - name: Checkout

46+uses: actions/checkout@v5

47+ - name: Set up Docker Buildx

48+uses: docker/setup-buildx-action@v3

49+ - name: Build Dockerfile

50+uses: docker/build-push-action@v6

51+with:

52+context: ./wasicontainer

53+load: true

54+tags: ${{ env.TAG }}

55+ - name: Test WASI SDK

56+run: docker run --rm ${{ env.TAG }} /opt/wasi-sdk/bin/clang --version

57+ - name: Test Wasmtime

58+run: docker run --rm ${{ env.TAG }} wasmtime --version

59+3560build_autoconf:

3661name: Build and test (Autoconf)

3762strategy:

@@ -43,7 +68,7 @@ jobs:

4368env:

4469TAG: autoconf:${{ matrix.autoconf_version }}-${{ github.run_id }}

4570steps:

46- - name: Checkout Push to Registry action

71+ - name: Checkout

4772uses: actions/checkout@v5

4873 - name: Set up Docker Buildx

4974uses: docker/setup-buildx-action@v3

Original file line numberDiff line numberDiff line change@@ -11,6 +11,7 @@ on:

1111options:

1212 - autoconf

1313 - devcontainer

14+ - wasicontainer

14151516run-name: "Release: ${{ inputs.package }}"

1617Original file line numberDiff line numberDiff line change@@ -0,0 +1,20 @@

1+FROM ghcr.io/python/devcontainer:latest

2+3+LABEL org.opencontainers.image.base.name="ghcr.io/python/wasicontainer:latest"

4+LABEL org.opencontainers.image.source="https://github.com/python/cpython-devcontainers"

5+LABEL org.opencontainers.image.title="CPython WASI development container"

6+LABEL org.opencontainers.image.description="CPython development container with the tooling to work on WASI builds."

7+LABEL org.opencontainers.image.authors="Brett Cannon"

8+9+ARG TARGETARCH

10+11+# WASI SDK versions are controlled in install-wasi.sh.

12+ENV WASI_SDK_ROOT=/opt

13+14+ENV WASMTIME_VERSION=36.0.2

15+ENV WASMTIME_HOME=/opt/wasmtime

16+17+RUN mkdir -p /opt/cpython-devcontainer/bin

18+COPY --chmod=755 install-wasi.sh /opt/cpython-devcontainer/bin/

19+20+RUN /opt/cpython-devcontainer/bin/install-wasi.sh

Original file line numberDiff line numberDiff line change@@ -0,0 +1,3 @@

1+A container for developing CPython for WASI.

2+3+It is based on the dev container, and thus includes the same common utilities.

Original file line numberDiff line numberDiff line change@@ -0,0 +1,45 @@

1+#! /bin/bash -ex

2+3+mkdir --parents ${WASI_SDK_ROOT}

4+5+# For 3.11, 3.12.

6+# There is no Arm support for WASI SDK < 23.

7+if [ "${TARGETARCH}"="amd64" ];then

8+ URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/wasi-sdk-16.0-linux.tar.gz

9+ curl --location $URL| tar --directory ${WASI_SDK_ROOT} --extract --gunzip

10+fi

11+12+case"${TARGETARCH}"in

13+ amd64) WASI_ARCH="x86_64" ;;

14+ arm64) WASI_ARCH="arm64" ;;

15+*) echo"Unsupported TARGETARCH: ${TARGETARCH}"&&exit 1 ;;

16+esac&& \

17+18+# 24: 3.13, 3.14

19+# The URL format only works for WASI SDK >= 23.

20+WASI_SDK_VERSIONS=(24)

21+forVERSIONin"${WASI_SDK_VERSIONS[@]}";do

22+ URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${VERSION}/wasi-sdk-${VERSION}.0-${WASI_ARCH}-linux.tar.gz

23+ curl --location $URL| tar --directory ${WASI_SDK_ROOT} --extract --gunzip

24+done

25+26+# For Python 3.13 as Tools/wasm/wasi.py expects /opt/wasi-sdk by default.

27+ln -s ${WASI_SDK_ROOT}/wasi-sdk-24.0*/ /opt/wasi-sdk

28+29+30+mkdir --parents ${WASMTIME_HOME}

31+32+case"${TARGETARCH}"in

33+ amd64) WASMTIME_ARCH="x86_64" ;;

34+ arm64) WASMTIME_ARCH="aarch64" ;;

35+*) echo"Unsupported TARGETARCH: ${TARGETARCH}"&&exit 1 ;;

36+esac

37+38+URL="https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-${WASMTIME_ARCH}-linux.tar.xz"

39+40+curl --location $URL|

41+ xz --decompress |

42+ tar --strip-components 1 --directory ${WASMTIME_HOME} -x

43+44+# Put `wasmtime` on $PATH.

45+ln -s ${WASMTIME_HOME}/wasmtime* /usr/local/bin