Skip to content

Commit 8642dec

Browse files
ezekielnewrengitster
authored andcommitted
github workflows: define rust versions and targets in the same place
Consolidate the Rust toolchain definitions in main.yaml. Prefer using actions-rs/toolchain@v1 where possible, but for docker targets use a script to install the Rust toolchain. Four overrides are used in main.yaml: * On Windows: Rust didn't resolve the bcrypt library on Windows correctly until version 1.78.0. Also since rustup mis-identifies the Rust toolchain, the Rust target triple must be set to x86_64-pc-windows-gnu. * On musl: libc differences, such as ftruncate64 vs ftruncate, were not accounted for until Rust version 1.72.0. No older version of Rust will work on musl for our needs. * In a 32-bit docker container running on a 64-bit host, we need to override the Rust target triple. This is because rustup asks the kernel for the bitness of the system and it says 64, even though the container will only run 32-bit. This also allows us to remove the BITNESS environment variable in ci/lib.sh. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f1cf460 commit 8642dec

File tree

7 files changed

+65
-41
lines changed

7 files changed

+65
-41
lines changed

.github/workflows/main.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on: [push, pull_request]
44

55
env:
66
DEVELOPER: 1
7-
RUST_VERSION: 1.87.0
87

98
# If more than one workflow run is triggered for the very same commit hash
109
# (which happens when multiple branches pointing to the same commit), only
@@ -27,6 +26,12 @@ jobs:
2726
outputs:
2827
enabled: ${{ steps.check-ref.outputs.enabled }}${{ steps.skip-if-redundant.outputs.enabled }}
2928
skip_concurrent: ${{ steps.check-ref.outputs.skip_concurrent }}
29+
rust_version_minimum: 1.61.0
30+
rust_version_windows: 1.78.0
31+
rust_version_musl: 1.72.0
32+
## the rust target is inferred by rustup unless specified
33+
rust_target_windows: x86_64-pc-windows-gnu
34+
rust_target_32bit_linux: i686-unknown-linux-gnu
3035
steps:
3136
- name: try to clone ci-config branch
3237
run: |
@@ -123,11 +128,19 @@ jobs:
123128
/c/Program\ Files/Git/mingw64/bin/curl -Lo libuserenv.a \
124129
https://github.com/git-for-windows/git-sdk-64/raw/HEAD/mingw64/lib/libuserenv.a
125130
}
131+
- name: Install Rust
132+
uses: actions-rs/toolchain@v1
133+
with:
134+
toolchain: ${{ needs.ci-config.outputs.rust_version_windows }}
135+
target: ${{ needs.ci-config.outputs.rust_target_windows }}
136+
profile: minimal
137+
override: true
126138
- name: build
127139
shell: bash
128140
env:
129141
HOME: ${{runner.workspace}}
130142
NO_PERL: 1
143+
CARGO_HOME: "/c/Users/runneradmin/.cargo"
131144
run: . /etc/profile && ci/make-test-artifacts.sh artifacts
132145
- name: zip up tracked files
133146
run: git archive -o artifacts/tracked.tar.gz HEAD
@@ -269,6 +282,13 @@ jobs:
269282
steps:
270283
- uses: actions/checkout@v4
271284
- uses: actions/setup-python@v5
285+
- name: Install Rust
286+
uses: actions-rs/toolchain@v1
287+
with:
288+
toolchain: ${{ needs.ci-config.outputs.rust_version_windows }}
289+
target: ${{ needs.ci-config.outputs.rust_target_windows }}
290+
profile: minimal
291+
override: true
272292
- name: Set up dependencies
273293
shell: pwsh
274294
run: pip install meson ninja
@@ -342,6 +362,12 @@ jobs:
342362
steps:
343363
- uses: actions/checkout@v4
344364
- run: ci/install-dependencies.sh
365+
- name: Install Rust
366+
uses: actions-rs/toolchain@v1
367+
with:
368+
toolchain: ${{ needs.ci-config.outputs.rust_version_minimum }}
369+
profile: minimal
370+
override: true
345371
- run: ci/run-build-and-tests.sh
346372
- name: print test failures
347373
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
@@ -402,9 +428,11 @@ jobs:
402428
cc: gcc
403429
- jobname: linux-musl-meson
404430
image: alpine:latest
431+
rust_version_override: ${{ needs.ci-config.outputs.rust_version_musl }}
405432
# Supported until 2025-04-02.
406433
- jobname: linux32
407434
image: i386/ubuntu:focal
435+
rust_target_override: ${{ needs.ci-config.outputs.rust_target_32bit_linux }}
408436
- jobname: pedantic
409437
image: fedora:latest
410438
# A RHEL 8 compatible distro. Supported until 2029-05-31.
@@ -417,7 +445,11 @@ jobs:
417445
jobname: ${{matrix.vector.jobname}}
418446
CC: ${{matrix.vector.cc}}
419447
CI_JOB_IMAGE: ${{matrix.vector.image}}
448+
CI_IS_DOCKER: "true"
420449
CUSTOM_PATH: /custom
450+
RUST_VERSION: ${{ matrix.vector.rust_version_override || needs.ci-config.outputs.rust_version_minimum }}
451+
RUST_TARGET: ${{ matrix.vector.rust_target_override || '' }}
452+
CARGO_HOME: /home/builder/.cargo
421453
runs-on: ubuntu-latest
422454
container: ${{matrix.vector.image}}
423455
steps:

