From ab66bba43bb6f8e30462580168018d11f9ce653b Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Sat, 16 Mar 2024 02:23:21 -0700 Subject: [PATCH] Build C versions of dav1d tools and tests against librav1d Closes #803. Can be toggled on off via the test_rust meson configuration option. --- meson.build | 20 ++++++++++++++++++++ tests/meson.build | 21 ++++----------------- tools/meson.build | 6 +++++- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index 11eda46e2..b3140fe45 100644 --- a/meson.build +++ b/meson.build @@ -472,7 +472,27 @@ endif # Generate config.h config_h_target = configure_file(output: 'config.h', configuration: cdata) +# Use --out-dir instead of --target-dir to fully control where librav1d.a goes. +# Using --target-dir would put it in a subdirectory. The --out-dir option is +# currently unstable so we need to tell cargo to enable those. +# FIXME: this will only work if the host matches the build target. +cargo_command = [ + 'cargo', 'build', '--lib', + '-Z', 'unstable-options', + '--out-dir', meson.current_build_dir() +] +if get_option('buildtype') == 'release' + cargo_command += ['--release'] +endif +librav1d = custom_target( + 'librav1d', + output: 'librav1d.a', + input: ['lib.rs'], + command: cargo_command, + install: true, + install_dir: get_option('libdir') +) # # Include subdir meson.build files diff --git a/tests/meson.build b/tests/meson.build index 4ef7d03e7..606f7e275 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -135,7 +135,7 @@ if get_option('enable_tools') dav1d_input_objs.extract_objects('input/input.c', 'input/ivf.c'), ], include_directories: [dav1d_inc_dirs, include_directories('../tools')], - link_with: libdav1d, + link_with: get_option('test_rust') ? librav1d : libdav1d, dependencies: [ thread_dependency, rt_dependency, @@ -149,22 +149,9 @@ if get_option('test_rust') test_rust_path = get_option('test_rust_path') seek_stress_test_rust_path = get_option('seek_stress_test_rust_path') - # HACK: If we're trying to test the Rust build, override the `dav1d` and - # `seek_stress` executables to point to the versions produced by Cargo. - # This will test the Rust executables instead of the C versions. - if test_rust_path == '' - if get_option('debug') - profile = 'debug' - else - profile = 'release' - endif - test_rust_path = '../target/' + profile + '/dav1d' - test_rust_path = join_paths(meson.current_source_dir(), test_rust_path) - dav1d = find_program(test_rust_path, required: true) - seek_stress_test_rust_path = '../target/' + profile + '/seek_stress' - seek_stress_test_rust_path = join_paths(meson.current_source_dir(), seek_stress_test_rust_path) - seek_stress = find_program(seek_stress_test_rust_path, required: true) - else + # We're trying to test the Rust build, override the `dav1d` and + # `seek_stress` executables to point to the versions given during setup. + if test_rust_path != '' # Adjust relative paths so one can use binary paths relative to project # top dir rather than relative to the location of the test subdirectory. dav1d = files(join_paths('../', get_option('test_rust_path'))) diff --git a/tools/meson.build b/tools/meson.build index 59b145828..e32eac480 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -111,7 +111,11 @@ dav1d = executable('dav1d', dav1d_rc_obj, rev_target, cli_config_h_target, - link_with : [libdav1d, dav1d_input_objs, dav1d_output_objs], + link_with : [ + get_option('test_rust') ? librav1d : libdav1d, + dav1d_input_objs, + dav1d_output_objs + ], include_directories : [dav1d_inc_dirs], dependencies : [ getopt_dependency,