[vlc-commits] [Git][videolan/vlc][master] 7 commits: vlcrs-core: specify how we link libvlccore

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sat Apr 4 16:46:21 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
ec7382a6 by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
vlcrs-core: specify how we link libvlccore

Declare the links = "vlccore" and allow a specific cargo
configuration to signal to the crate whether we actually link libvlccore
or not.

- - - - -
0c481c0b by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
vlcrs-core: build.rs: add build script to signal no linkage

cargo test -p vlcrs-core fails because the test binary needs to link
against symbols from libvlccore, more precisely they currently depend
on vlc_object_create and vlc_object_delete.

Add a build.rs that signal there is no linkage configured by default, so
that it default to this. Buildsystems and user configuration can override
the configuration with .cargo/config.toml or --config parameter to
provide them, which disable the build.rs script and thus removes the
activation of the custom cfg().

- - - - -
abf28491 by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
cargo-test.py: integrate vlcrs-core tests with libvlccore linking

cargo test -p vlcrs-core fails because the test binary needs to link
against symbols from libvlccore, more precisely they currently depend
on vlc_object_create and vlc_object_delete.

Previous commit added a build.rs that indicates we're not actually
linking libvlccore, but since the cargo-test.py is made to be run within
a build folder, we actually have everything to configure the linking for
the test binaries.

Note that adding the link configuration is safe for non-tests builds, as
cargo build for modules actually produces an .rlib with no final linking
and that we repackage into a shared object (when needed) manually, so
the directives are generated but unused.

Co-authored-by: Alaric Senat <alaric at videolabs.io>

- - - - -
82c2fb2d by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
rust: Makefile.am: provide RUST_TARGET to cargo-test.py

We'll be overriding the linker parameter from the cargo-test.py script
so we need to actually forward the target we're compiling for. The
parameter has been added in previous commits.

- - - - -
9f2199a9 by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
meson: extract rust triplet on native build

This was not necessary before, but we'll use this to inject the link
configuration from the build system for tests.

- - - - -
c9dfa4d9 by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
meson: setup rust tests as meson test targets

So as to run tests, use --config overrides so that we properly define
our build folder as the build folder for tests.

Co-authored-by: Alaric Senat <alaric at videolabs.io>

- - - - -
35320bff by Alexandre Janniaux at 2026-04-04T18:17:50+02:00
vlcrs-core: lib.rs: error out on #[test] with vlccore_not_linked

cargo test -p vlcrs-core fails because the test binary needs to link
against symbols from libvlccore, more precisely they currently depend
on vlc_object_create and vlc_object_delete.

As it generates linker errors, it's not obvious that it comes from cargo
not being configured to find and link the builded libvlccore from the
build tree.

This uses the previously defined custom cfg() that is only added when
the config.toml is not providing compiler and linker arguments for the
triplet target, and instead generate a compilation error if trying to
compile the tests.

It means that cargo check continues to work properly.

- - - - -


7 changed files:

- buildsystem/cargo-test.py
- src/rust/Makefile.am
- src/rust/meson.build
- src/rust/vlcrs-core/Cargo.toml
- + src/rust/vlcrs-core/build.rs
- src/rust/vlcrs-core/meson.build
- src/rust/vlcrs-core/src/lib.rs


Changes:

=====================================
buildsystem/cargo-test.py
=====================================
@@ -18,6 +18,7 @@ parser.add_argument('--trs-file')
 parser.add_argument('--color-tests')
 parser.add_argument('--expect-failure')
 parser.add_argument('--enable-hard-errors')
+parser.add_argument('--host', required=True)
 parser.add_argument('--working-directory', default=os.getcwd())
 
 args = []
@@ -40,8 +41,16 @@ if test_name.endswith('.cargo'):
 # test_name = "::".join(args.test_name.split('.')[1:-1])
 
 import subprocess, os
