Skip to content

Commit 3bfa125

Browse files
committed
ci: replace mips with powerpc64, aarch64 and s390x
We drop our MIPS target because it no longer works.[1] We were previously using it as a means of testing ripgrep in a big endian environment. So to achieve that without MIPS, we test on powerpc64 and s390x. (No particular reason to do both, but why not.) We also add aarch64 as a proxy for at least ensuring everything works for the same architecture as Apple silicon. It's not a guarantee that everything works, but it seems better than nothing until we can actually test Apple silicon in CI. [1]: rust-lang/regex@c788378
1 parent 51765f2 commit 3bfa125

File tree

11 files changed

+114
-59
lines changed

11 files changed

+114
-59
lines changed

.github/workflows/ci.yml

+52-37
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ on:
66
- master
77
schedule:
88
- cron: '00 01 * * *'
9+
10+
# The section is needed to drop write-all permissions that are granted on
11+
# `schedule` event. By specifying any permission explicitly all others are set
12+
# to none. By using the principle of least privilege the damage a compromised
13+
# workflow can do (because of an injection or compromised third party tool or
14+
# action) is restricted. Currently the worklow doesn't need any additional
15+
# permission except for pulling the code. Adding labels to issues, commenting
16+
# on pull-requests, etc. may need additional permissions:
17+
#
18+
# Syntax for this section:
19+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
20+
#
21+
# Reference for how to assign permissions on a job-by-job basis:
22+
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
23+
#
24+
# Reference for available permissions that we can enable if needed:
25+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
26+
permissions:
27+
# to fetch code (actions/checkout)
28+
contents: read
29+
930
jobs:
1031
test:
1132
name: test
@@ -14,32 +35,21 @@ jobs:
1435
# systems.
1536
CARGO: cargo
1637
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
38+
# Note that we only use cross on Linux, so setting a target on a
39+
# different OS will just use normal cargo.
1740
TARGET_FLAGS:
1841
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
1942
TARGET_DIR: ./target
43+
# Bump this as appropriate. We pin to a version to make sure CI
44+
# continues to work as cross releases in the past have broken things
45+
# in subtle ways.
46+
CROSS_VERSION: v0.2.5
2047
# Emit backtraces on panics.
2148
RUST_BACKTRACE: 1
2249
runs-on: ${{ matrix.os }}
2350
strategy:
51+
fail-fast: false
2452
matrix:
25-
build:
26-
# We test ripgrep on a pinned version of Rust, along with the moving
27-
# targets of 'stable' and 'beta' for good measure.
28-
- pinned
29-
- stable
30-
- beta
31-
# Our release builds are generated by a nightly compiler to take
32-
# advantage of the latest optimizations/compile time improvements. So
33-
# we test all of them here. (We don't do mips releases, but test on
34-
# mips for big-endian coverage.)
35-
- nightly
36-
- nightly-musl
37-
- nightly-32
38-
- nightly-mips
39-
- nightly-arm
40-
- macos
41-
- win-msvc
42-
- win-gnu
4353
include:
4454
- build: pinned
4555
os: ubuntu-latest
@@ -53,27 +63,26 @@ jobs:
5363
- build: nightly
5464
os: ubuntu-latest
5565
rust: nightly
56-
- build: nightly-musl
66+
- build: stable-musl
5767
os: ubuntu-latest
58-
rust: nightly
68+
rust: stable
5969
target: x86_64-unknown-linux-musl
60-
- build: nightly-32
70+
- build: stable-x86
6171
os: ubuntu-latest
62-
rust: nightly
72+
rust: stable
6373
target: i686-unknown-linux-gnu
64-
- build: nightly-mips
74+
- build: stable-aarch64
6575
os: ubuntu-latest
66-
rust: nightly
67-
target: mips64-unknown-linux-gnuabi64
68-
- build: nightly-arm
76+
rust: stable
77+
target: aarch64-unknown-linux-gnu
78+
- build: stable-powerpc64
6979
os: ubuntu-latest
70-
rust: nightly
71-
# For stripping release binaries:
72-
# docker run --rm -v $PWD/target:/target:Z \
73-
# rustembedded/cross:arm-unknown-linux-gnueabihf \
74-
# arm-linux-gnueabihf-strip \
75-
# /target/arm-unknown-linux-gnueabihf/debug/rg
76-
target: arm-unknown-linux-gnueabihf
80+
rust: stable
81+
target: powerpc64-unknown-linux-gnu
82+
- build: stable-s390x
83+
os: ubuntu-latest
84+
rust: stable
85+
target: s390x-unknown-linux-gnu
7786
- build: macos
7887
os: macos-latest
7988
rust: nightly
@@ -103,9 +112,17 @@ jobs:
103112
toolchain: ${{ matrix.rust }}
104113

