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