Skip to content

Commit 691b91f

Browse files
committed
build: move dsp56300 meson.build to packagefiles
The cross-compilation and platform-specific configuration is specific to xemu's build environment. Use Meson's patch_directory mechanism to overlay the xemu-specific meson.build onto the upstream source.
1 parent 429183a commit 691b91f

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

subprojects/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ genconfig
3939
curl-*
4040
json-*
4141
SDL3-*
42-
dsp56300
42+
/dsp56300

subprojects/dsp56300.wrap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
url=https://github.com/mborgerson/dsp56300
33
revision=main
44
depth=1
5+
patch_directory=dsp56300
56

67
[provide]
78
dsp56300-emu-ffi=dsp56300_dep
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
project('dsp56300', version: '0.1.0')
2+
3+
dsp56300_src = meson.current_source_dir()
4+
5+
# Determine Rust target triple for cross-compilation.
6+
# Map Meson's host_machine to Rust target triples.
7+
host_cpu = host_machine.cpu_family()
8+
host_os = host_machine.system()
9+
10+
if host_os == 'darwin'
11+
if host_cpu == 'aarch64'
12+
rust_target = 'aarch64-apple-darwin'
13+
else
14+
rust_target = 'x86_64-apple-darwin'
15+
endif
16+
elif host_os == 'windows'
17+
if host_cpu == 'aarch64'
18+
rust_target = 'aarch64-pc-windows-gnullvm'
19+
else
20+
rust_target = 'x86_64-pc-windows-gnu'
21+
endif
22+
elif host_os == 'linux'
23+
if host_cpu == 'aarch64'
24+
rust_target = 'aarch64-unknown-linux-gnu'
25+
else
26+
rust_target = 'x86_64-unknown-linux-gnu'
27+
endif
28+
else
29+
error('Unsupported host OS: ' + host_os)
30+
endif
31+
32+
# GNU/LLVM targets always produce .a; only MSVC would produce .lib.
33+
lib_name = 'libdsp56300_emu_ffi.a'
34+
35+
cargo_target_dir = dsp56300_src / 'target' / rust_target / 'release'
36+
37+
dsp56300_lib = custom_target(
38+
'dsp56300_emu_ffi',
39+
command: [
40+
'sh', '-c',
41+
'cargo build --release -p dsp56300-emu-ffi --no-default-features --target "$1" --manifest-path "$2/Cargo.toml" && cp "$3/$4" "$5"',
42+
'--', rust_target, dsp56300_src, cargo_target_dir, lib_name, '@OUTPUT@'
43+
],
44+
output: lib_name,
45+
build_by_default: true,
46+
build_always_stale: true,
47+
console: true,
48+
)
49+
50+
# System libraries needed by the Rust staticlib.
51+
system_link_args = [dsp56300_lib.full_path()]
52+
if host_os == 'linux'
53+
system_link_args += ['-lpthread', '-ldl', '-lm']
54+
elif host_os == 'darwin'
55+
system_link_args += ['-lpthread', '-lm', '-framework', 'Security']
56+
elif host_os == 'windows'
57+
system_link_args += ['-lbcrypt', '-lntdll', '-luserenv', '-lws2_32']
58+
endif
59+
60+
dsp56300_dep = declare_dependency(
61+
sources: dsp56300_lib,
62+
link_args: system_link_args,
63+
include_directories: include_directories('crates/emu-ffi/include'),
64+
)
65+
66+
meson.override_dependency('dsp56300-emu-ffi', dsp56300_dep)

0 commit comments

Comments
 (0)