105114
- name: Use Cross
106-
if: matrix.target != ''
115+
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
107116
run: |
108-
cargo install cross
117+
# In the past, new releases of 'cross' have broken CI. So for now, we
118+
# pin it. We also use their pre-compiled binary releases because cross
119+
# has over 100 dependencies and takes a bit to compile.
120+
dir="$RUNNER_TEMP/cross-download"
121+
mkdir "$dir"
122+
echo "$dir" >> $GITHUB_PATH
123+
cd "$dir"
124+
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
125+
tar xf cross-x86_64-unknown-linux-musl.tar.gz
109126
echo "CARGO=cross" >> $GITHUB_ENV
110127
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
111128
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
@@ -177,7 +194,6 @@ jobs:
177194
run: ci/test-complete
178195

179196
rustfmt:
180-
name: rustfmt
181197
runs-on: ubuntu-latest
182198
steps:
183199
- name: Checkout repository
@@ -191,7 +207,6 @@ jobs:
191207
run: cargo fmt --all --check
192208

193209
docs:
194-
name: Docs
195210
runs-on: ubuntu-latest
196211
steps:
197212
- name: Checkout repository

Cross.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ image = "burntsushi/cross:x86_64-unknown-linux-musl"
44
[target.i686-unknown-linux-gnu]
55
image = "burntsushi/cross:i686-unknown-linux-gnu"
66

7-
[target.mips64-unknown-linux-gnuabi64]
8-
image = "burntsushi/cross:mips64-unknown-linux-gnuabi64"
9-
build-std = true
7+
[target.aarch64-unknown-linux-gnu]
8+
image = "burntsushi/cross:aarch64-unknown-linux-gnu"
109

11-
[target.arm-unknown-linux-gnueabihf]
12-
image = "burntsushi/cross:arm-unknown-linux-gnueabihf"
10+
[target.powerpc64-unknown-linux-gnu]
11+
image = "burntsushi/cross:powerpc64-unknown-linux-gnu"
12+
13+
[target.s390x-unknown-linux-gnu]
14+
image = "burntsushi/cross:s390x-unknown-linux-gnu"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rustembedded/cross:arm-unknown-linux-gnueabihf
1+
FROM rustembedded/cross:aarch64-unknown-linux-gnu
22

33
COPY stage/ubuntu-install-packages /
44
RUN /ubuntu-install-packages

ci/docker/arm-unknown-linux-gnueabihf/build ci/docker/aarch64-unknown-linux-gnu/build

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
mkdir -p stage
44
cp ../../ubuntu-install-packages ./stage/
5-
docker build -t burntsushi/cross:arm-unknown-linux-gnueabihf .
5+
docker build -t burntsushi/cross:aarch64-unknown-linux-gnu .
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rustembedded/cross:mips64-unknown-linux-gnuabi64
1+
FROM rustembedded/cross:powerpc64-unknown-linux-gnu
22

33
COPY stage/ubuntu-install-packages /
44
RUN /ubuntu-install-packages

ci/docker/mips64-unknown-linux-gnuabi64/build ci/docker/powerpc64-unknown-linux-gnu/build

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
mkdir -p stage
44
cp ../../ubuntu-install-packages ./stage/
5-
docker build -t burntsushi/cross:mips64-unknown-linux-gnuabi64 .
5+
docker build -t burntsushi/cross:powerpc64-unknown-linux-gnu .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM rustembedded/cross:s390x-unknown-linux-gnu
2+
3+
COPY stage/ubuntu-install-packages /
4+
RUN /ubuntu-install-packages
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
mkdir -p stage
4+
cp ../../ubuntu-install-packages ./stage/
5+
docker build -t burntsushi/cross:s390x-unknown-linux-gnu .

