Skip to content

Commit fe95c55

Browse files
committed
Merge branch 'ps/ci-rust'
CI improvements to handle the recent Rust integration better. * ps/ci-rust: rust: support for Windows ci: verify minimum supported Rust version ci: check for common Rust mistakes via Clippy rust/varint: add safety comments ci: check formatting of our Rust code ci: deduplicate calls to `apt-get update`
2 parents 3deb97f + e509b5b commit fe95c55

File tree

9 files changed

+103
-9
lines changed

9 files changed

+103
-9
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,21 @@ jobs:
458458
- run: ci/install-dependencies.sh
459459
- run: ci/run-static-analysis.sh
460460
- run: ci/check-directional-formatting.bash
461+
rust-analysis:
462+
needs: ci-config
463+
if: needs.ci-config.outputs.enabled == 'yes'
464+
env:
465+
jobname: RustAnalysis
466+
CI_JOB_IMAGE: ubuntu:rolling
467+
runs-on: ubuntu-latest
468+
container: ubuntu:rolling
469+
concurrency:
470+
group: rust-analysis-${{ github.ref }}
471+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
472+
steps:
473+
- uses: actions/checkout@v4
474+
- run: ci/install-dependencies.sh
475+
- run: ci/run-rust-checks.sh
461476
sparse:
462477
needs: ci-config
463478
if: needs.ci-config.outputs.enabled == 'yes'

.gitlab-ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test:mingw64:
161161
- saas-windows-medium-amd64
162162
before_script:
163163
- *windows_before_script
164-
- choco install -y git meson ninja
164+
- choco install -y git meson ninja rust-ms
165165
- Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
166166
- refreshenv
167167

@@ -212,6 +212,17 @@ static-analysis:
212212
- ./ci/run-static-analysis.sh
213213
- ./ci/check-directional-formatting.bash
214214

215+
rust-analysis:
216+
image: ubuntu:rolling
217+
stage: analyze
218+
needs: [ ]
219+
variables:
220+
jobname: RustAnalysis
221+
before_script:
222+
- ./ci/install-dependencies.sh
223+
script:
224+
- ./ci/run-rust-checks.sh
225+
215226
check-whitespace:
216227
image: ubuntu:latest
217228
stage: analyze

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "gitcore"
33
version = "0.1.0"
44
edition = "2018"
5+
rust-version = "1.49.0"
56

67
[lib]
78
crate-type = ["staticlib"]

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,17 @@ export PYTHON_PATH
927927
TEST_SHELL_PATH = $(SHELL_PATH)
928928

929929
LIB_FILE = libgit.a
930+
930931
ifdef DEBUG
931-
RUST_LIB = target/debug/libgitcore.a
932+
RUST_TARGET_DIR = target/debug
932933
else
933-
RUST_LIB = target/release/libgitcore.a
934+
RUST_TARGET_DIR = target/release
935+
endif
936+
937+
ifeq ($(uname_S),Windows)
938+
RUST_LIB = $(RUST_TARGET_DIR)/gitcore.lib
939+
else
940+
RUST_LIB = $(RUST_TARGET_DIR)/libgitcore.a
934941
endif
935942

936943
GITLIBS = common-main.o $(LIB_FILE)
@@ -1556,6 +1563,9 @@ ALL_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
15561563
ifdef WITH_RUST
15571564
BASIC_CFLAGS += -DWITH_RUST
15581565
GITLIBS += $(RUST_LIB)
1566+
ifeq ($(uname_S),Windows)
1567+
EXTLIBS += -luserenv
1568+
endif
15591569
endif
15601570

15611571
ifdef SANITIZE

ci/install-dependencies.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ begin_group "Install dependencies"
1010
P4WHENCE=https://cdist2.perforce.com/perforce/r23.2
1111
LFSWHENCE=https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION
1212
JGITWHENCE=https://repo1.maven.org/maven2/org/eclipse/jgit/org.eclipse.jgit.pgm/6.8.0.202311291450-r/org.eclipse.jgit.pgm-6.8.0.202311291450-r.sh
13+
CARGO_MSRV_VERSION=0.18.4
14+
CARGO_MSRV_WHENCE=https://github.com/foresterre/cargo-msrv/releases/download/v$CARGO_MSRV_VERSION/cargo-msrv-x86_64-unknown-linux-musl-v$CARGO_MSRV_VERSION.tgz
1315

