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