git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 01/15] doc: add a policy for using Rust

From
brian m. carlson via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 29, 2025, 19:42 UTC
Message-ID
<6d065f550fe871cf010409f7bd2a63438cf52723.1756496539.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2043.git.git.1756496539.gitgitgadget@gmail.com>
From: "brian m. carlson" <sandals@crustytoothpaste.net>

Git has historically been written primarily in C, with some shell and Perl. However, C is not memory safe, which makes it more likely that security vulnerabilities or other bugs will be introduced, and it is also more verbose and less ergonomic than other, more modern languages.

One of the most common modern compiled languages which is easily interoperable with C is Rust. It is popular (the most admired language on the 2024 Stack Overflow Developer Survey), efficient, portable, and robust.

Introduce a document laying out the incremental introduction of Rust to Git and provide a detailed rationale for doing so, including the points above. Propose a design for this approach that addresses the needs of downstreams and distributors, as well as contributors.

Since we don't want to carry both a C and Rust version of code and want to be able to add new features only in Rust, mention that Rust is a required part of our platform support policy.

It should be noted that a recent discussion at the Berlin Git Merge Contributor Summit found widespread support for the addition of Rust to Git. While of course not all contributors were represented, the proposal appeared to have the support of a majority of active contributors.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
[en: Added some comments about types, and changed the recommondations
     about cbindgen, bindgen, rustix, libc.]
Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com>
---
 Documentation/Makefile                        |   1 +
 Documentation/technical/platform-support.adoc |   2 +
 Documentation/technical/rust-support.adoc     | 142 ++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 Documentation/technical/rust-support.adoc
diff --git a/Documentation/Makefile b/Documentation/Makefile
index b109d25e9c..066b761c01 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -127,6 +127,7 @@ TECH_DOCS += technical/parallel-checkout
 TECH_DOCS += technical/partial-clone
 TECH_DOCS += technical/platform-support
 TECH_DOCS += technical/racy-git
+TECH_DOCS += technical/rust-support
 TECH_DOCS += technical/reftable
 TECH_DOCS += technical/scalar
 TECH_DOCS += technical/send-pack-pipeline
diff --git a/Documentation/technical/platform-support.adoc b/Documentation/technical/platform-support.adoc
index 0a2fb28d62..dc71672dcb 100644
--- a/Documentation/technical/platform-support.adoc
+++ b/Documentation/technical/platform-support.adoc
@@ -33,6 +33,8 @@ meet the following minimum requirements:
 
 * Has active security support (taking security releases of dependencies, etc)
 
+* Supports Rust and the toolchain version specified in link:rust-support.adoc[].
+
 These requirements are a starting point, and not sufficient on their own for the
 Git community to be enthusiastic about supporting your platform. Maintainers of
 platforms which do meet these requirements can follow the steps below to make it
