From 8d3d850b3450ca0c57a8d4a1d6a832783a376847 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Wed, 17 Jun 2026 18:01:22 -0700 Subject: [PATCH 1/5] tests: integration: add `libgit2` submodule --- .gitmodules | 5 +++++ tests/integration/tests/libgit2/repo | 1 + 2 files changed, 6 insertions(+) create mode 160000 tests/integration/tests/libgit2/repo diff --git a/.gitmodules b/.gitmodules index 69a39f6358..d13de09b28 100644 --- a/.gitmodules +++ b/.gitmodules @@ -101,3 +101,8 @@ path = tests/integration/tests/libmcs/repo url = https://gitlab.com/gtd-gmbh/libmcs update = none +[submodule "tests/integration/tests/libgit2"] + path = tests/integration/tests/libgit2/repo + url = https://github.com/libgit2/libgit2 + ignore = all + update = none diff --git a/tests/integration/tests/libgit2/repo b/tests/integration/tests/libgit2/repo new file mode 160000 index 0000000000..f7164261c9 --- /dev/null +++ b/tests/integration/tests/libgit2/repo @@ -0,0 +1 @@ +Subproject commit f7164261c9bc0a7e0ebf767c584e5192810a8b24 From 369a894c0ab81b9546ee2d9105e3234076f14b60 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Wed, 17 Jun 2026 18:22:47 -0700 Subject: [PATCH 2/5] tests: integration: add `libgit2` transpile support --- tests/integration/tests/libgit2/cmake.sh | 32 ++++++++++++++++++++++++ tests/integration/tests/libgit2/conf.yml | 14 +++++++++++ 2 files changed, 46 insertions(+) create mode 100755 tests/integration/tests/libgit2/cmake.sh create mode 100644 tests/integration/tests/libgit2/conf.yml diff --git a/tests/integration/tests/libgit2/cmake.sh b/tests/integration/tests/libgit2/cmake.sh new file mode 100755 index 0000000000..e22b3d0072 --- /dev/null +++ b/tests/integration/tests/libgit2/cmake.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e; set -o pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0" )" && pwd)" +LOG_FILE="$(basename "$0")".log +BUILD_DIR="$SCRIPT_DIR/repo/build" + +rm -f compile_commands.json + +cmake -S "$SCRIPT_DIR/repo" -B "$BUILD_DIR" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTS=OFF \ + -DBUILD_CLI=OFF \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_FUZZERS=OFF \ + -DUSE_HTTPS=OFF \ + -DUSE_SSH=OFF \ + -DUSE_SHA256=builtin \ + -DUSE_HTTP_PARSER=builtin \ + -DREGEX_BACKEND=builtin \ + -DUSE_BUNDLED_ZLIB=ON \ + -DUSE_NTLMCLIENT=OFF \ + -DUSE_ICONV=OFF \ + 2>&1 | tee "$LOG_FILE" + +# Configuring is enough: it generates compile_commands.json and every header +# that transpilation needs (e.g. gen_headers/{experimental,git2_features}.h). +# Building the library is not required to transpile, so we skip it. + +# The test runner expects compile_commands.json in the fixture directory. +ln -sf repo/build/compile_commands.json compile_commands.json diff --git a/tests/integration/tests/libgit2/conf.yml b/tests/integration/tests/libgit2/conf.yml new file mode 100644 index 0000000000..d771eed52e --- /dev/null +++ b/tests/integration/tests/libgit2/conf.yml @@ -0,0 +1,14 @@ +transpile: + autogen: true + tflags: --reorganize-definitions --disable-refactoring + # libgit2 builds its tests with GIT_DEPRECATE_HARD but not the library + # itself (which implements the deprecated APIs), so the same struct has two + # incompatible declarations across TUs (e.g. git_remote_callbacks.update_tips + # vs .reserved_update_tips). That breaks the refactor stage's + # reorganize_definitions pass, which merges declarations by name. Undefine + # the macro during transpilation so every TU sees one consistent view; the + # structs are layout-identical and the tests don't use deprecated APIs. + cflags: -UGIT_DEPRECATE_HARD + +cargo.transpile: + autogen: true From 9334f2647427b1f0c6c208dd328c1332eebca8f2 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Wed, 17 Jun 2026 19:09:52 -0700 Subject: [PATCH 3/5] tests: integration: enable `libgit2` in CI --- .github/workflows/internal-testsuite.yml | 5 ++++- tests/integration/tests/libgit2/conf.yml | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/internal-testsuite.yml b/.github/workflows/internal-testsuite.yml index 008d21b9c7..e66f5474c2 100644 --- a/.github/workflows/internal-testsuite.yml +++ b/.github/workflows/internal-testsuite.yml @@ -47,6 +47,7 @@ jobs: run: | git submodule update --init --checkout tests/integration/tests/curl/repo git submodule update --init --checkout tests/integration/tests/json-c/repo + git submodule update --init --checkout tests/integration/tests/libgit2/repo git submodule update --init --checkout tests/integration/tests/lua/repo git submodule update --init --checkout tests/integration/tests/nginx/repo git submodule update --init --checkout tests/integration/tests/zstd/repo @@ -75,6 +76,7 @@ jobs: sudo apt-get -qq install \ bear \ build-essential \ + cmake \ libbrotli-dev \ libbz2-dev \ libclang-${{ matrix.clang-version }}-dev \ @@ -91,6 +93,7 @@ jobs: librtmp-dev \ libtool \ libzstd-dev \ + pkg-config \ rcs \ tcl-dev \ tk-dev \ @@ -125,7 +128,7 @@ jobs: export PATH=$PWD/target/release:$PWD/c2rust-postprocess:$HOME/.local/bin:$PATH echo "PATH=$PATH" export C2RUST_DIR=$PWD - ./tests/integration/test.py curl json-c lua nginx zstd libxml2 python2 libmcs + ./tests/integration/test.py curl json-c libgit2 lua nginx zstd libxml2 python2 libmcs - uses: actions/upload-artifact@v4 with: diff --git a/tests/integration/tests/libgit2/conf.yml b/tests/integration/tests/libgit2/conf.yml index d771eed52e..bc7cabe997 100644 --- a/tests/integration/tests/libgit2/conf.yml +++ b/tests/integration/tests/libgit2/conf.yml @@ -1,3 +1,10 @@ +requirements: + ubuntu: + apt: + packages: + - cmake + - pkg-config + transpile: autogen: true tflags: --reorganize-definitions --disable-refactoring From db923905bdcf01ea1ecab6f24b7a70804cba7896 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Wed, 17 Jun 2026 19:57:44 -0700 Subject: [PATCH 4/5] tests: integration: add `libgit2` refactor support --- tests/integration/tests/libgit2/conf.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/integration/tests/libgit2/conf.yml b/tests/integration/tests/libgit2/conf.yml index bc7cabe997..13aa9e386f 100644 --- a/tests/integration/tests/libgit2/conf.yml +++ b/tests/integration/tests/libgit2/conf.yml @@ -19,3 +19,15 @@ transpile: cargo.transpile: autogen: true + +refactor: + autogen: true + transforms: + - rename_unnamed + - reorganize_definitions + - shorten_imported_paths + - remove_unused_labels + - remove_literal_suffixes + +cargo.refactor: + autogen: true From cd83a914809d44c7681fafa500ea0deefa657aa3 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Thu, 18 Jun 2026 00:43:32 -0700 Subject: [PATCH 5/5] tests: integration: add `libgit2` test support Enable the clar tests in the cmake configure, transpile the test runner as a binary, and run its offline suites via `test.sh`. --- tests/integration/tests/libgit2/cmake.sh | 11 ++++++----- tests/integration/tests/libgit2/conf.yml | 1 + tests/integration/tests/libgit2/test.sh | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100755 tests/integration/tests/libgit2/test.sh diff --git a/tests/integration/tests/libgit2/cmake.sh b/tests/integration/tests/libgit2/cmake.sh index e22b3d0072..f231c82ca6 100755 --- a/tests/integration/tests/libgit2/cmake.sh +++ b/tests/integration/tests/libgit2/cmake.sh @@ -10,7 +10,7 @@ rm -f compile_commands.json cmake -S "$SCRIPT_DIR/repo" -B "$BUILD_DIR" \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_TESTS=OFF \ + -DBUILD_TESTS=ON \ -DBUILD_CLI=OFF \ -DBUILD_EXAMPLES=OFF \ -DBUILD_FUZZERS=OFF \ @@ -24,9 +24,10 @@ cmake -S "$SCRIPT_DIR/repo" -B "$BUILD_DIR" \ -DUSE_ICONV=OFF \ 2>&1 | tee "$LOG_FILE" -# Configuring is enough: it generates compile_commands.json and every header -# that transpilation needs (e.g. gen_headers/{experimental,git2_features}.h). -# Building the library is not required to transpile, so we skip it. - # The test runner expects compile_commands.json in the fixture directory. ln -sf repo/build/compile_commands.json compile_commands.json + +# clar generates `clar_suite.h` at build time, so the test sources can't be +# transpiled until the test target is built. +cmake --build "$BUILD_DIR" --target libgit2_tests --parallel "$(nproc)" \ + 2>&1 | tee -a "$LOG_FILE" diff --git a/tests/integration/tests/libgit2/conf.yml b/tests/integration/tests/libgit2/conf.yml index 13aa9e386f..9c2dd420ee 100644 --- a/tests/integration/tests/libgit2/conf.yml +++ b/tests/integration/tests/libgit2/conf.yml @@ -7,6 +7,7 @@ requirements: transpile: autogen: true + binary: main # clar test runner's `main()` lives in tests/clar/main.c tflags: --reorganize-definitions --disable-refactoring # libgit2 builds its tests with GIT_DEPRECATE_HARD but not the library # itself (which implements the deprecated APIs), so the same struct has two diff --git a/tests/integration/tests/libgit2/test.sh b/tests/integration/tests/libgit2/test.sh new file mode 100755 index 0000000000..825f30c5c2 --- /dev/null +++ b/tests/integration/tests/libgit2/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e; set -o pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0" )" && pwd)" + +(cd "$SCRIPT_DIR/repo" && \ + cargo run --release 2>&1 \ + | tee "$SCRIPT_DIR/$(basename "$0")".log)