-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathDockerfile.zed-build
More file actions
113 lines (104 loc) · 4.31 KB
/
Dockerfile.zed-build
File metadata and controls
113 lines (104 loc) · 4.31 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
108
109
110
111
112
113
# ====================================================================
# Ubuntu 25.10 Build Environment for Zed Editor
# ====================================================================
# Uses Ubuntu 25.10 to match Sway/KDE and GNOME containers.
# BuildKit cache mounts persist cargo registry, git deps, rustup
# toolchain, and build artifacts across builds.
#
# Usage:
# Local: ./stack build-zed [dev|release] (builds full image with Zed source as context)
# CI: docker build --target builder-env -t zed-builder:ubuntu25 -f Dockerfile.zed-build .
# (builds just the environment; actual compilation runs via docker run with volume mounts)
# ====================================================================
# --- Stage 1: Build environment (deps + rustup, no source or compilation) ---
FROM ubuntu:25.10@sha256:4a9232cc47bf99defcc8860ef6222c99773330367fcecbf21ba2edb0b810a31e AS builder-env
ENV DEBIAN_FRONTEND=noninteractive
# Install Zed build dependencies (cached as Docker layer)
# Based on Zed's official build requirements + additional libs for full feature support
RUN apt-get update && apt-get install -y \
# Core build tools
build-essential \
curl \
git \
pkg-config \
clang \
cmake \
mold \
# SSL/crypto
libssl-dev \
# Compression
libzstd-dev \
# Database
libsqlite3-dev \
# Graphics/Vulkan
libvulkan-dev \
# Wayland support
libwayland-dev \
libxkbcommon-dev \
# X11/XCB support
libxcb-shape0-dev \
libxcb-xfixes0-dev \
libxcb-render0-dev \
libxcb1-dev \
libx11-dev \
libx11-xcb-dev \
libxrandr-dev \
# XKB support
libxkbcommon-x11-dev \
# Font rendering
libfreetype-dev \
libfontconfig-dev \
# Audio (package renamed in Ubuntu 24.04+)
libasound2-dev \
# GTK/GUI
libatk1.0-dev \
libgtk-3-dev \
libglib2.0-dev \
&& rm -rf /var/lib/apt/lists/*
# Install rustup minimal installer (no toolchain yet — that comes from rust-toolchain.toml)
ENV RUSTUP_HOME=/root/.rustup
ENV CARGO_HOME=/root/.cargo
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
ENV PATH="/root/.cargo/bin:${PATH}"
# --- Stage 2: Full build (copies source, compiles Zed) ---
# Only reached when building locally with Zed source as Docker context.
# CI uses --target builder-env to stop before this stage.
FROM builder-env AS builder
ARG BUILD_TYPE=release
# Copy source (filtered by .dockerignore — excludes target/, .git/)
COPY . /zed
WORKDIR /zed
# Build with BuildKit cache mounts:
# - /root/.cargo/registry: crate index + source archives
# - /root/.cargo/git: git dependency checkouts
# - /root/.rustup: toolchain + rustup data (entire dir cached so rename() works)
# - /zed/target-ubuntu25-v3: build artifacts (incremental compilation)
#
# On first run, the rustup cache mount is empty so we bootstrap from the layer.
# The cargo binary is in /root/.cargo/bin which is NOT cache-mounted (just registry/git).
#
# NOTE: Bump the target dir version (v3, v4, ...) if incremental compilation
# produces stale artifacts after struct/field changes. The old mount gets GC'd.
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/root/.rustup \
--mount=type=cache,target=/zed/target-ubuntu25-v3 \
if [ ! -f /root/.rustup/settings.toml ]; then \
echo "Bootstrapping rustup in cache mount..." && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none; \
fi && \
if [ -f rust-toolchain.toml ] && [ ! -s rust-toolchain.toml ]; then \
echo "ERROR: rust-toolchain.toml exists but is empty — Docker context is stale." && \
echo "Try: docker builder prune --filter type=regular (preserves cache mounts)" && \
exit 1; \
fi && \
CARGO_TARGET_DIR=target-ubuntu25-v3 \
RUSTFLAGS='-C link-arg=-s' \
cargo build \
$(if [ "$BUILD_TYPE" = "release" ]; then echo "--release"; else echo ""; fi) \
--features external_websocket_sync \
&& CARGO_OUT_DIR=$(if [ "$BUILD_TYPE" = "release" ]; then echo "release"; else echo "debug"; fi) \
&& cp target-ubuntu25-v3/${CARGO_OUT_DIR}/zed /zed-binary
# Output stage — just the binary, nothing else
FROM scratch
COPY --from=builder /zed-binary /zed