Skip to content

Commit

Permalink
Add sccache to docker images (apache#9844)
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati authored and crazydemo committed Jan 27, 2022
1 parent 2adddee commit 95d7d78
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 11 deletions.
11 changes: 11 additions & 0 deletions docker/Dockerfile.ci_arm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ RUN apt-get install -y ca-certificates gnupg2
COPY install/ubuntu_install_core.sh /install/ubuntu_install_core.sh
RUN bash /install/ubuntu_install_core.sh

# Rust env
COPY install/ubuntu_install_rust.sh /install/ubuntu_install_rust.sh
RUN bash /install/ubuntu_install_rust.sh
ENV RUSTUP_HOME /opt/rust
ENV CARGO_HOME /opt/rust
ENV PATH $PATH:$CARGO_HOME/bin

# sccache
COPY install/ubuntu_install_sccache.sh /install/ubuntu_install_sccache.sh
RUN bash /install/ubuntu_install_sccache.sh

COPY install/ubuntu_install_llvm.sh /install/ubuntu_install_llvm.sh
RUN bash /install/ubuntu_install_llvm.sh

Expand Down
8 changes: 8 additions & 0 deletions docker/Dockerfile.ci_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ ENV RUSTUP_HOME /opt/rust
ENV CARGO_HOME /opt/rust
ENV PATH $PATH:$CARGO_HOME/bin

# wasmtime
COPY install/ubuntu_install_wasmtime.sh /install/ubuntu_install_wasmtime.sh
RUN bash /install/ubuntu_install_wasmtime.sh

# AutoTVM deps
COPY install/ubuntu_install_redis.sh /install/ubuntu_install_redis.sh
RUN bash /install/ubuntu_install_redis.sh
Expand Down Expand Up @@ -126,3 +130,7 @@ ENV PATH /opt/arm/gcc-arm-none-eabi/bin:/opt/arm/FVP_Corstone_SSE-300/models/Lin
# PaddlePaddle deps
COPY install/ubuntu_install_paddle.sh /install/ubuntu_install_paddle.sh
RUN bash /install/ubuntu_install_paddle.sh

# sccache
COPY install/ubuntu_install_sccache.sh /install/ubuntu_install_sccache.sh
RUN bash /install/ubuntu_install_sccache.sh
8 changes: 8 additions & 0 deletions docker/Dockerfile.ci_gpu
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ ENV RUSTUP_HOME /opt/rust
ENV CARGO_HOME /opt/rust
ENV PATH $PATH:$CARGO_HOME/bin

# wasmtime
COPY install/ubuntu_install_wasmtime.sh /install/ubuntu_install_wasmtime.sh
RUN bash /install/ubuntu_install_wasmtime.sh

# AutoTVM deps
COPY install/ubuntu_install_redis.sh /install/ubuntu_install_redis.sh
RUN bash /install/ubuntu_install_redis.sh
Expand All @@ -117,6 +121,10 @@ RUN bash /install/ubuntu_install_universal.sh
COPY install/ubuntu_install_papi.sh /install/ubuntu_install_papi.sh
RUN bash /install/ubuntu_install_papi.sh "cuda rocm"

# sccache
COPY install/ubuntu_install_sccache.sh /install/ubuntu_install_sccache.sh
RUN bash /install/ubuntu_install_sccache.sh

# Environment variables
ENV PATH=/usr/local/nvidia/bin:${PATH}
ENV PATH=/usr/local/cuda/bin:${PATH}
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.ci_lint
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ ENV RUSTUP_HOME /opt/rust
ENV CARGO_HOME /opt/rust
ENV PATH $PATH:$CARGO_HOME/bin

# wasmtime
COPY install/ubuntu_install_wasmtime.sh /install/ubuntu_install_wasmtime.sh
RUN bash /install/ubuntu_install_wasmtime.sh

# java deps for rat
COPY install/ubuntu_install_java.sh /install/ubuntu_install_java.sh
RUN bash /install/ubuntu_install_java.sh
Expand Down
8 changes: 8 additions & 0 deletions docker/Dockerfile.ci_qemu
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ RUN bash /install/ubuntu_install_rust.sh
ENV RUSTUP_HOME /opt/rust
ENV CARGO_HOME /opt/rust

# wasmtime
COPY install/ubuntu_install_wasmtime.sh /install/ubuntu_install_wasmtime.sh
RUN bash /install/ubuntu_install_wasmtime.sh

# AutoTVM deps
COPY install/ubuntu_install_redis.sh /install/ubuntu_install_redis.sh
RUN bash /install/ubuntu_install_redis.sh
Expand All @@ -59,6 +63,10 @@ RUN bash /install/ubuntu_install_tensorflow.sh
COPY install/ubuntu_install_tflite.sh /install/ubuntu_install_tflite.sh
RUN bash /install/ubuntu_install_tflite.sh

# sccache
COPY install/ubuntu_install_sccache.sh /install/ubuntu_install_sccache.sh
RUN bash /install/ubuntu_install_sccache.sh

# Zephyr SDK deps
COPY install/ubuntu_install_zephyr.sh /install/ubuntu_install_zephyr.sh
COPY install/ubuntu_init_zephyr_project.sh /install/ubuntu_init_zephyr_project.sh
Expand Down
12 changes: 1 addition & 11 deletions docker/install/ubuntu_install_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
# specific language governing permissions and limitations
# under the License.

set -e
set -u
set -o pipefail

set -euxo pipefail

export RUSTUP_HOME=/opt/rust
export CARGO_HOME=/opt/rust
Expand All @@ -29,12 +26,5 @@ export PATH=$CARGO_HOME/bin:$PATH
rustup component add rustfmt
rustup component add clippy

# install wasmtime
apt-get install -y --no-install-recommends libc6-dev-i386
export WASMTIME_HOME=/opt/wasmtime
curl https://wasmtime.dev/install.sh -sSf | bash
export PATH="${WASMTIME_HOME}/bin:${PATH}"
rustup target add wasm32-wasi

# make rust usable by all users
chmod -R a+w /opt/rust
28 changes: 28 additions & 0 deletions docker/install/ubuntu_install_sccache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set -e
set -u
set -o pipefail

cargo install sccache

# The docs specifically recommend hard links: https://github.com/mozilla/sccache#known-caveats
mkdir /opt/sccache
ln "$(which sccache)" /opt/sccache/cc
ln "$(which sccache)" /opt/sccache/c++
26 changes: 26 additions & 0 deletions docker/install/ubuntu_install_wasmtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set -euxo pipefail

# install wasmtime (note: requires ubuntu_install_rust.sh to run first)
apt-get install -y --no-install-recommends libc6-dev-i386
export WASMTIME_HOME=/opt/wasmtime
curl https://wasmtime.dev/install.sh -sSf | bash
export PATH="${WASMTIME_HOME}/bin:${PATH}"
rustup target add wasm32-wasi
9 changes: 9 additions & 0 deletions tests/scripts/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def docker(name: str, image: str, scripts: List[str], env: Dict[str, str]):
"""
check_docker()

if os.getenv("USE_SCCACHE", "0") == "1":
scripts = [
"sccache --start-server",
] + scripts
# Set the C/C++ compiler so CMake picks them up in the build
env["CC"] = "/opt/sccache/cc"
env["CXX"] = "/opt/sccache/c++"
env["SCCACHE_CACHE_SIZE"] = os.getenv("SCCACHE_CACHE_SIZE", "50G")

docker_bash = REPO_ROOT / "docker" / "bash.sh"
command = [docker_bash, "--name", name]
for key, value in env.items():
Expand Down

0 comments on commit 95d7d78

Please sign in to comment.