xref: /rust-libc-0.2.174/ci/run-docker.sh (revision 8d68ec6f)
1#!/bin/sh
2
3# Disable SC2086 as it confuses the docker command.
4# shellcheck disable=SC2086
5
6# Small script to run tests for a target (or all targets) inside all the
7# respective docker images.
8
9set -ex
10
11# Default to assuming the CARGO_HOME is one directory up (to account for a `bin`
12# subdir) from where the `cargo` binary in `$PATH` lives.
13default_cargo_home="$(dirname "$(dirname "$(command -v cargo)")")"
14# If the CARGO_HOME env var is already set, use that. If it isn't set use the
15# default.
16export CARGO_HOME="${CARGO_HOME:-$default_cargo_home}"
17
18echo "${HOME}"
19pwd
20
21# Avoid "no space left on device" failure.
22if [ "${1}" = "aarch64-linux-android" ] ; then
23    docker system prune -af
24    docker system df
25fi
26
27run() {
28    echo "Building docker container for target ${1}"
29
30    # use -f so we can use ci/ as build context
31    docker build -t "libc-${1}" -f "ci/docker/${1}/Dockerfile" ci/
32    mkdir -p target
33    if [ -w /dev/kvm ]; then
34        kvm="--volume /dev/kvm:/dev/kvm"
35    else
36        kvm=""
37    fi
38
39    docker run \
40        --rm \
41        --user "$(id -u)":"$(id -g)" \
42        --env LIBC_CI \
43        --env LIBC_CI_ZBUILD_STD \
44        --env CARGO_HOME=/cargo \
45        --env CARGO_TARGET_DIR=/checkout/target \
46        --volume "$CARGO_HOME":/cargo \
47        --volume "$(rustc --print sysroot)":/rust:ro \
48        --volume "$(pwd)":/checkout:ro \
49        --volume "$(pwd)"/target:/checkout/target \
50        $kvm \
51        --init \
52        --workdir /checkout \
53        "libc-${1}" \
54        sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh ${1}"
55}
56
57build_switch() {
58    echo "Building docker container for target switch"
59
60    # use -f so we can use ci/ as build context
61    docker build -t libc-switch -f "ci/docker/switch/Dockerfile" ci/
62    mkdir -p target
63    if [ -w /dev/kvm ]; then
64        kvm="--volume /dev/kvm:/dev/kvm"
65    else
66        kvm=""
67    fi
68
69    cp "$(command -v rustup)" "$(rustc --print sysroot)/bin"
70
71    docker run \
72        --rm \
73        --user "$(id -u)":"$(id -g)" \
74        --env LIBC_CI \
75        --env CARGO_HOME=/cargo \
76        --env CARGO_TARGET_DIR=/checkout/target \
77        --volume "$CARGO_HOME":/cargo \
78        --volume "$(rustc --print sysroot)":/rust:ro \
79        --volume "$(pwd)":/checkout:ro \
80        --volume "$(pwd)"/target:/checkout/target \
81        --volume ~/.rustup:/.rustup:Z \
82        $kvm \
83        --init \
84        --workdir /checkout \
85        libc-switch \
86        sh -c "HOME=/tmp RUSTUP_HOME=/tmp PATH=\$PATH:/rust/bin rustup default nightly \
87            && rustup component add rust-src --target ci/switch.json \
88            && cargo build -Z build-std=core,alloc --target ci/switch.json"
89}
90
91if [ -z "${1}" ]; then
92  for d in ci/docker/*; do
93    run "${d}"
94  done
95else
96  if [ "${1}" != "switch" ]; then
97    run "${1}"
98  else
99    build_switch
100  fi
101fi
102