[PATCH v7 0/9] Introduce Rust and announce that it will become mandatory
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 25, 2025, 06:30 UTC
- Message-ID
- <20250925-b4-pks-rust-breaking-change-v7-0-4e49dcb904d5@pks.im>
- In-Reply-To
- <20250904-b4-pks-rust-breaking-change-v1-0-3af1d25e0be9@pks.im>
Hi,
this small patch series introduces Rust into the core of Git. This patch series is designed as a test balloon, similar to how we introduced test balloons for C99 features in the past. The goal is threefold:
- Give us some time to experiment with Rust and introduce proper build
infrastructure. - Give distributors time to ease into the new toolchain requirements.
Introducing Rust is impossible for some platforms and hard for
others. - Announce that Git 3.0 will make Rust a mandatory part of our build
infrastructure.The test balloon itself is quite uninteresting: I've chosen to convert the "varint.c" subsystem, mostly because it is trivial and does not have any dependencies. But it does allow us to verify that C to Rust interop works as expected, and to play around with tooling. All tests pass with the "varint.rs" implementation.
For now, the series only contains support for Meson. If we agree to go down this route I'll also introduce support for Rust into our Makefiles at a later point in time.
Furthermore missing is additional tooling:
- At least one CI job to verify that Rust builds and works as
expected. - Tooling and CI jobs to ensure that we have consistent formatting via
`cargo format`.And probably lots more. As said, the entire goal is for us to have an easy playground that we can experiment on and develop the infrastructure incrementally without yet having to commit to anything.
I'm mostly splitting out the topic of introducing Rust from the larger series that introduce it into xdiff so that we can focus more on the actual process of introducing Rust into Git and less on the potential features that we want to build on top of it.
Changes in v2:
- Introduce support for building the Rust library via our Makefile.
- Introduce a '-DWITH_RUST' define. This define is used to print
whether or not Git is built with Rust via `git version
--build-options`.
- Adjust Meson to not depend on v1.9.0 and newer anymore.
- Introduce a roadmap into our BreakingChanges document to explain how
we'll iterate towards mandatory Rust support.
- Rework the Fedora job to do a full compile-and-test run with Meson
and breaking changes enabled.
- Adapt our breaking-changes jobs to enable Rust support.
- Link to v1: https://lore.kernel.org/r/20250904-b4-pks-rust-breaking-change-v1-0-3af1d25e0be9@pks.imChanges in v3:
- Reorder all uses of `WITH_RUST` after the include of "config.mak".
- Add a test to verify overflow behaviour in Rust and explicitly use
`add_wrapping()`.
- Use explicit dependencies for the Rust library in our Makefile.
- Fix Alma Linux CI job.
- Stop tying maintenance of our LTS release to the availability of
gcc-rs.
- Add a fallback to Meson to use cargo directly.
- I've fixed the Rust edition to 2018 for now. This is intentionally
conservative so that we might be able to use Rust 1.49. For now, we
don't have any reason to use a newer edition, either. So let's take
the oldest version we can live with for now and then bump it as
required.
- Link to v2: https://lore.kernel.org/r/20250905-b4-pks-rust-breaking-change-v2-0-6939cbf4a0b8@pks.imChanges in v4:
- Convert "varint.c" to use explicit integer width so that we don't
need to use C types in Rust.
- Adapt Meson to unconditionally use Cargo.
- Don't use the unstable `--out-dir` option in Cargo. Instead, we
resort to a wrapper script in Meson.
- Shorten the timeline a bit to drop the extra step that ties Rust
support to `-Dbreaking_changes=true`. This accelerates the timeline
until distros are made forcibly aware of the upcoming changes in
Rust.
- Link to v3: https://lore.kernel.org/r/20250908-b4-pks-rust-breaking-change-v3-0-1cd7189fed3b@pks.imChanges in v5: - Fix indentation in the BreakingChanges document. - Fix a commit message typo. - Include "Cargo.lock" in the `make clean` target again. - Link to v4: https://lore.kernel.org/r/20250910-b4-pks-rust-breaking-change-v4-0-4a63fc69278d@pks.im
Changes in v6:
- Give attribution to Ezekiel for kickstarting the Rust adoption
again. I'm happy to change how I do the attribution.
- Fix "varint.rs" to use `u64` instead of `usize`. Issues like these
will eventually be catched by cbindgen.
- Adapt the breaking changes document to mention that we already have
Rust in our tree starting with Git 2.49.
- Mention that we won't blindly make Rust mandatory, but consider the
impact on downstream distributions.
- Slightly reword how we'll handle LTS maintainership. This probably
still is an ongoing discussion.
- Link to v5: https://lore.kernel.org/r/20250915-b4-pks-rust-breaking-change-v5-0-dc3a32fbb216@pks.imChanges in v7:
- Rename "git" crate to "gitcore".
- Some word smithing for the breaking changes doc.
- Punt on the exact details of how we hand over maintenance of the LTS
release to the community. This is something we can decide on in the
future.
- Link to v6: https://lore.kernel.org/r/20250923-b4-pks-rust-breaking-change-v6-0-59076fee486a@pks.imThanks!
Patrick
---
Patrick Steinhardt (9):
meson: add infrastructure to build internal Rust library
Makefile: reorder sources after includes
Makefile: introduce infrastructure to build internal Rust library
help: report on whether or not Rust is enabled
varint: use explicit width for integers
varint: reimplement as test balloon for Rust
BreakingChanges: announce Rust becoming mandatory
ci: convert "pedantic" job into full build with breaking changes
ci: enable Rust for breaking-changes jobs.github/workflows/main.yml | 4 +- .gitignore | 2 + .gitlab-ci.yml | 4 +- Cargo.toml | 9 ++ Documentation/BreakingChanges.adoc | 45 ++++++++ Makefile | 214 ++++++++++++++++++++++--------------- ci/install-dependencies.sh | 8 +- ci/run-build-and-tests.sh | 31 ++---- dir.c | 18 ++-- help.c | 6 ++ meson.build | 15 ++- meson_options.txt | 2 + read-cache.c | 6 +- shared.mak | 1 + src/cargo-meson.sh | 32 ++++++ src/lib.rs | 1 + src/meson.build | 41 +++++++ src/varint.rs | 92 ++++++++++++++++ varint.c | 6 +- varint.h | 4 +- 20 files changed, 410 insertions(+), 131 deletions(-)
Range-diff versus v6:
1: bb793b71e3 ! 1: 4c4b07ed93 meson: add infrastructure to build internal Rust library
@@ Commit message
## Cargo.toml (new) ##
@@
+[package]
-+name = "git"
++name = "gitcore"
+version = "0.1.0"
+edition = "2018"
+
@@ src/cargo-meson.sh (new)
+ exit $RET
+fi
+
-+if ! cmp "$BUILD_DIR/$BUILD_TYPE/libgit.a" "$BUILD_DIR/libgit.a" >/dev/null 2>&1
++if ! cmp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
+then
-+ cp "$BUILD_DIR/$BUILD_TYPE/libgit.a" "$BUILD_DIR/libgit.a"
++ cp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a"
+fi
## src/lib.rs (new) ##
@@ src/meson.build (new)
+ input: libgit_rs_sources + [
+ meson.project_source_root() / 'Cargo.toml',
+ ],
-+ output: 'libgit.a',
++ output: 'libgitcore.a',
+ command: cargo_command,
+)
+libgit_dependencies += declare_dependency(link_with: libgit_rs)
2: e3f8101578 = 2: 58633be050 Makefile: reorder sources after includes
3: 66673f7ce5 ! 3: 16300fbeba Makefile: introduce infrastructure to build internal Rust library
@@ Makefile: TEST_SHELL_PATH = $(SHELL_PATH)
XDIFF_LIB = xdiff/lib.a
REFTABLE_LIB = reftable/libreftable.a
+ifdef DEBUG
-+RUST_LIB = target/debug/libgit.a
++RUST_LIB = target/debug/libgitcore.a
+else
-+RUST_LIB = target/release/libgit.a
++RUST_LIB = target/release/libgitcore.a
+endif
# xdiff and reftable libs may in turn depend on what is in libgit.a
4: 65bcb1233d = 4: 240bc33e56 help: report on whether or not Rust is enabled
5: 908150d3ea = 5: 43e1f96e06 varint: use explicit width for integers
6: 8f92ff1e13 = 6: e9f421bfb6 varint: reimplement as test balloon for Rust
7: 5e88d4d553 ! 7: 73f4a8e639 BreakingChanges: announce Rust becoming mandatory
@@ Documentation/BreakingChanges.adoc: A prerequisite for this change is that the e
+support release. This long-term release will receive important bug fixes for at
+least four release cycles and security fixes for six release cycles. The Git
+project will hand over maintainership of the long-term release to distributors
-+in case they need to extend the life of that long-term release even further. In
-+that case, the backporting process will be handled by these distributors, but
-+the long-term release tags will be created in the canonical Git repository.
++in case they need to extend the life of that long-term release even further.
++Details of how this long-term release will be handed over to the community will
++be discussed once the Git project decides to stop officially supporting it.
++
+We will evaluate the impact on downstream distributions before making Rust
+mandatory in Git 3.0. If we see that the impact on downstream distributions
-+would be significant, we may decide to defer this breaking change to a
-+subsequent minor release. This evaluation will also take into account our own
-+learnings with how painful it is to keep Rust an optional component.
++would be significant, we may decide to defer this change to a subsequent minor
++release. This evaluation will also take into account our own experience with
++how painful it is to keep Rust an optional component.
+
=== Removals
8: d7d7256a48 = 8: c1d3c3fcab ci: convert "pedantic" job into full build with breaking changes
9: a38eec0af9 = 9: 14271538e3 ci: enable Rust for breaking-changes jobs--- base-commit: 2462961280690837670d997bde64bd4ebf8ae66d change-id: 20250904-b4-pks-rust-breaking-change-7167d9d3e37d