Skip to content

Commit 3cac558

Browse files
committed
Introduce the concept of using another toolchain in an image
1 parent 86e3f62 commit 3cac558

35 files changed

+2205
-579
lines changed

.changes/817.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"description": "Images can now specify a certain toolchain via `target.{target}.image.toolchain`",
4+
"type": "changed"
5+
},
6+
{
7+
"description": "made `cross +channel` parsing more compliant to parsing a toolchain",
8+
"type": "fixed"
9+
}
10+
]

.github/workflows/ci.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ jobs:
341341
- uses: ./.github/actions/setup-rust
342342

343343
- name: LLVM instrument coverage
344-
id: remote-cov
345344
uses: ./.github/actions/cargo-llvm-cov
346345
with:
347346
name: integration-remote
@@ -361,7 +360,6 @@ jobs:
361360
- uses: ./.github/actions/setup-rust
362361

363362
- name: LLVM instrument coverage
364-
id: bisect-cov
365363
uses: ./.github/actions/cargo-llvm-cov
366364
with:
367365
name: integration-bisect
@@ -372,6 +370,23 @@ jobs:
372370
run: ./ci/test-bisect.sh
373371
shell: bash
374372

373+
foreign:
374+
needs: [shellcheck, test, check]
375+
runs-on: ubuntu-latest
376+
if: github.actor == 'bors[bot]'
377+
steps:
378+
- uses: actions/checkout@v3
379+
- uses: ./.github/actions/setup-rust
380+
381+
- name: LLVM instrument coverage
382+
uses: ./.github/actions/cargo-llvm-cov
383+
with:
384+
name: integration-bisect
385+
386+
- name: Run Foreign toolchain test
387+
run: ./ci/test-foreign-toolchain.sh
388+
shell: bash
389+
375390
docker-in-docker:
376391
needs: [shellcheck, test, check]
377392
runs-on: ubuntu-latest
@@ -381,7 +396,6 @@ jobs:
381396
- uses: ./.github/actions/setup-rust
382397

383398
- name: LLVM instrument coverage
384-
id: docker-in-docker-cov
385399
uses: ./.github/actions/cargo-llvm-cov
386400
with:
387401
name: integration-docker-in-docker
@@ -405,7 +419,7 @@ jobs:
405419
github-token: ${{ secrets.GITHUB_TOKEN }}
406420

