Skip to content

Instantly share code, notes, and snippets.

@narumichiaki
Created November 8, 2024 08:18
Show Gist options
  • Save narumichiaki/0cb32c5b6db64493d19066a9ca3aeccb to your computer and use it in GitHub Desktop.
Save narumichiaki/0cb32c5b6db64493d19066a9ca3aeccb to your computer and use it in GitHub Desktop.
Dockerfile to compile jiter to wheel for Pyodide/Pyscript
# wasm32 compiler of jiter-python
# For PyScript 2024.10.1 - Required Python 3.12 and Emscripten 3.1.58
# USAGE: DOCKER_BUILDKIT=1 docker build --file Dockerfile --output out .
FROM python:3.12 AS builder
# Install pyodide-build
RUN pip install pyodide-build==0.26.3
# Install Latest Rust using rustup
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal
ENV PATH $PATH:/root/.cargo/bin
# Add Rust WASM target (Nightly version is required for wasm32-unknown-emscripten)
RUN rustup toolchain install nightly
RUN rustup target add --toolchain nightly wasm32-unknown-emscripten
# Install Emscripten
RUN git clone https://github.com/emscripten-core/emsdk.git
WORKDIR /emsdk
RUN ./emsdk install 3.1.58
RUN ./emsdk activate 3.1.58
# ./emsdk_env.sh (Fails when use emsdk_env.sh directly)
ENV PATH $PATH:/emsdk:/emsdk/upstream/emscripten:/emsdk/node/20.18.0_64bit/bin
ENV EMSDK /emsdk
ENV EMSDK_NODE /emsdk/node/20.18.0_64bit/bin/node
WORKDIR /
# Set environment variables for Emscripten
ENV PYO3_CROSS_PYTHON_VERSION 3.12
ENV PYO3_CROSS_LIB_DIR /usr/local/lib
# Get jiter
RUN git clone --depth 1 https://github.com/pydantic/jiter.git
# Build
WORKDIR /jiter/crates/jiter-python
RUN pyodide venv .venv-pyodide
RUN . .venv-pyodide/bin/activate \
&& RUSTUP_TOOLCHAIN=nightly pyodide build
# Export
FROM scratch AS export-stage
COPY --from=builder /jiter/crates/jiter-python/dist .
@narumichiaki
Copy link
Author

narumichiaki commented Nov 8, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment