clap_wrapper/
lib.rs

1#![doc = include_str!("../README.md")]
2
3/// Exports an AUv2 entrypoint named `GetPluginFactoryAUV2` that wraps a global CLAP entrypoint (`clap_entry`) exported from the resulting shared library.
4/// Currently it only reexports the first plugin available through the CLAP entrypoint, but this limitation might be lifted in the future.
5///
6/// Failure to export a CLAP entrypoint might result in linker errors or missing symbols.
7#[macro_export]
8macro_rules! export_vst3 {
9    () => {
10        #[allow(unused_imports)]
11        pub use $crate::vst3::*;
12    };
13}
14
15/// Exports a VST3 entrypoint named `GetPluginFactory` that wraps a global CLAP entrypoint (`clap_entry`) exported from the resulting shared library.
16///
17/// Failure to export a CLAP entrypoint might result in linker errors or missing symbols.
18#[macro_export]
19macro_rules! export_auv2 {
20    () => {
21        #[allow(unused_imports)]
22        pub use $crate::auv2::*;
23    };
24}
25
26#[cfg(all(target_os = "macos", feature = "auv2"))]
27#[doc(hidden)]
28pub mod auv2 {
29    #[link(name = "clap_wrapper_auv2")]
30    unsafe extern "C" {
31        pub unsafe fn wrapAsAUV2_inst0Factory(
32            desc: *const core::ffi::c_void,
33        ) -> *mut core::ffi::c_void;
34    }
35
36    #[unsafe(no_mangle)]
37    pub unsafe extern "C" fn GetPluginFactoryAUV2(
38        desc: *const core::ffi::c_void,
39    ) -> *mut core::ffi::c_void {
40        unsafe { wrapAsAUV2_inst0Factory(desc) }
41    }
42}
43
44#[cfg(not(all(target_os = "macos", feature = "auv2")))]
45#[doc(hidden)]
46pub mod auv2 {}
47
48#[cfg(feature = "vst3")]
49#[doc(hidden)]
50pub mod vst3 {
51    #[link(name = "clap_wrapper_vst3")]
52    unsafe extern "system" {
53        unsafe fn clap_wrapper_GetPluginFactory() -> *mut core::ffi::c_void;
54    }
55
56    #[link(name = "clap_wrapper_vst3")]
57    #[cfg(all(target_family = "unix", not(target_os = "macos")))]
58    unsafe extern "C" {
59        unsafe fn clap_wrapper_ModuleEntry(lib_module: *mut core::ffi::c_void) -> bool;
60        unsafe fn clap_wrapper_ModuleExit() -> bool;
61    }
62
63    #[link(name = "clap_wrapper_vst3")]
64    #[cfg(target_os = "macos")]
65    unsafe extern "C" {
66        unsafe fn clap_wrapper_bundleEntry(lib_module: *mut core::ffi::c_void) -> bool;
67        unsafe fn clap_wrapper_bundleExit() -> bool;
68    }
69
70    #[link(name = "clap_wrapper_vst3")]
71    #[cfg(target_os = "windows")]
72    unsafe extern "system" {
73        unsafe fn clap_wrapper_InitDll() -> bool;
74        unsafe fn clap_wrapper_ExitDll() -> bool;
75    }
76
77    #[unsafe(no_mangle)]
78    pub extern "system" fn GetPluginFactory() -> *mut core::ffi::c_void {
79        unsafe { clap_wrapper_GetPluginFactory() }
80    }
81
82    #[unsafe(no_mangle)]
83    #[cfg(all(target_family = "unix", not(target_os = "macos")))]
84    pub extern "C" fn ModuleEntry(lib_module: *mut core::ffi::c_void) -> bool {
85        unsafe { clap_wrapper_ModuleEntry(lib_module) }
86    }
87
88    #[unsafe(no_mangle)]
89    #[cfg(all(target_family = "unix", not(target_os = "macos")))]
90    pub extern "C" fn ModuleExit() -> bool {
91        unsafe { clap_wrapper_ModuleExit() }
92    }
93
94    #[unsafe(no_mangle)]
95    #[cfg(target_os = "macos")]
96    pub extern "C" fn bundleEntry(lib_module: *mut core::ffi::c_void) -> bool {
97        unsafe { clap_wrapper_bundleEntry(lib_module) }
98    }
99
100    #[unsafe(no_mangle)]
101    #[cfg(target_os = "macos")]
102    pub extern "C" fn bundleExit() -> bool {
103        unsafe { clap_wrapper_bundleExit() }
104    }
105
106    #[unsafe(no_mangle)]
107    #[cfg(target_os = "windows")]
108    pub extern "system" fn InitDll() -> bool {
109        unsafe { clap_wrapper_InitDll() }
110    }
111
112    #[unsafe(no_mangle)]
113    #[cfg(target_os = "windows")]
114    pub extern "system" fn ExitDll() -> bool {
115        unsafe { clap_wrapper_ExitDll() }
116    }
117}
118
119#[cfg(not(feature = "vst3"))]
120#[doc(hidden)]
121pub mod vst3 {}