Created
November 8, 2024 08:18
-
-
Save narumichiaki/0cb32c5b6db64493d19066a9ca3aeccb to your computer and use it in GitHub Desktop.
Dockerfile to compile jiter to wheel for Pyodide/Pyscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explanation (in Japanese): https://qiita.com/narumichiaki/items/84d1e36f6b3180bdc642