From 487bc2fce2fb43792aa5a12f88c4eac9a75a3ec0 Mon Sep 17 00:00:00 2001 From: Adrien Beraud Date: Sat, 24 Oct 2026 23:09:21 -0400 Subject: [PATCH] meson: add optional Rust bindings build --- meson.build | 42 ++++++++++++++++++++++++++++++++++++++++++ meson.options | 1 + 2 files changed, 43 insertions(+) diff --git a/meson.build b/meson.build index 4aedd6fd..d1ab4afc 100644 --- a/meson.build +++ b/meson.build @@ -208,6 +208,48 @@ if get_option('c').enabled() endif endif +rust_option = get_option('rust').require( + get_option('c').enabled(), + error_message: 'rust requires c', +).require( + get_option('default_library') != 'static', + error_message: 'rust requires shared libraries', +) +if rust_option.allowed() + cargo = find_program('cargo', required: rust_option) + if cargo.found() + rust_env = environment() + rust_env.prepend('LIBRARY_PATH', meson.current_build_dir()) + rust_env.prepend('LD_LIBRARY_PATH', meson.current_build_dir()) + rust_env.prepend('DYLD_LIBRARY_PATH', meson.current_build_dir()) + rust_env.prepend('PATH', meson.current_build_dir()) + cargo_args = [ + '--manifest-path', meson.current_source_dir() / 'rust/Cargo.toml', + '--target-dir', meson.current_build_dir() / 'rust', + ] + rust_build = custom_target( + 'rust-bindings', + output: 'rust-build.json', + command: [cargo, 'build', '--lib', '--examples', '--message-format=json-render-diagnostics'] + cargo_args, + env: rust_env, + depends: opendht_c, + capture: true, + build_by_default: true, + build_always_stale: true, + ) + if get_option('tests').enabled() + test( + 'Rust', + cargo, + args: ['test'] + cargo_args, + env: rust_env, + depends: rust_build, + timeout: 120, + ) + endif + endif +endif + if get_option('python').require( get_option('indexation').enabled(), error_message: 'python requires indexation', diff --git a/meson.options b/meson.options index 294a8e11..f1f95aa5 100644 --- a/meson.options +++ b/meson.options @@ -4,6 +4,7 @@ option('push_notifications', type : 'feature', value : 'disabled') option('peer_discovery', type : 'feature', value : 'enabled') option('tools', type : 'feature', value : 'enabled') option('c', type : 'feature', value : 'enabled') +option('rust', type : 'feature', value : 'disabled') option('indexation', type : 'feature', value : 'enabled') option('python', type : 'feature', value : 'enabled') option('tests', type : 'feature', value : 'enabled')