1416
# Make sudo a no-op and execute the command directly when running as root.
1517
# While using sudo would be fine on most platforms when we are root already,
@@ -129,21 +131,28 @@ esac
129131

130132
case "$jobname" in
131133
ClangFormat)
132-
sudo apt-get -q update
133134
sudo apt-get -q -y install clang-format
134135
;;
135136
StaticAnalysis)
136-
sudo apt-get -q update
137137
sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \
138138
libexpat-dev gettext make
139139
;;
140+
RustAnalysis)
141+
sudo apt-get -q -y install rustup
142+
rustup default stable
143+
rustup component add clippy rustfmt
144+
145+
wget -q "$CARGO_MSRV_WHENCE" -O "cargo-msvc.tgz"
146+
sudo mkdir -p "$CUSTOM_PATH"
147+
sudo tar -xf "cargo-msvc.tgz" --strip-components=1 \
148+
--directory "$CUSTOM_PATH" --wildcards "*/cargo-msrv"
149+
sudo chmod a+x "$CUSTOM_PATH/cargo-msrv"
150+
;;
140151
sparse)
141-
sudo apt-get -q update -q
142152
sudo apt-get -q -y install libssl-dev libcurl4-openssl-dev \
143153
libexpat-dev gettext zlib1g-dev sparse
144154
;;
145155
Documentation)
146-
sudo apt-get -q update
147156
sudo apt-get -q -y install asciidoc xmlto docbook-xsl-ns make
148157

149158
test -n "$ALREADY_HAVE_ASCIIDOCTOR" ||

ci/run-rust-checks.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
. ${0%/*}/lib.sh
4+
5+
set +x
6+
7+
if ! group "Check Rust formatting" cargo fmt --all --check
8+
then
9+
RET=1
10+
fi
11+
12+
if ! group "Check for common Rust mistakes" cargo clippy --all-targets --all-features -- -Dwarnings
13+
then
14+
RET=1
15+
fi
16+
17+
if ! group "Check for minimum required Rust version" cargo msrv verify
18+
then
19+
RET=1
20+
fi
21+
22+
exit $RET

meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,10 @@ rust_option = get_option('rust').disable_auto_if(not cargo.found())
17081708
if rust_option.allowed()
17091709
subdir('src')
17101710
libgit_c_args += '-DWITH_RUST'
1711+
1712+
if host_machine.system() == 'windows'
1713+
libgit_dependencies += compiler.find_library('userenv')
1714+
endif
17111715
else
17121716
libgit_sources += [
17131717
'varint.c',

src/cargo-meson.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ then
2626
exit $RET
2727
fi
2828

29-
if ! cmp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
29+
case "$(cargo -vV | sed -s 's/^host: \(.*\)$/\1/')" in
30+
*-windows-*)
31+
LIBNAME=gitcore.lib;;
32+
*)
33+
LIBNAME=libgitcore.a;;
34+
esac
35+
36+
if ! cmp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
3037
then
31-
cp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a"
38+
cp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
3239
fi

src/varint.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/// Decode the variable-length integer stored in `bufp` and return the decoded value.
2+
///
3+
/// Returns 0 in case the decoded integer would overflow u64::MAX.
4+
///
5+
/// # Safety
6+
///
7+
/// The buffer must be NUL-terminated to ensure safety.
18
#[no_mangle]
29
pub unsafe extern "C" fn decode_varint(bufp: *mut *const u8) -> u64 {
310
let mut buf = *bufp;
@@ -22,6 +29,14 @@ pub unsafe extern "C" fn decode_varint(bufp: *mut *const u8) -> u64 {
2229
val
2330
}
2431

32+
/// Encode `value` into `buf` as a variable-length integer unless `buf` is null.
33+
///
34+
/// Returns the number of bytes written, or, if `buf` is null, the number of bytes that would be
35+
/// written to encode the integer.
36+
///
37+
/// # Safety
38+
///
39+
/// `buf` must either be null or point to at least 16 bytes of memory.
2540
#[no_mangle]
2641
pub unsafe extern "C" fn encode_varint(value: u64, buf: *mut u8) -> u8 {
2742
let mut varint: [u8; 16] = [0; 16];

0 commit comments

Comments
 (0)