Skip to content

Commit e7bd17c

Browse files
committed
Merge branch 'ps/ci-rust' into seen
CI improvements to handle the recent Rust integration better. Comments? * 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 4f94101 + 847a13c commit e7bd17c

File tree

9 files changed

+96
-9
lines changed

9 files changed

+96
-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)
@@ -1564,6 +1571,9 @@ ALL_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
15641571
ifdef WITH_RUST
15651572
BASIC_CFLAGS += -DWITH_RUST
15661573
GITLIBS += $(RUST_LIB)
1574+
ifeq ($(uname_S),Windows)
1575+
EXTLIBS += -luserenv
1576+
endif
15671577
endif
15681578

15691579
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,
@@ -120,21 +122,28 @@ esac
120122

121123
case "$jobname" in
122124
ClangFormat)
123-
sudo apt-get -q update
124125
sudo apt-get -q -y install clang-format
125126
;;
126127
StaticAnalysis)
127-
sudo apt-get -q update
128128
sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \
129129
libexpat-dev gettext make
130130
;;
131+
RustAnalysis)
132+
sudo apt-get -q -y install rustup
133+
rustup default stable
134+
rustup component add clippy rustfmt
135+
136+
wget -q "$CARGO_MSRV_WHENCE" -O "cargo-msvc.tgz"
137+
sudo mkdir -p "$CUSTOM_PATH"
138+
sudo tar -xf "cargo-msvc.tgz" --strip-components=1 \
139+
--directory "$CUSTOM_PATH" --wildcards "*/cargo-msrv"
140+
sudo chmod a+x "$CUSTOM_PATH/cargo-msrv"
141+
;;
131142
sparse)
132-
sudo apt-get -q update -q
133143
sudo apt-get -q -y install libssl-dev libcurl4-openssl-dev \
134144
libexpat-dev gettext zlib1g-dev sparse
135145
;;
136146
Documentation)
137-
sudo apt-get -q update
138147
sudo apt-get -q -y install asciidoc xmlto docbook-xsl-ns make
139148

140149
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
@@ -1717,6 +1717,10 @@ rust_option = get_option('rust').disable_auto_if(not cargo.found())
17171717
if rust_option.allowed()
17181718
subdir('src')
17191719
libgit_c_args += '-DWITH_RUST'
1720+
1721+
if host_machine.system() == 'windows'
1722+
libgit_dependencies += compiler.find_library('userenv')
1723+
endif
17201724
else
17211725
libgit_sources += [
17221726
'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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// # Safety
2+
///
3+
/// Callers must provide a NUL-terminated array to ensure safety.
14
#[no_mangle]
25
pub unsafe extern "C" fn decode_varint(bufp: *mut *const u8) -> u64 {
36
let mut buf = *bufp;
@@ -22,6 +25,11 @@ pub unsafe extern "C" fn decode_varint(bufp: *mut *const u8) -> u64 {
2225
val
2326
}
2427

28+
/// # Safety
29+
///
30+
/// The provided buffer must be large enough to store the encoded varint. Callers may either provide
31+
/// a `[u8; 16]` here, which is guaranteed to satisfy all encodable numbers. Or they can call this
32+
/// function with a `NULL` pointer first to figure out array size.
2533
#[no_mangle]
2634
pub unsafe extern "C" fn encode_varint(value: u64, buf: *mut u8) -> u8 {
2735
let mut varint: [u8; 16] = [0; 16];

0 commit comments

Comments
 (0)