Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable usage of other toolchains in images #817

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changes/817.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"description": "Images can now specify a certain toolchain via `target.{target}.image.toolchain`",
"breaking": true,
"type": "added"
},
{
"description": "made `cross +channel` parsing more compliant to parsing a toolchain",
"type": "fixed"
},
{
"description": "`pre-build` and `dockerfile` now uses buildx/buildkit",
"breaking": true,
"type": "changed"
}
]
36 changes: 29 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,14 @@ jobs:

# we should always have an artifact from a previous build.
remote:
needs: [shellcheck, test, check]
needs: [test, check]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust

- name: LLVM instrument coverage
id: remote-cov
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-remote
Expand All @@ -353,15 +352,14 @@ jobs:
shell: bash

bisect:
needs: [shellcheck, test, check]
needs: [test, check]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust

- name: LLVM instrument coverage
id: bisect-cov
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-bisect
Expand All @@ -372,16 +370,40 @@ jobs:
run: ./ci/test-bisect.sh
shell: bash

foreign:
needs: [test, check]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust

- name: LLVM instrument coverage
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-bisect
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Set up docker buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved
- name: Run Foreign toolchain test
run: ./ci/test-foreign-toolchain.sh
shell: bash

docker-in-docker:
needs: [shellcheck, test, check]
needs: [test, check]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust

- name: LLVM instrument coverage
id: docker-in-docker-cov
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-docker-in-docker
Expand All @@ -405,7 +427,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

