Repository navigation
Expand file tree
/
Copy pathDockerfile.native
More file actions
121 lines (108 loc) · 5.09 KB
/
Copy pathDockerfile.native
File metadata and controls
121 lines (108 loc) · 5.09 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
114
115
116
117
118
119
120
121
# Dockerfile.native — xeus-lean base image (kernel + Display lib).
#
# Published as `ghcr.io/verilean/xeus-lean:latest`. Downstream
# projects FROM this and use the generic `XEUS_LEAN_EXTRA_LIBS`
# extension point declared in `lakefile.lean` to thread their own
# static libraries into xlean. See README.md ("Extending the
# kernel with your own Lean lib") and `tests/fixtures/mock-extra/`
# for the worked example.
#
# Run as a JupyterLab server:
# docker run --rm -it -p 8888:8888 ghcr.io/verilean/xeus-lean:latest
#
# Or as the base for a downstream image:
# FROM ghcr.io/verilean/xeus-lean:latest
# COPY my-lib/ /app/my-lib/
# RUN cd /app/my-lib && lake build mylib
# RUN ar rcs /app/build-cmake/libmy_olean.a /app/my-lib/.lake/.../*.c.o.export
# RUN rm -f /app/.lake/build/bin/xlean && \
# XEUS_LEAN_EXTRA_LIBS="-Wl,--whole-archive /app/build-cmake/libmy_olean.a -Wl,--no-whole-archive" \
# lake build xlean
FROM ubuntu:24.04
# tzdata and a few other packages drop into an interactive prompt
# during install if they cannot detect the host timezone, which hangs
# `docker build` forever.
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake build-essential nlohmann-json3-dev \
uuid-dev libssl-dev python3 python3-pip \
clang libc++-dev libc++abi-dev \
curl git ca-certificates \
zstd \
&& rm -rf /var/lib/apt/lists/*
# jupyter_client drives smoke-test-native.py; jupyterlab is what users
# open in their browser when they `docker run` this image.
RUN pip install --break-system-packages --no-cache-dir jupyter_client jupyterlab
# Install Lean via elan. Pre-fetch the toolchain in the same layer
# so a transient releases.lean-lang.org timeout fails *here* (where
# bash retry works) rather than later under cmake/lake (where it
# manifests as "Could not find LEAN_LIBRARY"). CI hit the latter on
# run 27171954909.
ENV PATH="/root/.elan/bin:${PATH}"
RUN set -eu; \
for attempt in 1 2 3; do \
curl --retry 5 --retry-delay 5 --retry-connrefused \
https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf \
| sh -s -- -y --default-toolchain leanprover/lean4:v4.28.0 && break; \
echo "elan install attempt $attempt failed; retrying"; \
rm -rf /root/.elan; sleep 10; \
done; \
# Sanity-check: lean must actually be present after install.
lean --version
WORKDIR /app
COPY CMakeLists.txt lakefile.lean lake-manifest.json lean-toolchain /app/
COPY cmake/ /app/cmake/
COPY include/ /app/include/
COPY src/ /app/src/
# Build the C++ FFI library (xeus, xeus-zmq, libzmq fetched via cmake).
RUN cmake -S . -B build-cmake \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" && \
cmake --build build-cmake -j
# Linux glibc C23 shim (clang -> __isoc23_strtoull -> Lean's older glibc).
RUN leanc -c src/glibc_isoc23_compat.c -o build-cmake/glibc_isoc23_compat.o
# Build the kernel binary + the Display lib (so notebook cells can
# `import Display` for inline SVG/HTML/Markdown rich output, plus the
# new comm-driven waveform viewer).
RUN lake build xlean Display CommBus
# Register the kernelspec under /root/.local/share/jupyter so that
# `jupyter lab` finds it. install-kernelspec.sh writes LD_LIBRARY_PATH
# but not LEAN_PATH / PATH; we append both here so Display oleans
# resolve and `bv_decide` can spawn the cadical bundled with elan.
COPY scripts/ /app/scripts/
RUN bash scripts/install-kernelspec.sh --user
RUN python3 -c "import json,pathlib; \
p=pathlib.Path('/root/.local/share/jupyter/kernels/xlean/kernel.json'); \
spec=json.loads(p.read_text()); \
env=spec.get('env',{}); \
env['LEAN_PATH']='/app/.lake/build/lib/lean'; \
env['PATH']='/root/.elan/toolchains/leanprover--lean4---v4.28.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'; \
spec['env']=env; \
p.write_text(json.dumps(spec,indent=2))"
# Smoke-test the kernel inside the image so a broken build fails the
# `docker build` rather than silently shipping.
RUN python3 scripts/smoke-test-native.py
# Strip build-time crud that doesn't need to ship: cmake FetchContent
# leaves a full `.git/` for each dep (xeus, xeus-zmq, xtl, cppzmq,
# libzmq) plus assorted upstream dotfiles. None of it is sensitive,
# but removing it shaves several hundred MB and tightens the image.
RUN find /app/build-cmake/_deps -type d -name ".git" -prune -exec rm -rf {} + 2>/dev/null; \
find /app \
\( -name ".clang-format" -o -name ".clang-tidy" \
-o -name ".travis.yml" -o -name ".hgeol" \
-o -name ".mailmap" -o -name ".git-blame-ignore-revs" \
-o -name ".releash.py" -o -name ".gitignore" \
-o -name ".dockerignore" -o -name ".envrc" \) \
-delete 2>/dev/null; \
true
# Pre-populate /notebooks so users see something on first launch even
# without a -v mount.
RUN mkdir -p /notebooks
# Default command: launch JupyterLab serving /notebooks on :8888.
WORKDIR /notebooks
EXPOSE 8888
CMD ["jupyter", "lab", \
"--ip=0.0.0.0", "--allow-root", "--no-browser", \
"--ServerApp.token=", "--ServerApp.password="]