diff --git a/Documentation/technical/rust-support.adoc b/Documentation/technical/rust-support.adoc
new file mode 100644
index 0000000000..57a001fa2d
--- /dev/null
+++ b/Documentation/technical/rust-support.adoc
@@ -0,0 +1,142 @@
+Usage of Rust in Git
+====================
+
+Objective
+---------
+Introduce Rust into Git incrementally to improve security and maintainability.
+
+Background
+----------
+Git has historically been written primarily in C, with some portions in shell,
+Perl, or other languages.  At the time it was originally written, this was
+important for portability and was a logical choice for software development.
+
+:0: link:https://security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html
+:1: link:https://www.cisa.gov/resources-tools/resources/product-security-bad-practices
+
+However, as time has progressed, we've seen an increased concern with memory
+safety vulnerabilities and the development of newer languages, such as Rust,
+that substantially limit or eliminate this class of vulnerabilities.
+Development in a variety of projects has found that memory safety
+vulnerabilities constitute about 70% of vulnerabilities of software in
+languages that are not memory safe.  For instance, {0}[one survey of Android]
+found that memory safety vulnerabilities decreased from 76% to 24% over six
+years due to an increase in memory safe code.  Similarly, the U.S. government
+is {1}[proposing to classify development in memory unsafe languages as a
+Product Security Bad Practice"].
+
+These risks are even more substantial when we consider the fact that Git is a
+network-facing service.  Many organizations run Git servers internally or use a
+cloud-based forge, and the risk of accidental exposure or compromise of user
+data is substantial.  It's important to ensure that Git, whether it's used
+locally or remotely, is robustly secure.
+
+In addition, C is a difficult language to write well and concisely.  While it
+is of course possible to do anything with C, it lacks built-in support for
+niceties found in modern languages, such as hash tables, generics, typed
+errors, and automatic destruction, and most modern language offer shorter, more
+ergonomic syntax for expressing code.  This is valuable functionality that can
+allow Git to be developed more rapidly, more easily, by more developers of a
+variety of levels, and with more confidence in the correctness of the code.
+
+For these reasons, adding Rust to Git is a sensible and prudent move that will
+allow us to improve the quality of the code and potentially attract new developers.
+
+Goals
+-----
+1. Git continues to build, run, and pass tests on a wide variety of operating
+   systems and architectures.
+2. Transition from C to Rust is incremental; that is, code can be ported as it
+   is convenient and Git does not need to transition all at once.
+3. Git continues to support older operating systems in conformance with the
+   platform support policy.
+
+Non-Goals
+---------
+1. Support for every possible operating system and architecture.  Git already
+   has a platform support policy which defines what is supported and we already
+   exclude some operating systems for various reasons (e.g., lacking enough POSIX
+   tools to pass the test suite).
+2. Implementing C-only versions of Rust code or compiling a C-only Git.  This
+   would be difficult to maintain and would not offer the ergonomic benefits we
+   desire.
+
+Design
+------
+Git will adopt Rust incrementally.  This transition will start with the
+creation of a static library that can be linked into the existing Git binaries.
+At some point, we may wish to expose a dynamic library and compile the Git
+binaries themselves using Rust.  Using an incremental approach allows us to
+determine as we go along how to structure our code in the best way for the
+project and avoids the need to make hard, potentially disruptive, transitions
+caused by porting a binary wholesale from one language to another that might
+introduce bugs.
+
+Crates like libc or rustix define types like c_long, but in ways that are not
+safe across platforms.
+From https://docs.rs/rustix/latest/rustix/ffi/type.c_long.html:
+
+    This type will always be i32 or i64.  Most notably, many Linux-based
+    systems assume an i64, but Windows assumes i32.  The C standard technically
+    only requires that this type be a signed integer that is at least 32 bits
+    and at least the size of an int, although in practice, no system would
+    have a long that is neither an i32 nor i64.
+
+Also, note that other locations, such as
+https://docs.rs/libc/latest/libc/type.c_long.html, just hardcode c_long as i64
+even though C may mean i32 on some platforms.
+
+As such, using the c_long type would give us portability issues, and
+perpetuate some of the bugs git has faced across platforms.  Avoid using C's
+types (long, unsigned, char, etc.), and switch to unambiguous types (e.g. i32
+or i64) before trying to make C and Rust interoperate.
+
+Crates like libc and rustix may have also traditionally aided interoperability
+with older versions of Rust (e.g.  when worrying about stat[64] system calls),
+but the Rust standard library in newer versions of Rust handle these concerns
+in a platform agnostic way.  There may arise cases where we need to consider
+these crates, but for now we omit them.
+
+Tools like bindgen and cbindgen create C-styled unsafe Rust code rather than
+idiomatic Rust; where possible, we prefer to switch to idiomatic Rust.  Any
+standard C library functions that are needed can be manually wrapped on the
+Rust side.
+
+Rust upstream releases every six weeks and only supports the latest stable
+release.  While it is nice that upstream is active, we would like our software
+releases to have a lifespan exceeding six weeks.  To allow compiling our code
+on a variety of systems, we will support the version of Rust in Debian stable,
+plus, for a year after a new Debian stable is released, the version in Debian
+oldstable.
+
+This provides an approximately three-year lifespan of support for a Rust
+release and allows us to support a variety of operating systems and
+architectures, including those for which Rust upstream does not build binaries.
+Debian stable is the benchmark distribution used by many Rust projects when
+determining supported Rust versions, and it is an extremely portable and
+popular free software operating system that is available to the public at no
+charge, which makes it a sensible choice for us as well.
+
+We may change this policy if the Rust project issues long-term support releases
+or the Rust community and distributors agree on releases to target as if they
+were long-term support releases.
+
+This version support policy necessitates that we be very careful about the
+dependencies we include, since many Rust projects support only the latest
+stable version.  However, we typically have been careful about dependencies in
+the first place, so this should not be a major departure from existing policy,
+although it may be a change for some existing Rust developers.
+
+We will avoid including the `Cargo.lock` file in the repository and instead
+specify minimum dependency versions in the `Cargo.toml` file.  We want to allow
+people to use newer versions of dependencies if necessary to support newer
+platforms without needing to force upgrades of dependencies on all users, and
+it provides additional flexibility for distribution maintainers.
+
+We do not plan to support beta or nightly versions of the Rust compiler.  These
+versions may change rapidly and especially parts of the toolchain such as
+Clippy, the lint tool, can have false positives or add additional warnings with
+too great of a frequency to be supportable by the project.  However, we do plan
+to support alternate compilers, such as the rust_codegen_gcc backend and gccrs
+when they are stable and support our desired release versions.  This will
+provide greater support for more operating systems and architectures.
-- 
gitgitgadget
Previous: Ezekiel Newren via GitGitGadgetNext: brian m. carlson
Message 2 of 100 in “Introduce rust: In xdiff”
  1. 00/15 Introduce rust: In xdiffEzekiel Newren via GitGitGadget, Aug 29, 2025
  2. 01/15 doc: add a policy for using Rustbrian m. carlson via GitGitGadget, Aug 29, 2025
  3. brian m. carlsonAug 29, 2025
  4. Ezekiel NewrenAug 29, 2025
  5. brian m. carlsonSep 2, 2025
  6. Ezekiel NewrenSep 2, 2025
  7. Ezekiel NewrenSep 4, 2025
  8. 02/15 xdiff: introduce rustEzekiel Newren via GitGitGadget, Aug 29, 2025
  9. 03/15 github workflows: install rustEzekiel Newren via GitGitGadget, Aug 29, 2025
  10. 04/15 win+Meson: do allow linking with the Rust-built xdiffJohannes Schindelin via GitGitGadget, Aug 29, 2025
  11. 05/15 github workflows: upload Cargo.lockEzekiel Newren via GitGitGadget, Aug 29, 2025
  12. 06/15 ivec: create a vector type that is interoperable between C and RustEzekiel Newren via GitGitGadget, Aug 29, 2025
  13. 07/15 xdiff/xprepare: remove superfluous forward declarationsEzekiel Newren via GitGitGadget, Aug 29, 2025
  14. 08/15 xdiff: delete unnecessary fields from xrecord_t and xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  15. 09/15 xdiff: make fields of xrecord_t Rust friendlyEzekiel Newren via GitGitGadget, Aug 29, 2025
  16. 10/15 xdiff: use one definition for freeing xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  17. 11/15 xdiff: replace chastore with an ivec in xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  18. 12/15 xdiff: delete nrec field from xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  19. 13/15 xdiff: delete recs field from xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  20. 14/15 xdiff: make xdfile_t more rust friendlyEzekiel Newren via GitGitGadget, Aug 29, 2025
  21. 15/15 xdiff: implement xdl_trim_ends() in RustEzekiel Newren via GitGitGadget, Aug 29, 2025
  22. 00/18 Introduce rust: In xdiffEzekiel Newren via GitGitGadget, Sep 17, 2025
  23. 01/18 cleanup: rename variables that collide with Rust primitive type namesEzekiel Newren via GitGitGadget, Sep 17, 2025
  24. Eric SunshineSep 17, 2025
  25. Junio C HamanoSep 17, 2025
  26. Ezekiel NewrenSep 19, 2025
  27. 02/18 make: add -fPIE flagEzekiel Newren via GitGitGadget, Sep 17, 2025
  28. Eric SunshineSep 17, 2025
  29. Ezekiel NewrenSep 19, 2025
  30. Junio C HamanoSep 19, 2025
  31. Ezekiel NewrenSep 19, 2025
  32. Junio C HamanoSep 19, 2025
  33. Collin FunkSep 19, 2025
  34. Junio C HamanoSep 20, 2025
  35. Ramsay JonesSep 21, 2025
  36. 03/18 make: merge xdiff lib into libgit.aEzekiel Newren via GitGitGadget, Sep 17, 2025
  37. Eric SunshineSep 17, 2025
  38. Ezekiel NewrenSep 19, 2025
  39. 04/18 make: merge reftable lib into libgit.aEzekiel Newren via GitGitGadget, Sep 17, 2025
  40. Eric SunshineSep 17, 2025
  41. Junio C HamanoSep 19, 2025
  42. Ezekiel NewrenSep 19, 2025
  43. Junio C HamanoSep 19, 2025
  44. Ezekiel NewrenSep 19, 2025
  45. 05/18 doc: add a policy for using Rustbrian m. carlson via GitGitGadget, Sep 17, 2025
  46. 06/18 BreakingChanges: announce Rust becoming mandatoryPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  47. 07/18 build: introduce rustEzekiel Newren via GitGitGadget, Sep 17, 2025
  48. Eric SunshineSep 17, 2025
  49. Junio C HamanoSep 17, 2025
  50. Eric SunshineSep 18, 2025
  51. Ezekiel NewrenSep 19, 2025
  52. Eric SunshineSep 19, 2025
  53. Ezekiel NewrenSep 19, 2025
  54. 08/18 help: report on whether or not Rust is enabledPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  55. 09/18 github workflows: install rustEzekiel Newren via GitGitGadget, Sep 17, 2025
  56. Eric SunshineSep 17, 2025
  57. 10/18 win+Meson: do allow linking with the Rust-built xdiffJohannes Schindelin via GitGitGadget, Sep 17, 2025
  58. 11/18 github workflows: upload Cargo.lockEzekiel Newren via GitGitGadget, Sep 17, 2025
  59. 12/18 build: new crate, build-helperEzekiel Newren via GitGitGadget, Sep 17, 2025
  60. Eric SunshineSep 17, 2025
  61. 13/18 build-helper: link against libgit.a and any other required C librariesEzekiel Newren via GitGitGadget, Sep 17, 2025
  62. Eric SunshineSep 17, 2025
  63. D. Ben KnobleSep 17, 2025
  64. Eric SunshineSep 17, 2025
  65. Ezekiel NewrenSep 19, 2025
  66. 14/18 build-helper: cbindgen, let crates generate a header fileEzekiel Newren via GitGitGadget, Sep 17, 2025
  67. Eric SunshineSep 17, 2025
  68. Ezekiel NewrenSep 19, 2025
  69. 15/18 varint: use explicit width for integersPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  70. 16/18 build: new crate, miscEzekiel Newren via GitGitGadget, Sep 17, 2025
  71. Eric SunshineSep 17, 2025
  72. Ezekiel NewrenSep 19, 2025
  73. Eric SunshineSep 19, 2025
  74. Ezekiel NewrenSep 19, 2025
  75. 17/18 misc: use BuildHelperEzekiel Newren via GitGitGadget, Sep 17, 2025
  76. 18/18 misc::varint: reimplement as test balloon for RustPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  77. Patrick SteinhardtSep 17, 2025
  78. Ezekiel NewrenSep 19, 2025
  79. Patrick SteinhardtSep 22, 2025
  80. Ezekiel NewrenSep 22, 2025
  81. Patrick SteinhardtSep 22, 2025
  82. Junio C HamanoSep 22, 2025
  83. Ezekiel NewrenSep 22, 2025
  84. Ezekiel NewrenSep 22, 2025
  85. Junio C HamanoSep 22, 2025
  86. Ezekiel NewrenSep 22, 2025
  87. Junio C HamanoSep 22, 2025
  88. Junio C HamanoSep 22, 2025
  89. Junio C HamanoSep 17, 2025
  90. Junio C HamanoSep 17, 2025
  91. Elijah NewrenSep 17, 2025
  92. Junio C HamanoSep 17, 2025
  93. Patrick SteinhardtSep 22, 2025
  94. Ezekiel NewrenSep 22, 2025
  95. Patrick SteinhardtSep 22, 2025
  96. Ezekiel NewrenSep 22, 2025
  97. Patrick SteinhardtSep 23, 2025
  98. Ezekiel NewrenSep 23, 2025
  99. Ezekiel NewrenSep 23, 2025
  100. Junio C HamanoSep 23, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.