build_rust.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#!/bin/sh
22

3-
if [ -z "$CARGO_HOME" ]; then
4-
export CARGO_HOME=$HOME/.cargo
5-
echo >&2 "::warning:: CARGO_HOME is not set"
6-
fi
7-
echo "CARGO_HOME=$CARGO_HOME"
83

9-
rustc -vV
10-
cargo --version
4+
rustc -vV || exit $?
5+
cargo --version || exit $?
116

127
dir_git_root=${0%/*}
138
dir_build=$1
@@ -55,7 +50,7 @@ dst=$dir_build/$libfile
5550
if [ "$dir_git_root" != "$dir_build" ]; then
5651
src=$dir_rust/target/$rust_target/$libfile
5752
if [ ! -f $src ]; then
58-
echo >&2 "::error:: cannot find path of static library"
53+
echo >&2 "::error:: cannot find path of static library $src is not a file or does not exist"
5954
exit 5
6055
fi
6156

ci/install-rust.sh

100644100755
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
#!/bin/sh
22

3+
## github workflows actions-rs/toolchain@v1 doesn't work for docker
4+
## targets. This script should only be used if the ci pipeline
5+
## doesn't support installing rust on a particular target.
6+
37
if [ "$(id -u)" -eq 0 ]; then
48
echo >&2 "::warning:: installing rust as root"
59
fi
610

7-
if [ "$CARGO_HOME" = "" ]; then
8-
echo >&2 "::warning:: CARGO_HOME is not set"
9-
export CARGO_HOME=$HOME/.cargo
10-
fi
11-
12-
export RUSTUP_HOME=$CARGO_HOME
13-
1411
if [ "$RUST_VERSION" = "" ]; then
1512
echo >&2 "::error:: RUST_VERSION is not set"
13+
exit 1
14+
fi
15+
16+
if [ "$CARGO_HOME" = "" ]; then
17+
echo >&2 "::error:: CARGO_HOME is not set"
1618
exit 2
1719
fi
1820

21+
export RUSTUP_HOME=$CARGO_HOME
22+
1923
## install rustup
2024
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y
2125
if [ ! -f $CARGO_HOME/env ]; then
2226
echo "PATH=$CARGO_HOME/bin:\$PATH" > $CARGO_HOME/env
2327
fi
28+
. $CARGO_HOME/env
29+
2430
## install a specific version of rust
25-
if [ "$BITNESS" = "32" ]; then
26-
$CARGO_HOME/bin/rustup set default-host i686-unknown-linux-gnu || exit $?
27-
$CARGO_HOME/bin/rustup install $RUST_VERSION || exit $?
28-
$CARGO_HOME/bin/rustup default --force-non-host $RUST_VERSION || exit $?
31+
if [ "$RUST_TARGET" != "" ]; then
32+
rustup default --force-non-host "$RUST_VERSION-$RUST_TARGET" || exit $?
2933
else
30-
$CARGO_HOME/bin/rustup default $RUST_VERSION || exit $?
31-
if [ "$CI_OS_NAME" = "windows" ]; then
32-
$CARGO_HOME/bin/rustup target add x86_64-pc-windows-gnu || exit $?
33-
fi
34+
rustup default "$RUST_VERSION" || exit $?
3435
fi
3536

36-
. $CARGO_HOME/env
37+
rustc -vV || exit $?

ci/lib.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
# Library of functions shared by all CI scripts
22

33

4-
export BITNESS="64"
5-
if command -v getconf >/dev/null && [ "$(getconf LONG_BIT 2>/dev/null)" = "32" ]; then
6-
export BITNESS="32"
7-
fi
8-
echo "BITNESS=$BITNESS"
9-
10-
114
if test true = "$GITHUB_ACTIONS"
125
then
136
begin_group () {

ci/make-test-artifacts.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ mkdir -p "$1" # in case ci/lib.sh decides to quit early
77

88
. ${0%/*}/lib.sh
99

10-
## install rust per user rather than system wide
11-
. ${0%/*}/install-rust.sh
10+
if [ -z "$CARGO_HOME" ]; then
11+
echo >&2 "::error:: CARGO_HOME is not set"
12+
exit 1
13+
fi
1214

13-
group Build make artifacts-tar ARTIFACTS_DIRECTORY="$1"
15+
export PATH="$CARGO_HOME/bin:$PATH"
1416

15-
if [ -d "$CARGO_HOME" ]; then
16-
rm -rf $CARGO_HOME
17-
fi
17+
group Build make artifacts-tar ARTIFACTS_DIRECTORY="$1"
1818

1919
check_unignored_build_artifacts

ci/run-build-and-tests.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
. ${0%/*}/lib.sh
77

8-
## install rust per user rather than system wide
9-
. ${0%/*}/install-rust.sh
8+
## actions-rs/toolchain@v1 doesn't work for docker targets.
9+
if [ "$CI_IS_DOCKER" = "true" ]; then
10+
. ${0%/*}/install-rust.sh
11+
fi
1012

11-
rustc -vV
13+
rustc -vV || exit $?
1214
cargo --version || exit $?
1315

1416
run_tests=t

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ rust_build_xdiff = custom_target('rust_build_xdiff',
293293
meson.project_source_root() / 'build_rust.sh',
294294
meson.current_build_dir(), rust_target, 'xdiff',
295295
],
296+
env: script_environment,
296297
install: false,
297298
)
298299

0 commit comments

Comments
 (0)