conclusion:
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker]
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign]
if: always()
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ version = "0.2.4"
edition = "2021"
include = [
"src/**/*",
"docker/Dockerfile.*",
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved
"docker/*.sh",
"docs/*.md",
"Cargo.toml",
"Cargo.lock",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ One of these container engines is required. If both are installed, `cross` will
default to `docker`.

- [Docker]. Note that on Linux non-sudo users need to be in the `docker` group.
Read the official [post-installation steps][post]. Requires version 1.24 or later.
Read the official [post-installation steps][post]. Requires version 20.10 (API 1.40) or later.

[post]: https://docs.docker.com/install/linux/linux-postinstall/

- [Podman]. Requires version 1.6.3 or later.
- [Podman]. Requires version 3.4.0 or later.
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved

## Installation

Expand Down
27 changes: 27 additions & 0 deletions ci/shared.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env bash

ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
PROJECT_HOME=$(dirname "${ci_dir}")
export PROJECT_HOME
CARGO_TMP_DIR="${PROJECT_HOME}/target/tmp"
export CARGO_TMP_DIR

if [[ -n "${CROSS_CONTAINER_ENGINE}" ]]; then
CROSS_ENGINE="${CROSS_CONTAINER_ENGINE}"
elif command -v docker >/dev/null 2>&1; then
CROSS_ENGINE=docker
else
CROSS_ENGINE=podman
fi
export CROSS_ENGINE

function retry {
local tries="${TRIES-5}"
local timeout="${TIMEOUT-1}"
Expand All @@ -21,3 +37,14 @@ function retry {

return ${exit_code}
}

function mkcargotemp {
local td=
td="$CARGO_TMP_DIR"/$(mktemp -u "${@}" | xargs basename)
mkdir -p "$td"
echo '# Cargo.toml
[workspace]
members = ["'"$(basename "$td")"'"]
' > "$CARGO_TMP_DIR"/Cargo.toml
echo "$td"
}
4 changes: 2 additions & 2 deletions ci/test-bisect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
. "${ci_dir}"/shared.sh
project_home=$(dirname "${ci_dir}")


main() {
local td=
Expand All @@ -22,7 +22,7 @@ main() {
retry cargo fetch
cargo build
cargo install cargo-bisect-rustc --debug
export CROSS="${project_home}/target/debug/cross"
export CROSS="${PROJECT_HOME}/target/debug/cross"

td="$(mktemp -d)"
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
Expand Down
5 changes: 4 additions & 1 deletion ci/test-cross-image.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2086
# shellcheck disable=SC2086,SC1091,SC1090

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

ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
. "${ci_dir}"/shared.sh

main() {

Expand Down
12 changes: 6 additions & 6 deletions ci/test-docker-in-docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC1004
# shellcheck disable=SC1004,SC1091,SC1090

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

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

source=$(dirname "${BASH_SOURCE[0]}")
source=$(realpath "${source}")
home=$(dirname "${source}")
ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
. "${ci_dir}"/shared.sh

main() {
docker run -v "${home}":"${home}" -w "${home}" \
docker run -v "${PROJECT_HOME}":"${PROJECT_HOME}" -w "${PROJECT_HOME}" \
--rm -e TARGET -e RUSTFLAGS -e RUST_TEST_THREADS \
-e LLVM_PROFILE_FILE -e CARGO_INCREMENTAL \
-e "CROSS_TARGET_${TARGET_UPPER//-/_}_IMAGE" \
-v /var/run/docker.sock:/var/run/docker.sock \
docker:18.09-dind sh -c '
docker:20.10-dind sh -c '
#!/usr/bin/env sh
set -x
set -euo pipefail
Expand Down
71 changes: 71 additions & 0 deletions ci/test-foreign-toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091,SC1090

# test to see that foreign toolchains work

set -x
set -eo pipefail

ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
. "${ci_dir}"/shared.sh

main() {
local td=

retry cargo fetch
cargo build
export CROSS="${PROJECT_HOME}/target/debug/cross"

td="$(mkcargotemp -d)"

pushd "${td}"
cargo init --bin --name foreign_toolchain
# shellcheck disable=SC2016
echo '# Cross.toml
[build]
default-target = "x86_64-unknown-linux-musl"

[target."x86_64-unknown-linux-musl"]
image.name = "alpine:edge"
image.toolchain = ["x86_64-unknown-linux-musl"]
pre-build = ["apk add --no-cache gcc musl-dev"]' >"${CARGO_TMP_DIR}"/Cross.toml

"$CROSS" run -v

local tmp_basename
tmp_basename=$(basename "${CARGO_TMP_DIR}")
"${CROSS_ENGINE}" images --format '{{.Repository}}:{{.Tag}}' --filter 'label=org.cross-rs.for-cross-target' | grep "cross-custom-${tmp_basename}" | xargs -t "${CROSS_ENGINE}" rmi

echo '# Cross.toml
[build]
default-target = "x86_64-unknown-linux-gnu"

[target.x86_64-unknown-linux-gnu]
pre-build = [
"apt-get update && apt-get install -y libc6 g++-x86-64-linux-gnu libc6-dev-amd64-cross",
]

[target.x86_64-unknown-linux-gnu.env]
passthrough = [
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc",
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER=/qemu-runner x86_64",
"CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc",
"CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++",
]

[target.x86_64-unknown-linux-gnu.image]
name = "ubuntu:20.04"
toolchain = ["aarch64-unknown-linux-gnu"]
' >"${CARGO_TMP_DIR}"/Cross.toml

"$CROSS" build -v

"${CROSS_ENGINE}" images --format '{{.Repository}}:{{.Tag}}' --filter 'label=org.cross-rs.for-cross-target' | grep "cross-custom-${tmp_basename}" | xargs "${CROSS_ENGINE}" rmi

popd

rm -rf "${td}"
}

main
7 changes: 3 additions & 4 deletions ci/test-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ fi
ci_dir=$(dirname "${BASH_SOURCE[0]}")
ci_dir=$(realpath "${ci_dir}")
. "${ci_dir}"/shared.sh
project_home=$(dirname "${ci_dir}")

main() {
local err=

retry cargo fetch
cargo build
export CROSS="${project_home}/target/debug/cross"
export CROSS_UTIL="${project_home}/target/debug/cross-util"
export CROSS="${PROJECT_HOME}/target/debug/cross"
export CROSS_UTIL="${PROJECT_HOME}/target/debug/cross-util"

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

cross_test_cpp() {
local td=
td="$(mktemp -d)"
td="$(mkcargotemp -d)"

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

Expand Down
Loading