-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.binaryen
More file actions
107 lines (89 loc) · 2.83 KB
/
Copy pathDockerfile.binaryen
File metadata and controls
107 lines (89 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Binaryen Component - Emscripten 4.0.16
# Builds Binaryen optimization tools from source
#
# Binaryen revision: c326e66bddcbb899e47358857e3c8ea1a70b6466
# From: emscripten-releases DEPS file for version 4.0.16
#
# Build: docker build -f Dockerfile.binaryen -t ghcr.io/discere-os/wasm-builder-binaryen:c326e66b .
# Time: ~5-10 minutes
# Size: ~200-300MB
#
# Stage 0: Node.js base (shared by all stages)
#
FROM ubuntu:24.04 AS nodejs-base
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV TZ=Pacific/Auckland
# Install Node.js 22 once, shared by all stages
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*
#
# Stage 1: Builder base
#
FROM nodejs-base AS builder-base
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
# Core build tools
build-essential \
cmake \
ninja-build \
git \
python3 \
python3-pip \
# Download tools
curl \
wget \
ca-certificates \
# Utilities
pkg-config \
file \
&& rm -rf /var/lib/apt/lists/*
#
# Stage 2: Build Binaryen
#
FROM builder-base AS binaryen-builder
# Binaryen revision from emscripten-releases DEPS file for version 4.0.16
# See: https://github.com/emscripten-core/emscripten/blob/main/docs/packaging.md
# This exact commit ensures compatibility with Emscripten 4.0.16
ARG BINARYEN_REVISION=c326e66bddcbb899e47358857e3c8ea1a70b6466
WORKDIR /build
# Clone Binaryen at specific revision
RUN git clone --depth 1 https://github.com/WebAssembly/binaryen.git && \
cd binaryen && \
git fetch --depth 1 origin ${BINARYEN_REVISION} && \
git checkout ${BINARYEN_REVISION} && \
git submodule update --init --force
# Build Binaryen
RUN mkdir binaryen/build && cd binaryen/build && \
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/binaryen \
.. && \
ninja && \
ninja install
# Strip debug symbols from binaries to reduce size
RUN strip /opt/binaryen/bin/* 2>/dev/null || true
# Verify required Binaryen tools exist
RUN for tool in wasm-opt wasm-emscripten-finalize wasm-as wasm-dis wasm2js wasm-metadce; do \
if [ ! -f "/opt/binaryen/bin/$tool" ]; then \
echo "ERROR: Required tool $tool not found"; \
exit 1; \
fi; \
done
# Clean up build artifacts
RUN rm -rf /build && \
echo "Binaryen build complete" && \
echo "Binaryen size: $(du -sh /opt/binaryen | cut -f1)"
# Final stage - Binaryen only
FROM ubuntu:24.04
COPY --from=binaryen-builder /opt/binaryen /opt/binaryen
ENV PATH="/opt/binaryen/bin:${PATH}"
# Verify installation
RUN wasm-opt --version && \
echo "Binaryen Component Ready"
WORKDIR /workspace