-cmd = ['cargo', 'test', 
+
+lib_dir = os.environ['top_builddir'] + '/src/.libs'
+
+rust_triple = args.host
+
+cmd = ['cargo', 'test',
        '--offline', '--locked',
+       '--config', f'target.{rust_triple}.vlccore.rustc-link-lib=["vlccore"]',
+       '--config', f'target.{rust_triple}.vlccore.rustc-link-search=["{lib_dir}"]',
+       '--config', f'target.{rust_triple}.vlccore.rustc-link-arg=["-Wl,rpath,{lib_dir}"]',
        '--color', 'always' if args.color_tests == 'yes' else 'never',
        '--package', test_name,
        '--',
@@ -55,8 +64,8 @@ out = subprocess.run(
     text=True,
     close_fds=False, # Necessary for jobserver
     env=os.environ | {
-        'DYLD_LIBRARY_PATH': os.environ['top_builddir'] + '/src/.libs',
-        'LD_LIBRARY_PATH': os.environ['top_builddir'] + '/src/.libs',
+        'DYLD_LIBRARY_PATH': lib_dir,
+        'LD_LIBRARY_PATH': lib_dir,
         }
     )
 


=====================================
src/rust/Makefile.am
=====================================
@@ -1,6 +1,7 @@
 TEST_EXTENSIONS += .cargo
 CARGO_LOG_DRIVER = env top_builddir="${abs_top_builddir}" \
                    $(abs_top_srcdir)/buildsystem/cargo-test.py \
+                   --host="@RUST_TARGET@" \
                    --working-directory="${abs_top_srcdir}/src/rust/"
 
 vlcrs-core.cargo:


=====================================
src/rust/meson.build
=====================================
@@ -13,10 +13,19 @@ module_cargo_depends = []
 rust_common_link_args = []
 rust_target = []
 
+rust_triplet = ''
 if get_option('rust').enabled()
     if meson.is_cross_build()
-        rust_target = ['--target=' + meson.get_external_property('rust_triplet')]
+        rust_triplet = meson.get_external_property('rust_triplet')
+        rust_target = ['--target=' + rust_triplet]
         extra_cargo_args += rust_target
+    else
+        rustc_version = run_command('rustc', '-vV', check: true, capture: true)
+        foreach line : rustc_version.stdout().split('\n')
+            if line.startswith('host:')
+                rust_triplet = line.split('host:')[1].strip()
+            endif
+        endforeach
     endif
 
     print_static_libs_rustc = run_command(cargo_rustc_static_libs, rust_target, cargo_bin,
@@ -42,3 +51,32 @@ if get_option('rust').enabled()
 endif
 
 module_cargo_depends += [vlcrs_core, vlcrs_core_macros]
+
+if get_option('rust').enabled() and not meson.is_cross_build()
+    vlc_build_lib_dir = join_paths(meson.project_build_root(), 'src')
+
+    rust_test_env = environment()
+    rust_test_env.prepend('LD_LIBRARY_PATH', vlc_build_lib_dir)
+    rust_test_env.prepend('DYLD_LIBRARY_PATH', vlc_build_lib_dir)
+    rust_test_env.set('CARGO_TARGET_DIR', cargo_target_dir)
+
+    cargo_link_override = [
+        '--config', 'target. at 0@.vlccore.rustc-link-lib=["vlccore"]'.format(rust_triplet),
+        '--config', 'target. at 0@.vlccore.rustc-link-search=["@1@"]'.format(rust_triplet, vlc_build_lib_dir),
+        '--config', 'target. at 0@.vlccore.rustc-link-arg=["-Wl,-rpath, at 1@"]'.format(rust_triplet, vlc_build_lib_dir),
+    ]
+
+    rust_test_args = ['test', '--locked'] + extra_cargo_args + cargo_link_override + \
+        ['--manifest-path', meson.project_source_root() / 'Cargo.toml']
+
+    foreach crate : ['vlcrs-core', 'vlcrs-macros', 'vlcrs-messages', 'vlcrs-utils']
+        test('rust-' + crate,
+            cargo_bin,
+            args: rust_test_args + ['-p', crate],
+            env: rust_test_env,
+            depends: [libvlccore, vlcrs_core, vlcrs_core_macros],
+            timeout: 60,
+            suite: 'rust',
+        )
+    endforeach
+endif


=====================================
src/rust/vlcrs-core/Cargo.toml
=====================================
@@ -3,9 +3,13 @@ name = "vlcrs-core"
 edition = "2021"
 version.workspace = true
 license.workspace = true
+links = "vlccore"
 
 [dependencies]
 vlcrs-messages = { path = "../vlcrs-messages" }
 
+[lints.rust]
+unexpected_cfgs = { level = "warn", check-cfg = ['cfg(vlccore_not_linked)'] }
+
 [dev-dependencies]
 vlcrs-macros.workspace = true


=====================================
src/rust/vlcrs-core/build.rs
=====================================
@@ -0,0 +1,12 @@
+fn main() {
+    // When a build script override is provided via .cargo/config.toml
+    // or via `cargo --config`, this script is not compiled or run.
+    //
+    // Without an override, set a cfg flag so that lib.rs can fail on
+    // test compilation and produces a proper error message instead of
+    // linker failure. This is needed because we can't test for "test"
+    // configuration from the build script directly, and forcing to have
+    // the proper parameter to setup link flag here breaks cargo check
+    // even though it's not linking anyway.
+    println!("cargo::rustc-cfg=vlccore_not_linked");
+}


=====================================
src/rust/vlcrs-core/meson.build
=====================================
@@ -4,6 +4,7 @@ vlcrs_core = custom_target('vlcrs_core-cargo',
     build_by_default: true,
     input: files(
         'Cargo.toml',
+        'build.rs',
         'src/object/mod.rs',
         'src/object/sys.rs',
         'src/plugin/mod.rs',


=====================================
src/rust/vlcrs-core/src/lib.rs
=====================================
@@ -12,6 +12,13 @@
 //! If you need a vlc core C API that is not ported or wrapped yet here,
 //! then do so first instead of bypassing this crate.
 
+#[cfg(all(test, vlccore_not_linked))]
+compile_error!(
+    "vlccore is not configured for linking. \
+     Set up .cargo/config.toml with a [target.<triple>.vlccore] override or run through make check / meson test. \
+     See https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts."
+);
+
 // SPDX-License-Identifier: LGPL-2.1-or-later
 // Copyright (C) 2024 Alexandre Janniaux <ajanni at videolabs.io>
 //



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d346f1fbe6eebae170b771309d331e937bb6b4d1...35320bff96df2ef160874ff65dc3688973b1b9c3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d346f1fbe6eebae170b771309d331e937bb6b4d1...35320bff96df2ef160874ff65dc3688973b1b9c3
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list