1- FROM nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
1+ # Multi-stage build to keep the final image lean while providing CUDA, LLVM 7, and Rust.
2+ FROM nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 AS builder
23
3- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
4- build-essential \
5- curl \
6- clang \
7- libssl-dev \
8- libtinfo-dev \
9- pkg-config \
10- xz-utils \
11- zlib1g-dev && \
4+ RUN apt-get update && \
5+ DEBIAN_FRONTEND=noninteractive apt-get -y install \
6+ build-essential \
7+ clang \
8+ cmake \
9+ curl \
10+ libffi-dev \
11+ libfontconfig-dev \
12+ libssl-dev \
13+ libtinfo-dev \
14+ libedit-dev \
15+ libncurses5-dev \
16+ libxml2-dev \
17+ libx11-xcb-dev \
18+ libxcursor-dev \
19+ libxi-dev \
20+ libxinerama-dev \
21+ libxrandr-dev \
22+ ninja-build \
23+ pkg-config \
24+ python3 \
25+ xz-utils \
26+ zlib1g-dev && \
1227 rm -rf /var/lib/apt/lists/*
1328
14- # Needed to build `path_tracer`, `optix/ex03_window` example
15- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
16- cmake \
17- libfontconfig-dev \
18- libx11-xcb-dev \
19- libxcursor-dev \
20- libxi-dev \
21- libxinerama-dev \
22- libxrandr-dev && \
23- rm -rf /var/lib/apt/lists/*
24-
25- # Get LLVM 7
26- WORKDIR /data/llvm7
27-
28- # Install dependencies for building LLVM
29- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
30- libffi-dev \
31- libedit-dev \
32- libncurses5-dev \
33- libxml2-dev \
34- python3 \
35- ninja-build && \
36- rm -rf /var/lib/apt/lists/*
37-
38- # Download and build LLVM 7.1.0 for all architectures
29+ WORKDIR /opt/build
3930RUN curl -sSf -L -O https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/llvm-7.1.0.src.tar.xz && \
4031 tar -xf llvm-7.1.0.src.tar.xz && \
4132 cd llvm-7.1.0.src && \
@@ -58,25 +49,56 @@ RUN curl -sSf -L -O https://github.com/llvm/llvm-project/releases/download/llvmo
5849 -DLLVM_INCLUDE_BENCHMARKS=OFF \
5950 -DLLVM_ENABLE_ZLIB=ON \
6051 -DLLVM_ENABLE_TERMINFO=ON \
61- -DCMAKE_INSTALL_PREFIX=/usr \
52+ -DCMAKE_INSTALL_PREFIX=/opt/llvm-7 \
6253 .. && \
63- ninja -j$(nproc) && \
54+ ninja -j" $(nproc)" && \
6455 ninja install && \
65- cd ../.. && \
66- rm -rf llvm-7.1.0.src* && \
67- ln -s /usr/bin/llvm-config /usr/bin/llvm-config-7
56+ cd /opt && rm -rf /opt/build
6857
69- # Get Rust
70- RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
58+ RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y --profile minimal && \
59+ /root/.cargo/bin/rustup component add rustfmt clippy && \
60+ rm -rf /root/.cargo/registry /root/.cargo/git /root/.rustup/tmp
7161ENV PATH="/root/.cargo/bin:${PATH}"
7262
73- # Setup the workspace
74- WORKDIR /data/rust-cuda
75- RUN --mount=type=bind,source=rust-toolchain.toml,target=/data/rust-cuda/rust-toolchain.toml \
76- rustup show
63+ FROM nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 AS runtime
7764
78- # Add nvvm to LD_LIBRARY_PATH.
65+ RUN apt-get update && \
66+ DEBIAN_FRONTEND=noninteractive apt-get -y install \
67+ build-essential \
68+ clang \
69+ cmake \
70+ curl \
71+ libffi-dev \
72+ libfontconfig-dev \
73+ libssl-dev \
74+ libtinfo-dev \
75+ libedit-dev \
76+ libncurses5-dev \
77+ libxml2-dev \
78+ libx11-xcb-dev \
79+ libxcursor-dev \
80+ libxi-dev \
81+ libxinerama-dev \
82+ libxrandr-dev \
83+ pkg-config \
84+ python3 \
85+ xz-utils \
86+ zlib1g-dev && \
87+ rm -rf /var/lib/apt/lists/*
88+
89+ COPY --from=builder /opt/llvm-7 /opt/llvm-7
90+ RUN ln -sf /opt/llvm-7/bin/llvm-config /usr/bin/llvm-config && \
91+ ln -sf /opt/llvm-7/bin/llvm-config /usr/bin/llvm-config-7
92+
93+ COPY --from=builder /root/.cargo /root/.cargo
94+ COPY --from=builder /root/.rustup /root/.rustup
95+ ENV PATH="/root/.cargo/bin:${PATH}"
96+ RUN /root/.cargo/bin/rustup show && \
97+ rm -rf /root/.cargo/registry /root/.cargo/git /root/.rustup/tmp
98+
99+ WORKDIR /data/rust-cuda
79100ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
80101ENV LLVM_LINK_STATIC=1
81102ENV RUST_LOG=info
82103
104+ CMD ["bash" ]
0 commit comments