tests/feature.rs

+3
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ rgtest!(f1466_no_ignore_files, |dir: Dir, mut cmd: TestCommand| {
791791
rgtest!(f2361_sort_nested_files, |dir: Dir, mut cmd: TestCommand| {
792792
use std::{thread::sleep, time::Duration};
793793

794+
if crate::util::is_cross() {
795+
return;
796+
}
794797
dir.create("foo", "1");
795798
sleep(Duration::from_millis(100));
796799
dir.create_dir("dir");

tests/misc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1100,12 +1100,18 @@ rgtest!(sort_files, |dir: Dir, mut cmd: TestCommand| {
11001100
});
11011101

11021102
rgtest!(sort_accessed, |dir: Dir, mut cmd: TestCommand| {
1103+
if crate::util::is_cross() {
1104+
return;
1105+
}
11031106
sort_setup(dir);
11041107
let expected = "a:test\ndir/c:test\nb:test\ndir/d:test\n";
11051108
eqnice!(expected, cmd.args(["--sort", "accessed", "test"]).stdout());
11061109
});
11071110

11081111
rgtest!(sortr_accessed, |dir: Dir, mut cmd: TestCommand| {
1112+
if crate::util::is_cross() {
1113+
return;
1114+
}
11091115
sort_setup(dir);
11101116
let expected = "dir/d:test\nb:test\ndir/c:test\na:test\n";
11111117
eqnice!(expected, cmd.args(["--sortr", "accessed", "test"]).stdout());

tests/util.rs

+33-13
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,39 @@ fn dir_list<P: AsRef<Path>>(dir: P) -> Vec<String> {
464464
/// will have setup qemu to run it. While this is integrated into the Rust
465465
/// testing by default, we need to handle it ourselves for integration tests.
466466
///
467-
/// Thankfully, cross sets an environment variable that points to the proper
468-
/// qemu binary that we want to run. So we just search for that env var and
469-
/// return its value if we could find it.
467+
/// Now thankfully, cross sets `CROSS_RUNNER` to point to the right qemu
468+
/// executable. Or so one thinks. But it seems to always be set to `qemu-user`
469+
/// and I cannot find `qemu-user` anywhere in the Docker image. Awesome.
470+
///
471+
/// Thers is `/linux-runner` which seems to work sometimes? But not always.
472+
///
473+
/// Instead, it looks like we have to use `qemu-aarch64` in the `aarch64`
474+
/// case. Perfect, so just get the current target architecture and append it
475+
/// to `qemu-`. Wrong. Cross (or qemu or whoever) uses `qemu-ppc64` for
476+
/// `powerpc64`, so we can't just use the target architecture as Rust knows
477+
/// it verbatim.
478+
///
479+
/// So... we just manually handle these cases. So fucking fun.
470480
fn cross_runner() -> Option<String> {
471-
for (k, v) in std::env::vars_os() {
472-
let (k, v) = (k.to_string_lossy(), v.to_string_lossy());
473-
if !k.starts_with("CARGO_TARGET_") && !k.ends_with("_RUNNER") {
474-
continue;
475-
}
476-
if !v.starts_with("qemu-") {
477-
continue;
478-
}
479-
return Some(v.into_owned());
481+
let runner = std::env::var("CROSS_RUNNER").ok()?;
482+
if runner.is_empty() {
483+
return None;
480484
}
481-
None
485+
if cfg!(target_arch = "powerpc64") {
486+
Some("qemu-ppc64".to_string())
487+
} else if cfg!(target_arch = "x86") {
488+
Some("i386".to_string())
489+
} else {
490+
// Make a guess... Sigh.
491+
Some(format!("qemu-{}", std::env::consts::ARCH))
492+
}
493+
}
494+
495+
/// Returns true if the test setup believes Cross is running and `qemu` is
496+
/// needed to run ripgrep.
497+
///
498+
/// This is useful because it has been difficult to get some tests to pass
499+
/// under Cross.
500+
pub fn is_cross() -> bool {
501+
std::env::var("CROSS_RUNNER").ok().map_or(false, |v| !v.is_empty())
482502
}

0 commit comments

Comments
 (0)