xref: /rust-libc-0.2.174/ci/run-docker.sh (revision faa0184a)
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
53build_switch() {
54    echo "Building docker container for target switch"
55
56    # use -f so we can use ci/ as build context
57    docker build -t libc -f "ci/docker/switch/Dockerfile" ci/
58    mkdir -p target
59    if [ -w /dev/kvm ]; then
60        kvm="--volume /dev/kvm:/dev/kvm"
61    else
62        kvm=""
63    fi
64
65    cp "$(command -v rustup)" "$(rustc --print sysroot)/bin"
66
67    docker run \
68      --rm \
69      --user "$(id -u)":"$(id -g)" \
70      --env LIBC_CI \
71      --env CARGO_HOME=/cargo \
72      --env CARGO_TARGET_DIR=/checkout/target \
73      --volume "$CARGO_HOME":/cargo \
74      --volume "$(rustc --print sysroot)":/rust:ro \
75      --volume "$(pwd)":/checkout:ro \
76      --volume "$(pwd)"/target:/checkout/target \
77      --volume ~/.rustup:/.rustup:Z \
78      $kvm \
79      --init \
80      --workdir /checkout \
81      libc \
82      sh -c "HOME=/tmp RUSTUP_HOME=/tmp PATH=\$PATH:/rust/bin rustup default nightly \
83        && rustup component add rust-src --target ci/switch.json \
84        && cargo build -Z build-std=core,alloc --target ci/switch.json"
85}
86
87if [ -z "${1}" ]; then
88  for d in ci/docker/*; do
89    run "${d}"
90  done
91else
92  if [ "${1}" != "switch" ]; then
93    run "${1}"
94  else
95    build_switch
96  fi
97fi
98