407421
conclusion:
408-
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker]
422+
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign]
409423
if: always()
410424
runs-on: ubuntu-latest
411425
steps:

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ version = "0.2.4"
1010
edition = "2021"
1111
include = [
1212
"src/**/*",
13-
"docker/Dockerfile.*",
14-
"docker/*.sh",
1513
"docs/*.md",
1614
"Cargo.toml",
1715
"Cargo.lock",

ci/shared.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env bash
22

3+
ci_dir=$(dirname "${BASH_SOURCE[0]}")
4+
ci_dir=$(realpath "${ci_dir}")
5+
PROJECT_HOME=$(dirname "${ci_dir}")
6+
export PROJECT_HOME
7+
CARGO_TMP_DIR="${PROJECT_HOME}/target/tmp"
8+
export CARGO_TMP_DIR
9+
10+
if [[ -n "${CROSS_CONTAINER_ENGINE}" ]]; then
11+
CROSS_ENGINE="${CROSS_CONTAINER_ENGINE}"
12+
elif command -v docker >/dev/null 2>&1; then
13+
CROSS_ENGINE=docker
14+
else
15+
CROSS_ENGINE=podman
16+
fi
17+
export CROSS_ENGINE
18+
319
function retry {
420
local tries="${TRIES-5}"
521
local timeout="${TIMEOUT-1}"
@@ -21,3 +37,14 @@ function retry {
2137

2238
return ${exit_code}
2339
}
40+
41+
function mkcargotemp {
42+
local td=
43+
td="$CARGO_TMP_DIR"/$(mktemp -u "${@}" | xargs basename)
44+
mkdir -p "$td"
45+
echo '# Cargo.toml
46+
[workspace]
47+
members = ["'"$(basename "$td")"'"]
48+
' > "$CARGO_TMP_DIR"/Cargo.toml
49+
echo "$td"
50+
}

ci/test-bisect.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fi
1313
ci_dir=$(dirname "${BASH_SOURCE[0]}")
1414
ci_dir=$(realpath "${ci_dir}")
1515
. "${ci_dir}"/shared.sh
16-
project_home=$(dirname "${ci_dir}")
16+
1717

1818
main() {
1919
local td=
@@ -22,7 +22,7 @@ main() {
2222
retry cargo fetch
2323
cargo build
2424
cargo install cargo-bisect-rustc --debug
25-
export CROSS="${project_home}/target/debug/cross"
25+
export CROSS="${PROJECT_HOME}/target/debug/cross"
2626

2727
td="$(mktemp -d)"
2828
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"

ci/test-cross-image.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2086
2+
# shellcheck disable=SC2086,SC1091,SC1090
33

44
set -x
55
set -eo pipefail
@@ -20,6 +20,9 @@ if [[ -z "${CROSS_TARGET_CROSS_IMAGE}" ]]; then
2020
CROSS_TARGET_CROSS_IMAGE="ghcr.io/cross-rs/cross:main"
2121
fi
2222

23+
ci_dir=$(dirname "${BASH_SOURCE[0]}")
24+
ci_dir=$(realpath "${ci_dir}")
25+
. "${ci_dir}"/shared.sh
2326

2427
main() {
2528

ci/test-docker-in-docker.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC1004
2+
# shellcheck disable=SC1004,SC1091,SC1090
33

44
# test to see that running docker-in-docker works
55

@@ -18,17 +18,17 @@ if [[ "${IMAGE}" ]]; then
1818
export "CROSS_TARGET_${TARGET_UPPER//-/_}_IMAGE"="${IMAGE}"
1919
fi
2020

21-
source=$(dirname "${BASH_SOURCE[0]}")
22-
source=$(realpath "${source}")
23-
home=$(dirname "${source}")
21+
ci_dir=$(dirname "${BASH_SOURCE[0]}")
22+
ci_dir=$(realpath "${ci_dir}")
23+
. "${ci_dir}"/shared.sh
2424

2525
main() {
26-
docker run -v "${home}":"${home}" -w "${home}" \
26+
docker run -v "${PROJECT_HOME}":"${PROJECT_HOME}" -w "${PROJECT_HOME}" \
2727
--rm -e TARGET -e RUSTFLAGS -e RUST_TEST_THREADS \
2828
-e LLVM_PROFILE_FILE -e CARGO_INCREMENTAL \
2929
-e "CROSS_TARGET_${TARGET_UPPER//-/_}_IMAGE" \
3030
-v /var/run/docker.sock:/var/run/docker.sock \
31-
docker:18.09-dind sh -c '
31+
docker:20.10-dind sh -c '
3232
#!/usr/bin/env sh
3333
set -x
3434
set -euo pipefail

ci/test-foreign-toolchain.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091,SC1090
3+
4+
# test to see that foreign toolchains work
5+
6+
set -x
7+
set -eo pipefail
8+
9+
ci_dir=$(dirname "${BASH_SOURCE[0]}")
10+
ci_dir=$(realpath "${ci_dir}")
11+
. "${ci_dir}"/shared.sh
12+
13+
main() {
14+
local td=
15+
16+
retry cargo fetch
17+
cargo build
18+
export CROSS="${PROJECT_HOME}/target/debug/cross"
19+
20+
td="$(mkcargotemp -d)"
21+
22+
pushd "${td}"
23+
cargo init --bin --name foreign_toolchain
24+
# shellcheck disable=SC2016
25+
echo '# Cross.toml
26+
[build]
27+
default-target = "x86_64-unknown-linux-musl"
28+
29+
[target."x86_64-unknown-linux-musl"]
30+
image.name = "alpine:edge"
31+
image.toolchain = ["x86_64-unknown-linux-musl"]
32+
pre-build = ["apk add --no-cache gcc musl-dev"]' >"${CARGO_TMP_DIR}"/Cross.toml
33+
34+
"$CROSS" run -v
35+
36+
local tmp_basename
37+
tmp_basename=$(basename "${CARGO_TMP_DIR}")
38+
"${CROSS_ENGINE}" images --format '{{.Repository}}:{{.Tag}}' --filter 'label=org.cross-rs.for-cross-target' | grep "cross-custom-${tmp_basename}" | xargs -t "${CROSS_ENGINE}" rmi
39+
40+
echo '# Cross.toml
41+
[build]
42+
default-target = "x86_64-unknown-linux-gnu"
43+
44+
[target.x86_64-unknown-linux-gnu]
45+
pre-build = [
46+
"apt-get update && apt-get install -y libc6 g++-x86-64-linux-gnu libc6-dev-amd64-cross",
47+
]
48+
49+
[target.x86_64-unknown-linux-gnu.env]
50+
passthrough = [
51+
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc",
52+
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER=/qemu-runner x86_64",
53+
"CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc",
54+
"CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++",
55+
]
56+
57+
[target.x86_64-unknown-linux-gnu.image]
58+
name = "ubuntu:20.04"
59+
toolchain = ["aarch64-unknown-linux-gnu"]
60+
' >"${CARGO_TMP_DIR}"/Cross.toml
61+
62+
"$CROSS" build -v
63+
64+
"${CROSS_ENGINE}" images --format '{{.Repository}}:{{.Tag}}' --filter 'label=org.cross-rs.for-cross-target' | grep "cross-custom-${tmp_basename}" | xargs "${CROSS_ENGINE}" rmi
65+
66+
popd
67+
68+
rm -rf "${td}"
69+
}
70+
71+
main

ci/test-remote.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ fi
1414
ci_dir=$(dirname "${BASH_SOURCE[0]}")
1515
ci_dir=$(realpath "${ci_dir}")
1616
. "${ci_dir}"/shared.sh
17-
project_home=$(dirname "${ci_dir}")
1817

1918
main() {
2019
local err=
2120

2221
retry cargo fetch
2322
cargo build
24-
export CROSS="${project_home}/target/debug/cross"
25-
export CROSS_UTIL="${project_home}/target/debug/cross-util"
23+
export CROSS="${PROJECT_HOME}/target/debug/cross"
24+
export CROSS_UTIL="${PROJECT_HOME}/target/debug/cross-util"
2625

2726
# if the create volume fails, ensure it exists.
2827
if ! err=$("${CROSS_UTIL}" volumes create 2>&1 >/dev/null); then
@@ -40,7 +39,7 @@ main() {
4039

4140
cross_test_cpp() {
4241
local td=
43-
td="$(mktemp -d)"
42+
td="$(mkcargotemp -d)"
4443

4544
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
4645

0 commit comments

Comments
 (0)