xref: /rust-libc-0.2.174/ci/run-docker.sh (revision 0dec549f)
1#!/usr/bin/env sh
2
3# Small script to run tests for a target (or all targets) inside all the
4# respective docker images.
5
6set -ex
7
8# Default to assuming the CARGO_HOME is one directory up (to account for a `bin`
9# subdir) from where the `cargo` binary in `$PATH` lives.
10DEFAULT_CARGO_HOME="$(dirname "$(dirname "$(command -v cargo)")")"
11# If the CARGO_HOME env var is already set, use that. If it isn't set use the
12# default.
13CARGO_HOME="${CARGO_HOME:-$DEFAULT_CARGO_HOME}"
14
15echo "${HOME}"
16pwd
17
18# Avoid "no space left on device" failure.
19if [ "${1}" = "aarch64-linux-android" ] ; then
20  docker system prune -af
21  docker system df
22fi
23
24run() {
25    echo "Building docker container for target ${1}"
26
27    # use -f so we can use ci/ as build context
28    docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/
29    mkdir -p target
30    if [ -w /dev/kvm ]; then
31        kvm="--volume /dev/kvm:/dev/kvm"
32    else
33        kvm=""
34    fi
35
36    docker run \
37      --rm \
38      --user "$(id -u)":"$(id -g)" \
39      --env LIBC_CI \
40      --env CARGO_HOME=/cargo \
41      --env CARGO_TARGET_DIR=/checkout/target \
42      --volume "$CARGO_HOME":/cargo \
43      --volume "$(rustc --print sysroot)":/rust:ro \
44      --volume "$(pwd)":/checkout:ro \
45      --volume "$(pwd)"/target:/checkout/target \
46      $kvm \
47      --init \
48      --workdir /checkout \
49      libc \
50      sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh ${1}"
51}
52
53if [ -z "${1}" ]; then
54  for d in ci/docker/*; do
55    run "${d}"
56  done
57else
58  run "${1}"
59fi
60