From c0003d6b9e25c82a07e62ca4cd1198747378f787 Mon Sep 17 00:00:00 2001 From: Jason Washburn <35488541+jasonwashburn@users.noreply.github.com> Date: Thu, 27 Apr 2023 11:48:00 +0000 Subject: [PATCH 01/14] adds base container build with deps Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 41 +++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..6fc65aa --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,41 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/rust/.devcontainer/base.Dockerfile + +# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye +ARG VARIANT="bullseye" + +FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} + +ARG WASI_VERSION="16" + +ARG SPIN_VERSION="canary" + +ENV WASI_VERSION_FULL=${WASI_VERSION}.0 + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# Install rust components +RUN rustup update stable \ + && rustup default stable \ + && rustup component add clippy rustfmt \ + && rustup target add wasm32-wasi wasm32-unknown-unknown + +# Install cPython build dependencies +RUN echo 'deb-src http://deb.debian.org/debian bullseye main' >> /etc/apt/sources.list \ + && sudo apt update \ + && sudo apt-get -y build-dep python3 \ + && sudo apt-get -y install pkg-config + +# Install WASI-SDK +RUN cd /tmp \ + && wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ + && tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ + && sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \ + && cd - + +# Install Spin +RUN cd /tmp \ + && curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash -s -- -v $SPIN_VERSION \ + && sudo mv spin /usr/local/bin/ \ + && cd - \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fdf23ed --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,49 @@ +// 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.224.2/containers/rust +{ + "name": "Rust", + "build": { + "dockerfile": "Dockerfile", + "args": { + // Use the VARIANT arg to pick a Debian OS version: buster, bullseye + // Use bullseye when on local on arm64/Apple Silicon. + "VARIANT": "bullseye", + "WASI_VERSION": "16", + "SPIN_VERSION": "canary" + } + }, + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Set *default* container specific settings.json values on container create. + "customizations": { + "vscode": { + "settings": { + "lldb.executable": "/usr/bin/lldb", + // VS Code don't watch files under ./target + "files.watcherExclude": { + "**/target/**": true + }, + "rust-analyzer.checkOnSave.command": "clippy" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "vadimcn.vscode-lldb", + "mutantdino.resourcemonitor", + "matklad.rust-analyzer", + "tamasfe.even-better-toml", + "serayuzgur.crates" + ] + } + }, + + + // 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": "sh ./.devcontainer/bootstrap.sh", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} \ No newline at end of file From 6e23add959e9a4ef60e6cdb3fc5fb20f02221558 Mon Sep 17 00:00:00 2001 From: Jason Washburn <35488541+jasonwashburn@users.noreply.github.com> Date: Fri, 28 Apr 2023 10:05:06 +0000 Subject: [PATCH 02/14] adds post creation commands Signed-off-by: Jason Washburn --- .devcontainer/devcontainer.json | 2 +- .devcontainer/postCreateCommands.sh | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/postCreateCommands.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fdf23ed..0774b11 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,7 +42,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "sh ./.devcontainer/bootstrap.sh", + "postCreateCommand": "sh ./.devcontainer/postCreateCommands.sh", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" diff --git a/.devcontainer/postCreateCommands.sh b/.devcontainer/postCreateCommands.sh new file mode 100755 index 0000000..23f7229 --- /dev/null +++ b/.devcontainer/postCreateCommands.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Build cPython +git submodule update --init --recursive +mkdir -p cpython/builddir/wasi +mkdir -p cpython/builddir/build +cd cpython/builddir/build +../../configure --prefix=$(pwd)/install --enable-optimizations +make +cd ../wasi +CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \ + ../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \ + --with-build-python=$(pwd)/../build/python --prefix=$(pwd)/install --disable-test-modules +make +make install +cd ../../.. + +# Build spin-python-cli +make \ No newline at end of file From e21208ba027ddbe6aaaeb1565a0da62eb2959a0e Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Sat, 29 Apr 2023 05:59:43 -0500 Subject: [PATCH 03/14] added variant arg to deb-src modification Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 6fc65aa..12b71bd 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -5,6 +5,8 @@ ARG VARIANT="bullseye" FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} +ARG VARIANT + ARG WASI_VERSION="16" ARG SPIN_VERSION="canary" @@ -22,8 +24,8 @@ RUN rustup update stable \ && rustup target add wasm32-wasi wasm32-unknown-unknown # Install cPython build dependencies -RUN echo 'deb-src http://deb.debian.org/debian bullseye main' >> /etc/apt/sources.list \ - && sudo apt update \ +RUN echo "deb-src http://deb.debian.org/debian $VARIANT main" >> /etc/apt/sources.list \ + && sudo apt-get update \ && sudo apt-get -y build-dep python3 \ && sudo apt-get -y install pkg-config From 1e5048252e79fb390fef7481a0bb912e27607081 Mon Sep 17 00:00:00 2001 From: Jason Washburn <35488541+jasonwashburn@users.noreply.github.com> Date: Mon, 8 May 2023 23:44:51 +0000 Subject: [PATCH 04/14] adds python install with tools Signed-off-by: Jason Washburn --- .devcontainer/devcontainer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0774b11..4cd4fb4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -37,6 +37,13 @@ } }, + "features": { + "ghcr.io/devcontainers/features/python:1": { + "installTools": true, + "version": "3.11" + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], From 22ec95900ee0e34a1301ba75d1d4add523f1a4f5 Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Sat, 8 Jul 2023 12:47:48 +0000 Subject: [PATCH 05/14] build spin from source in devcontainer Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 7 ++++--- .devcontainer/devcontainer.json | 1 + .devcontainer/postCreateCommands.sh | 9 +++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 12b71bd..e874f43 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -38,6 +38,7 @@ RUN cd /tmp \ # Install Spin RUN cd /tmp \ - && curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash -s -- -v $SPIN_VERSION \ - && sudo mv spin /usr/local/bin/ \ - && cd - \ No newline at end of file + && git clone -b $SPIN_VERSION https://github.com/fermyon/spin \ + && cd spin \ + && make build \ + && cp ./target/release/spin /usr/local/bin diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4cd4fb4..fc41e1f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,7 @@ { "name": "Rust", "build": { + "context": "../", "dockerfile": "Dockerfile", "args": { // Use the VARIANT arg to pick a Debian OS version: buster, bullseye diff --git a/.devcontainer/postCreateCommands.sh b/.devcontainer/postCreateCommands.sh index 23f7229..8e48999 100755 --- a/.devcontainer/postCreateCommands.sh +++ b/.devcontainer/postCreateCommands.sh @@ -1,19 +1,16 @@ #!/bin/bash -# Build cPython +# Build cPython for wasm32 git submodule update --init --recursive mkdir -p cpython/builddir/wasi mkdir -p cpython/builddir/build cd cpython/builddir/build ../../configure --prefix=$(pwd)/install --enable-optimizations -make +make -j$(nproc) -s cd ../wasi CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \ ../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \ --with-build-python=$(pwd)/../build/python --prefix=$(pwd)/install --disable-test-modules -make +make -j$(nproc) -s make install cd ../../.. - -# Build spin-python-cli -make \ No newline at end of file From abca37a05093cc85aa42bcfd01c98b97cba96601 Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Sat, 8 Jul 2023 20:49:47 +0000 Subject: [PATCH 06/14] moved spin install to postCreate Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 9 ++------- .devcontainer/postCreateCommands.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e874f43..d22b588 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,6 +13,8 @@ ARG SPIN_VERSION="canary" ENV WASI_VERSION_FULL=${WASI_VERSION}.0 +ENV SPIN_VERSION=${SPIN_VERSION} + # [Optional] Uncomment this section to install additional packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends @@ -35,10 +37,3 @@ RUN cd /tmp \ && tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ && sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \ && cd - - -# Install Spin -RUN cd /tmp \ - && git clone -b $SPIN_VERSION https://github.com/fermyon/spin \ - && cd spin \ - && make build \ - && cp ./target/release/spin /usr/local/bin diff --git a/.devcontainer/postCreateCommands.sh b/.devcontainer/postCreateCommands.sh index 8e48999..7a9165b 100755 --- a/.devcontainer/postCreateCommands.sh +++ b/.devcontainer/postCreateCommands.sh @@ -1,5 +1,15 @@ #!/bin/bash +set -ex + +# Build and install spin from source +cd /tmp +git clone -b $SPIN_VERSION https://github.com/fermyon/spin +cd spin +make build +sudo cp ./target/release/spin /usr/local/bin +cd /workspaces/spin-python-sdk + # Build cPython for wasm32 git submodule update --init --recursive mkdir -p cpython/builddir/wasi From c5f514449c3fd91d1e9f075af547a13bc9e5168a Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Thu, 27 Jul 2023 01:54:44 +0000 Subject: [PATCH 07/14] updates devcontainer python version Signed-off-by: Jason Washburn --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fc41e1f..ac4c554 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -41,7 +41,7 @@ "features": { "ghcr.io/devcontainers/features/python:1": { "installTools": true, - "version": "3.11" + "version": "3.11.4" } }, From d3c9675672b263570a2a28345cdb7a30a7248a03 Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Thu, 27 Jul 2023 01:56:15 +0000 Subject: [PATCH 08/14] devcontainer: use spin installer vs src Signed-off-by: Jason Washburn --- .devcontainer/postCreateCommands.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.devcontainer/postCreateCommands.sh b/.devcontainer/postCreateCommands.sh index 7a9165b..02da6b2 100755 --- a/.devcontainer/postCreateCommands.sh +++ b/.devcontainer/postCreateCommands.sh @@ -2,12 +2,10 @@ set -ex -# Build and install spin from source +# Install spin cd /tmp -git clone -b $SPIN_VERSION https://github.com/fermyon/spin -cd spin -make build -sudo cp ./target/release/spin /usr/local/bin +curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash +sudo mv ./spin /usr/local/bin/spin cd /workspaces/spin-python-sdk # Build cPython for wasm32 From 09fe303710b07000ff888c79164a3357b027b4a3 Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Tue, 15 Aug 2023 23:27:52 +0000 Subject: [PATCH 09/14] limits devcontainer build to dependencies only Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 30 ++++++++++++++++++++---------- .devcontainer/devcontainer.json | 3 +-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d22b588..f686626 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,31 +9,41 @@ ARG VARIANT ARG WASI_VERSION="16" -ARG SPIN_VERSION="canary" - ENV WASI_VERSION_FULL=${WASI_VERSION}.0 -ENV SPIN_VERSION=${SPIN_VERSION} - # [Optional] Uncomment this section to install additional packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends # Install rust components -RUN rustup update stable \ +RUN echo -e "${GREEN_COLOR}Installing Rust components...${RESET_COLOR}" \ + && rustup update stable \ && rustup default stable \ && rustup component add clippy rustfmt \ - && rustup target add wasm32-wasi wasm32-unknown-unknown + && rustup target add wasm32-wasi wasm32-unknown-unknown \ + && echo -e "${GREEN_COLOR}Rust components installed.${RESET_COLOR}" # Install cPython build dependencies -RUN echo "deb-src http://deb.debian.org/debian $VARIANT main" >> /etc/apt/sources.list \ +RUN echo -e "${GREEN_COLOR}Installing cPython build dependencies...${RESET_COLOR}" \ + && echo "deb-src http://deb.debian.org/debian $VARIANT main" >> /etc/apt/sources.list \ && sudo apt-get update \ && sudo apt-get -y build-dep python3 \ - && sudo apt-get -y install pkg-config + && sudo apt-get -y install pkg-config \ + && echo -e "${GREEN_COLOR}cPython build dependencies installed.${RESET_COLOR}" # Install WASI-SDK -RUN cd /tmp \ +RUN echo -e "${GREEN_COLOR}Installing WASI-SDK ${WASI_VERSION}...${RESET_COLOR}" \ + && cd /tmp \ && wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ && tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ && sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \ - && cd - + && cd - \ + && echo -e "${GREEN_COLOR}WASI-SDK installed.${RESET_COLOR}" + +# Install Spin +RUN echo -e "${GREEN_COLOR}Installing Spin...${RESET_COLOR}" \ + && cd /tmp \ + && curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash \ + && sudo mv ./spin /usr/local/bin/spin \ + && cd - + && echo -e "${GREEN_COLOR}Spin installed.${RESET_COLOR}" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ac4c554..fa4ea8a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,7 +10,6 @@ // Use bullseye when on local on arm64/Apple Silicon. "VARIANT": "bullseye", "WASI_VERSION": "16", - "SPIN_VERSION": "canary" } }, "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], @@ -50,7 +49,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "sh ./.devcontainer/postCreateCommands.sh", + // "postCreateCommand": "", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" From b8878a54f0d52979ef9a04132e46576929c6804d Mon Sep 17 00:00:00 2001 From: Jason Washburn <35488541+jasonwashburn@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:33:17 -0500 Subject: [PATCH 10/14] removed unnecessary status messages from devcontainer build Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f686626..ed16364 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -16,34 +16,26 @@ ENV WASI_VERSION_FULL=${WASI_VERSION}.0 # && apt-get -y install --no-install-recommends # Install rust components -RUN echo -e "${GREEN_COLOR}Installing Rust components...${RESET_COLOR}" \ - && rustup update stable \ +RUN rustup update stable \ && rustup default stable \ && rustup component add clippy rustfmt \ - && rustup target add wasm32-wasi wasm32-unknown-unknown \ - && echo -e "${GREEN_COLOR}Rust components installed.${RESET_COLOR}" + && rustup target add wasm32-wasi wasm32-unknown-unknown # Install cPython build dependencies -RUN echo -e "${GREEN_COLOR}Installing cPython build dependencies...${RESET_COLOR}" \ - && echo "deb-src http://deb.debian.org/debian $VARIANT main" >> /etc/apt/sources.list \ +RUN echo "deb-src http://deb.debian.org/debian $VARIANT main" >> /etc/apt/sources.list \ && sudo apt-get update \ && sudo apt-get -y build-dep python3 \ - && sudo apt-get -y install pkg-config \ - && echo -e "${GREEN_COLOR}cPython build dependencies installed.${RESET_COLOR}" + && sudo apt-get -y install pkg-config # Install WASI-SDK -RUN echo -e "${GREEN_COLOR}Installing WASI-SDK ${WASI_VERSION}...${RESET_COLOR}" \ - && cd /tmp \ +RUN cd /tmp \ && wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ && tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ && sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \ - && cd - \ - && echo -e "${GREEN_COLOR}WASI-SDK installed.${RESET_COLOR}" + && cd - # Install Spin -RUN echo -e "${GREEN_COLOR}Installing Spin...${RESET_COLOR}" \ - && cd /tmp \ +RUN cd /tmp \ && curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash \ && sudo mv ./spin /usr/local/bin/spin \ && cd - - && echo -e "${GREEN_COLOR}Spin installed.${RESET_COLOR}" From 0ad1436e6ee4ed3bf3cd430896abcbdf2c4615f7 Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Tue, 15 Aug 2023 18:56:00 -0500 Subject: [PATCH 11/14] adds git submodule update to readme Signed-off-by: Jason Washburn --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de96b84..9fb8795 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,12 @@ spin up ### Instructions -First, build CPython for wasm32-wasi. +First, perform a git submodule update to update the cpython submodule +```bash +git submodule update --init --recursive +``` + +Then, build CPython for wasm32-wasi. ```bash ./build-python.sh From 08a8b34b3587fac673f1fc826d3e95d6fdc5aa6e Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Wed, 16 Aug 2023 00:23:24 +0000 Subject: [PATCH 12/14] adds note about devcontainer deps to readme Signed-off-by: Jason Washburn --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9fb8795..9928ea9 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ spin up ## Building and Running ### Prerequisites +__Note__: When using the devcontainer for development, the following dependencies are already installed for you... - [WASI SDK](https://github.com/WebAssembly/wasi-sdk) v16 or later, installed in /opt/wasi-sdk - [CPython](https://github.com/python/cpython) build prereqs (e.g. Make, Clang, etc.) @@ -37,6 +38,7 @@ spin up - [Spin](https://github.com/fermyon/spin) - [pipenv](https://pypi.org/project/pipenv/) for installing Python project dependencies + ### Instructions First, perform a git submodule update to update the cpython submodule From 116bf0104e0cab2ee6397d9c14450e72e4228ca0 Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Tue, 12 Sep 2023 11:27:36 +0000 Subject: [PATCH 13/14] devcontainer uses artifact wasi cpython Signed-off-by: Jason Washburn --- .devcontainer/Dockerfile | 30 +++++------------- .devcontainer/devcontainer.json | 47 ++++++++++++++--------------- .devcontainer/onCreateCommands.sh | 28 +++++++++++++++++ .devcontainer/postCreateCommands.sh | 24 --------------- 4 files changed, 59 insertions(+), 70 deletions(-) create mode 100755 .devcontainer/onCreateCommands.sh delete mode 100755 .devcontainer/postCreateCommands.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ed16364..476c9bb 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,9 +1,7 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/rust/.devcontainer/base.Dockerfile -# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye ARG VARIANT="bullseye" -FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} +FROM mcr.microsoft.com/devcontainers/base:$VARIANT ARG VARIANT @@ -15,27 +13,15 @@ ENV WASI_VERSION_FULL=${WASI_VERSION}.0 # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends -# Install rust components -RUN rustup update stable \ - && rustup default stable \ - && rustup component add clippy rustfmt \ - && rustup target add wasm32-wasi wasm32-unknown-unknown - -# Install cPython build dependencies -RUN echo "deb-src http://deb.debian.org/debian $VARIANT main" >> /etc/apt/sources.list \ - && sudo apt-get update \ - && sudo apt-get -y build-dep python3 \ - && sudo apt-get -y install pkg-config - # Install WASI-SDK RUN cd /tmp \ - && wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ - && tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ - && sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \ - && cd - +&& wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ +&& tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \ +&& sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \ +&& cd - # Install Spin RUN cd /tmp \ - && curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash \ - && sudo mv ./spin /usr/local/bin/spin \ - && cd - +&& curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash \ +&& sudo mv ./spin /usr/local/bin/spin \ +&& cd - diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fa4ea8a..91a094e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,20 +1,26 @@ -// 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.224.2/containers/rust +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu { - "name": "Rust", + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "build": { "context": "../", "dockerfile": "Dockerfile", "args": { - // Use the VARIANT arg to pick a Debian OS version: buster, bullseye - // Use bullseye when on local on arm64/Apple Silicon. - "VARIANT": "bullseye", + "VARIANT": "jammy", "WASI_VERSION": "16", } }, - "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], - - // Set *default* container specific settings.json values on container create. + "features": { + "ghcr.io/devcontainers/features/python:1": { + "installTools": true, + "version": "3.11" + }, + "ghcr.io/devcontainers/features/rust:1": { + "version": "latest", + "profile": "minimal" + } + }, "customizations": { "vscode": { "settings": { @@ -25,7 +31,6 @@ }, "rust-analyzer.checkOnSave.command": "clippy" }, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "vadimcn.vscode-lldb", @@ -36,21 +41,15 @@ ] } }, - - "features": { - "ghcr.io/devcontainers/features/python:1": { - "installTools": true, - "version": "3.11.4" - } - }, - - + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - + "onCreateCommand": ".devcontainer/onCreateCommands.sh", // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "", - - // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + // "postCreateCommand": "uname -a", + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } \ No newline at end of file diff --git a/.devcontainer/onCreateCommands.sh b/.devcontainer/onCreateCommands.sh new file mode 100755 index 0000000..6b7eb46 --- /dev/null +++ b/.devcontainer/onCreateCommands.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -ex +ARTIFACT_PY_VERSION="3.11.4" +ARTIFACT_SDK_VERSION="16" + + +# Install rust components +rustup update stable +rustup default stable +rustup component add clippy rustfmt +rustup target add wasm32-wasi wasm32-unknown-unknown + +# Fetch WASI compiled cPython artifact +mkdir -p cpython/builddir/wasi/install + +cd cpython/builddir/wasi/install +wget https://github.com/brettcannon/cpython-wasi-build/releases/download/v${ARTIFACT_PY_VERSION}/python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip +unzip python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip + +cd - +cd cpython/builddir/wasi +wget https://github.com/brettcannon/cpython-wasi-build/releases/download/v${ARTIFACT_PY_VERSION}/_build-python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip +unzip _build-python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip +cd - + +# Make Spin Python SDK +make \ No newline at end of file diff --git a/.devcontainer/postCreateCommands.sh b/.devcontainer/postCreateCommands.sh deleted file mode 100755 index 02da6b2..0000000 --- a/.devcontainer/postCreateCommands.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -ex - -# Install spin -cd /tmp -curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash -sudo mv ./spin /usr/local/bin/spin -cd /workspaces/spin-python-sdk - -# Build cPython for wasm32 -git submodule update --init --recursive -mkdir -p cpython/builddir/wasi -mkdir -p cpython/builddir/build -cd cpython/builddir/build -../../configure --prefix=$(pwd)/install --enable-optimizations -make -j$(nproc) -s -cd ../wasi -CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \ - ../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \ - --with-build-python=$(pwd)/../build/python --prefix=$(pwd)/install --disable-test-modules -make -j$(nproc) -s -make install -cd ../../.. From f6dab681230ba45b17265ebf6bf87833ff82ba3b Mon Sep 17 00:00:00 2001 From: Jason Washburn Date: Tue, 12 Sep 2023 11:44:27 +0000 Subject: [PATCH 14/14] updated readme Signed-off-by: Jason Washburn --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9928ea9..2c47320 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ spin up ## Building and Running ### Prerequisites -__Note__: When using the devcontainer for development, the following dependencies are already installed for you... +__Note__: When using the devcontainer for development, the following dependencies are already installed for you. To prevent speed up build times and prevent compatibility issues, a pre-compiled artifact of cpython for wasi is used rather than compiling from source. (https://github.com/brettcannon/cpython-wasi-build/releases/tag/v3.11.4) - [WASI SDK](https://github.com/WebAssembly/wasi-sdk) v16 or later, installed in /opt/wasi-sdk - [CPython](https://github.com/python/cpython) build prereqs (e.g. Make, Clang, etc.) @@ -41,18 +41,18 @@ __Note__: When using the devcontainer for development, the following dependencie ### Instructions -First, perform a git submodule update to update the cpython submodule +First, perform a git submodule update to update the cpython submodule. **(Unnecessary if using devcontainer)** ```bash git submodule update --init --recursive ``` -Then, build CPython for wasm32-wasi. +Then, build CPython for wasm32-wasi. **(Unnecessary if using devcontainer)** ```bash ./build-python.sh ``` -Then, build the `spin-python-cli`: +Then, build the `spin-python-cli`: **(Unnecessary if using devcontainer)** ```bash make