juicewrld-desktopsrc-tauribuild.rs
1.4.2Released Nov 21, 2026
build.rs
169 lines7.2 KBRustuse std::path::{Path, PathBuf};fn main() { // The app's own commands get permissions (allow-presence, allow-bar, ...), so each webview can call only what its // capability grants: the site `presence`, the bar's room, notifications, the like shortcut and the plugin commands, // the title bar its own two, the plugin manager its own (manager_*, capabilities/plugin-manager.json). The two bench // commands and the test action are granted only to the debug build's plugin test page (src/plugins/testpage.rs). let manifest = tauri_build::AppManifest::new().commands(&[ "presence", "bar", "bar_state", "site_under_bar", "notify", "like_shortcut_get", "like_shortcut_set", "like_notice", "plugins_status", "plugins_subscribe", "plugins_request_enable", "plugins_request_scan", "plugins_list", "plugins_unsupported", "plugins_manage", "plugins_open", "plugins_close", "plugins_editor", "plugins_get_state", "plugins_set_state", "plugins_params", "plugins_set_param", "plugins_reset", "plugins_bypass", "plugins_stream", "plugins_stream_close", "plugins_render", "plugins_bench_echo", "plugins_bench_channel", "plugins_test_action", "manager_state", "manager_subscribe", "manager_enable", "manager_scan", "manager_stop", "manager_retry", "manager_favourite", "manager_hide", "manager_folder", "manager_add_folder", "manager_remove_folder", ]); tauri_build::try_build(tauri_build::Attributes::new().app_manifest(manifest)).expect("tauri build"); plugin_host();}/// Steinberg's VST 3 SDK, the parts a host needs (MIT; host/vst3sdk holds just these and their headers).const SDK_SOURCES: &[&str] = &[ "pluginterfaces/base/coreiids.cpp", "pluginterfaces/base/funknown.cpp", "public.sdk/source/common/commoniids.cpp", "public.sdk/source/common/commonstringconvert.cpp", "public.sdk/source/common/memorystream.cpp", "public.sdk/source/common/threadchecker_win32.cpp", "public.sdk/source/vst/vstinitiids.cpp", "public.sdk/source/vst/utility/stringconvert.cpp", "public.sdk/source/vst/hosting/connectionproxy.cpp", "public.sdk/source/vst/hosting/eventlist.cpp", "public.sdk/source/vst/hosting/hostclasses.cpp", "public.sdk/source/vst/hosting/module.cpp", "public.sdk/source/vst/hosting/module_win32.cpp", "public.sdk/source/vst/hosting/parameterchanges.cpp", "public.sdk/source/vst/hosting/pluginterfacesupport.cpp", "public.sdk/source/vst/hosting/processdata.cpp",];/// The plugin host's C++: the shim and the SDK under it, linked into juicewrld-plugins.exe (the app's own binary/// references none of it, so none of it ends up there). In debug builds also the test plugin the tests load.fn plugin_host() { let sdk = Path::new("host/vst3sdk"); println!("cargo:rerun-if-changed=host/shim"); println!("cargo:rerun-if-changed=host/testplug"); println!("cargo:rerun-if-changed=host/vst3sdk"); let mut build = cc::Build::new(); configure(&mut build, sdk); for s in SDK_SOURCES { build.file(sdk.join(s)); } build.file("host/shim/jwvst3.cpp"); build.compile("jwvst3"); if std::env::var("PROFILE").as_deref() == Ok("debug") { test_plugin(sdk); test_dlls(); }}/// host/testplug/jwtestdll.c as five tiny DLLs for the scan's tests, never shipped and never loaded (the scan reads/// their headers): 64-bit ones exporting VSTPluginMain, main, or nothing a plugin exports, and 32-bit ones exporting/// VSTPluginMain or GetPluginFactory. A PC without the 32-bit compiler gets a warning, and the tests skip those two.fn test_dlls() { let out = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR")).join("testdlls"); let _ = std::fs::create_dir_all(&out); let host = std::env::var("HOST").unwrap_or_else(|_| "x86_64-pc-windows-msvc".into()); let x64 = "x86_64-pc-windows-msvc"; let x86 = "i686-pc-windows-msvc"; for (name, target, define) in [ ("vst2-x64", x64, "JW_VST2"), ("vst2main-x64", x64, "JW_VST2_MAIN"), ("helper-x64", x64, "JW_HELPER"), ("vst2-x86", x86, "JW_VST2"), ("vst3-x86", x86, "JW_VST3"), ] { let tool = cc::Build::new().target(target).host(&host).opt_level(1).debug(false).cargo_metadata(false).warnings(false).try_get_compiler(); let Ok(tool) = tool else { println!("cargo:warning=no {target} C compiler: the scan's {name} test DLL isn't built"); continue; }; let mut cmd = tool.to_command(); cmd.arg("/nologo").arg("/LD").arg("/O1").arg("/GS-").arg(format!("/D{define}")); cmd.arg(format!("/Fo:{}", out.join(format!("{name}.obj")).display())).arg(format!("/Fe:{}", out.join(format!("{name}.dll")).display())); cmd.arg("host/testplug/jwtestdll.c").arg("/link").arg("/NOENTRY").arg("/NODEFAULTLIB"); match cmd.output() { Ok(o) if o.status.success() => {} Ok(o) => println!("cargo:warning=the scan's {name} test DLL didn't build: {}", String::from_utf8_lossy(&o.stdout).lines().last().unwrap_or("")), Err(e) => println!("cargo:warning=the scan's {name} test DLL didn't build: {e}"), } } println!("cargo:rustc-env=JW_TEST_DLLS={}", out.display());}fn configure(build: &mut cc::Build, sdk: &Path) { build .cpp(true) .std("c++17") // The C++ library statically, the C runtime from Windows (UCRT): the hybrid CRT tauri-build links the app // with, so neither exe needs a Visual C++ redistributable. .static_crt(true) .warnings(false) .include(sdk) .include("host/shim") .define("UNICODE", None) .define("_UNICODE", None) .define("NOMINMAX", None) .define("RELEASE", "1") .flag("/EHsc") .flag("/utf-8");}/// host/testplug as a VST 3 module (a DLL), for the tests and the debug test page; never shipped.fn test_plugin(sdk: &Path) { let out = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR")); let objs = out.join("testplug-obj"); let _ = std::fs::create_dir_all(&objs); let dll = out.join("jwtestplug.dll"); let mut build = cc::Build::new(); configure(&mut build, sdk); let mut cmd = build.get_compiler().to_command(); cmd.arg("/LD").arg("/O2").arg(format!("/Fo:{}\\", objs.display())).arg(format!("/Fe:{}", dll.display())); cmd.arg(format!("/I{}", sdk.display())); for flag in ["/DUNICODE", "/D_UNICODE", "/DNOMINMAX", "/DRELEASE=1", "/EHsc", "/utf-8", "/std:c++17"] { cmd.arg(flag); } cmd.arg("host/testplug/jwtestplug.cpp"); for s in ["pluginterfaces/base/coreiids.cpp", "pluginterfaces/base/funknown.cpp", "public.sdk/source/vst/vstinitiids.cpp", "public.sdk/source/common/commoniids.cpp"] { cmd.arg(sdk.join(s)); } let status = cmd.status().expect("the compiler for the test plugin"); assert!(status.success(), "the test plugin didn't build"); println!("cargo:rustc-env=JW_TEST_PLUGIN={}", dll.display());}