[PATCH RFC 1/3] meson: add infrastructure to build internal Rust library
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 4, 2025, 14:26 UTC
- Message-ID
- <20250904-b4-pks-rust-breaking-change-v1-1-3af1d25e0be9@pks.im>
- In-Reply-To
- <20250904-b4-pks-rust-breaking-change-v1-0-3af1d25e0be9@pks.im>
Add the infrastructure into Meson to build an internal Rust library. Building the Rust parts of Git are for now entirely optional, as they are mostly intended as a test balloon for both Git developers, but also for distributors of Git. So for now, they may contain:
- New features that are not mission critical to Git and that users can
easily live without.- Alternative implementations of small subsystems.
If these test balloons are successful, we will eventually make Rust a mandatory dependency for our build process in Git 3.0.
The availability of a Rust toolchain will be auto-detected by Meson at setup time. This behaviour can be tweaked via the `-Drust=` feature toggle.
Next to the linkable Rust library, also wire up tests that can be executed via `meson test`. This allows us to use the native unit testing capabilities of Rust.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- meson.build | 16 +++++++++++++++- meson_options.txt | 2 ++ src/lib.rs | 0 src/meson.build | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build index e8ec0eca165..1c0e98bbc14 100644 --- a/meson.build +++ b/meson.build @@ -1702,8 +1702,21 @@ version_def_h = custom_target( ) libgit_sources += version_def_h +libgit_libraries = [ ] + +if meson.version().version_compare('>=1.9.0') + rust_available = add_languages('rust', native: false, required: get_option('rust')) +else + rust_available = false +endif +rust_option = get_option('rust').disable_auto_if(not rust_available) + +if rust_option.allowed() and meson.version().version_compare('>=1.9.0') + subdir('src') +endif + libgit = declare_dependency( - link_with: static_library('git', + link_with: libgit_libraries + static_library('git', sources: libgit_sources, c_args: libgit_c_args + [ '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', @@ -2239,6 +2252,7 @@ summary({ 'pcre2': pcre2, 'perl': perl_features_enabled, 'python': target_python.found(), + 'rust': rust_option.allowed(), }, section: 'Auto-detected features', bool_yn: true) summary({ diff --git a/meson_options.txt b/meson_options.txt index 1668f260a18..143dee9237c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -71,6 +71,8 @@ option('zlib_backend', type: 'combo', choices: ['auto', 'zlib', 'zlib-ng'], valu # Build tweaks. option('breaking_changes', type: 'boolean', value: false, description: 'Enable upcoming breaking changes.') +option('rust', type: 'feature', value: 'auto', + description: 'Enable building with Rust.') option('macos_use_homebrew_gettext', type: 'boolean', value: true, description: 'Use gettext from Homebrew instead of the slightly-broken system-provided one.') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 00000000000..2bd2045a8ab --- /dev/null +++ b/src/meson.build @@ -0,0 +1,12 @@ +rustmod = import('rust') + +libgit_rs = static_library('git_rs', + sources: [ + 'lib.rs', + ], + rust_abi: 'c', +) + +rustmod.test('git-rs', libgit_rs) + +libgit_libraries += libgit_rs
-- 2.51.0.417.g1ba7204a04.dirty