Re: [PATCH RFC v2 1/7] meson: add infrastructure to build internal Rust library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 5, 2025 at 4:51 AM Patrick Steinhardt <ps@xxxxxx> wrote:
>
> 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.

Okay.

> 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.

This goes against what you said above, because it turns it into
something other than a test balloon.  As I've said elsewhere, I don't
think this part is helpful; it reduces the amount of notice that
distributors and platforms have about our intent to make Rust
mandatory.

> 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.

Cool.

> Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
> ---
>  meson.build       | 12 +++++++++++-
>  meson_options.txt |  2 ++
>  src/lib.rs        |  0
>  src/meson.build   | 15 +++++++++++++++
>  4 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/meson.build b/meson.build
> index e8ec0eca165..5b2e9af1bf1 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1702,8 +1702,17 @@ version_def_h = custom_target(
>  )
>  libgit_sources += version_def_h
>
> +libgit_libraries = [ ]
> +
> +rust_available = add_languages('rust', native: false, required: get_option('rust'))
> +rust_option = get_option('rust').disable_auto_if(not rust_available)
> +if rust_option.allowed()
> +  subdir('src')
> +  libgit_c_args += '-DWITH_RUST'
> +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 +2248,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..eb752651d35
> --- /dev/null
> +++ b/src/meson.build
> @@ -0,0 +1,15 @@
> +libgit_rs = static_library('git_rs',
> +  sources: [
> +    'lib.rs',
> +  ],
> +  rust_crate_type: 'staticlib',
> +)
> +libgit_libraries += libgit_rs
> +
> +# The 'rust' module was only introduced in Meson 1.0. Furthermore, the module
> +# does not seem to work on macOS as expected right now. As such, we only
> +# conditionally enable tests.
> +if meson.version().version_compare('>=1.0.0') and host_machine.system() != 'darwin'
> +  rustmod = import('rust')
> +  rustmod.test('rust', libgit_rs)
> +endif

Would it make sense to invoke 'cargo test' as one step of 'meson test'
on mac as an alternative, so that mac users also can run the tests?





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux