From 78ff40e29381c9909db07b498be9de84cd8d08c4 Mon Sep 17 00:00:00 2001 From: Joe Sorensen Date: Mon, 9 Sep 2024 12:19:18 -0600 Subject: [PATCH 1/5] fix broken release build on linux --- projectm-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projectm-sys/build.rs b/projectm-sys/build.rs index 03bba86..cb4cfb6 100644 --- a/projectm-sys/build.rs +++ b/projectm-sys/build.rs @@ -87,7 +87,7 @@ fn main() { #[cfg(target_os = "linux")] if Ok("release".to_owned()) == env::var("PROFILE") { - println!("cargo:rustc-link-lib=dylib=libprojectM=4"); + println!("cargo:rustc-link-lib=dylib=projectM-4"); #[cfg(feature = "playlist")] println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); From e5a218a35c8c2d1e4f0ff159424b6a8b2c18a635 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 13 Sep 2024 15:42:20 -0600 Subject: [PATCH 2/5] simplify build script and add static linking feature --- Cargo.toml | 9 +++-- projectm-sys/Cargo.toml | 5 ++- projectm-sys/build.rs | 88 +++++++++++++++++------------------------ 3 files changed, 45 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e05ed68..b22af3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,16 +6,17 @@ rust-version = "1.65" authors = ["AnomieVision "] description = "Bindings for ProjectM" license = " LGPL-3.0-or-later" -repository = "https://github.com/projectM-visualizer/projectm-rs" #https://github.com/anomievision/projectm-rs -keywords = ["visualization", "audio", "sound", "projectm"] +repository = "https://github.com/projectM-visualizer/projectm-rs" #https://github.com/anomievision/projectm-rs +keywords = ["visualization", "audio", "sound", "projectm"] categories = ["multimedia", "multimedia::video", "multimedia::audio"] readme = "README.md" [dependencies] libc = "0.2.147" -projectm-sys = { path = "projectm-sys", version = "1.0.8", features = ["playlist"] } +projectm-sys = { path = "projectm-sys", version = "1.0.8" } rand = "0.8.5" [features] default = ["playlist"] -playlist = [] +playlist = ["projectm-sys/playlist"] +static = ["projectm-sys/static"] diff --git a/projectm-sys/Cargo.toml b/projectm-sys/Cargo.toml index e0a54ba..a8fd6c4 100644 --- a/projectm-sys/Cargo.toml +++ b/projectm-sys/Cargo.toml @@ -8,7 +8,7 @@ description = "Bindings for ProjectM" license = "LGPL-3.0-or-later" repository = "https://github.com/anomievision/projectm-sys" documentation = "https://docs.rs/projectm-sys/latest" -keywords = ["visualization", "audio", "sound", "projectm"] +keywords = ["visualization", "audio", "sound", "projectm"] categories = ["multimedia", "multimedia::video", "multimedia::audio"] readme = "README.md" links = "projectm" @@ -22,4 +22,5 @@ lazy_static = "1.4.0" [features] default = ["playlist"] -playlist = [] \ No newline at end of file +playlist = [] +static = [] diff --git a/projectm-sys/build.rs b/projectm-sys/build.rs index cb4cfb6..7256e5f 100644 --- a/projectm-sys/build.rs +++ b/projectm-sys/build.rs @@ -28,11 +28,19 @@ fn main() { } // Feature: enable-playlist - fn enable_playlist() -> String { + fn enable_playlist() -> &'static str { if cfg!(feature = "playlist") { - "ON".to_string() + "ON" } else { - "OFF".to_string() + "OFF" + } + } + + fn enable_static_link() -> &'static str { + if cfg!(feature = "static") { + "OFF" + } else { + "ON" } } @@ -51,77 +59,55 @@ fn main() { "CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$:Debug>DLL", ) - .define("ENABLE_PLAYLIST", enable_playlist().as_str()) + .define("ENABLE_PLAYLIST", enable_playlist()) + .define("BUILD_SHARED_LIBS", enable_static_link()) .build(); #[cfg(target_os = "linux")] let dst = cmake::Config::new(PROJECTM_BUILD.as_str()) - .define("ENABLE_PLAYLIST", enable_playlist().as_str()) + .define("ENABLE_PLAYLIST", enable_playlist()) + .define("BUILD_SHARED_LIBS", enable_static_link()) .build(); #[cfg(target_os = "macos")] let dst = cmake::Config::new(PROJECTM_BUILD.as_str()) - .define("ENABLE_PLAYLIST", enable_playlist().as_str()) + .define("ENABLE_PLAYLIST", enable_playlist()) + .define("BUILD_SHARED_LIBS", enable_static_link()) .build(); #[cfg(target_os = "emscripten")] let dst = cmake::Config::new(PROJECTM_BUILD.as_str()) - .define("ENABLE_PLAYLIST", enable_playlist().as_str()) + .define("ENABLE_PLAYLIST", enable_playlist()) + .define("BUILD_SHARED_LIBS", enable_static_link()) .define("ENABLE_EMSCRIPTEN", "ON") .build(); println!("cargo:rustc-link-search=native={}/lib", dst.display()); - #[cfg(target_os = "windows")] - if Ok("release".to_owned()) == env::var("PROFILE") { - println!("cargo:rustc-link-lib=dylib=projectM-4"); - - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); - } else { - println!("cargo:rustc-link-lib=dylib=projectM-4d"); - - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); - } - - #[cfg(target_os = "linux")] if Ok("release".to_owned()) == env::var("PROFILE") { - println!("cargo:rustc-link-lib=dylib=projectM-4"); - - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); - } else { - println!("cargo:rustc-link-lib=dylib=projectM-4d"); + if cfg!(feature = "static") { + println!("cargo:rustc-link-lib=static=projectM"); - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); - } - - #[cfg(target_os = "macos")] - if Ok("release".to_owned()) == env::var("PROFILE") { - println!("cargo:rustc-link-lib=dylib=projectM-4"); + #[cfg(feature = "playlist")] + println!("cargo:rustc-link-lib=static=projectM_playlist"); + } else { + println!("cargo:rustc-link-lib=dylib=projectM-4"); - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); + #[cfg(feature = "playlist")] + println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); + } } else { - println!("cargo:rustc-link-lib=dylib=projectM-4d"); - - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); - } - - #[cfg(target_os = "emscripten")] - if Ok("release".to_owned()) == env::var("PROFILE") { - println!("cargo:rustc-link-lib=static=projectM-4"); + if cfg!(feature = "static") { + println!("cargo:rustc-link-lib=static=projectMd"); - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); - } else { - println!("cargo:rustc-link-lib=static=projectM-4d"); + #[cfg(feature = "playlist")] + println!("cargo:rustc-link-lib=static=projectM_playlistd"); + } else { + println!("cargo:rustc-link-lib=dylib=projectM-4d"); - #[cfg(feature = "playlist")] - println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); + #[cfg(feature = "playlist")] + println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); + } } bindgen() From f482024fd3424f3f8be1d6d2b55cb5fc1b68cd17 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 13 Sep 2024 16:08:51 -0600 Subject: [PATCH 3/5] add cargo config for linux --- projectm-sys/.cargo/config.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projectm-sys/.cargo/config.toml b/projectm-sys/.cargo/config.toml index 471e227..e2c3513 100644 --- a/projectm-sys/.cargo/config.toml +++ b/projectm-sys/.cargo/config.toml @@ -1,2 +1,5 @@ [target.wasm32-unknown-emscripten] linker = ".cargo/linker-emscripten" + +[target.x86_64-unknown-linux-gnu] +rustflags = "-C link-arg=-lGL -C link-arg=-lstdc++ -C link-arg=-lgomp" From fa50fd22964743d7ccd95c3761880ecdb1c31068 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 3 Nov 2024 10:13:44 -0800 Subject: [PATCH 4/5] static linking flag logic fix --- projectm-sys/build.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/projectm-sys/build.rs b/projectm-sys/build.rs index 631bf15..f922170 100644 --- a/projectm-sys/build.rs +++ b/projectm-sys/build.rs @@ -12,12 +12,12 @@ fn enable_playlist() -> &'static str { "OFF" } } - -fn enable_static_link() -> &'static str { +// Are we linking to shared or static libraries? +fn build_shared_libs_flag() -> &'static str { if cfg!(feature = "static") { - "ON" + "OFF" // Disable shared libs to enable static linking } else { - "OFF" + "ON" // Enable shared libs } } @@ -37,7 +37,7 @@ fn main() { // Determine feature flags let enable_playlist_flag = enable_playlist(); - let enable_static_flag = enable_static_link(); + let build_shared_libs = build_shared_libs_flag(); let dst; @@ -90,7 +90,7 @@ fn main() { .define("CMAKE_VERBOSE_MAKEFILE", "ON") .define("BUILD_TESTING", "OFF") .define("BUILD_EXAMPLES", "OFF") - .define("BUILD_SHARED_LIBS", enable_static_flag); // Integrated static linking option + .define("BUILD_SHARED_LIBS", build_shared_libs); // static/dynamic dst = cmake_config.build(); } else if cfg!(target_os = "emscripten") { @@ -100,7 +100,7 @@ fn main() { .define("BUILD_TESTING", "OFF") .define("BUILD_EXAMPLES", "OFF") .define("ENABLE_EMSCRIPTEN", "ON") - .define("BUILD_SHARED_LIBS", enable_static_flag) // Integrated static linking option + .define("BUILD_SHARED_LIBS", build_shared_libs) // static/dynamic .build(); } else { // Configure and build libprojectM using CMake for other platforms (Linux, macOS) @@ -108,7 +108,7 @@ fn main() { .define("ENABLE_PLAYLIST", enable_playlist_flag) .define("BUILD_TESTING", "OFF") .define("BUILD_EXAMPLES", "OFF") - .define("BUILD_SHARED_LIBS", enable_static_flag) // Integrated static linking option + .define("BUILD_SHARED_LIBS", build_shared_libs) // static/dynamic .build(); } @@ -120,7 +120,7 @@ fn main() { // Platform and feature-specific library linking if cfg!(target_os = "windows") || cfg!(target_os = "emscripten") { - // Static linking for Windows and Emscripten if the 'static' feature is enabled + // Static or Dynamic linking based on 'static' feature if cfg!(feature = "static") { if profile == "release" { println!("cargo:rustc-link-lib=static=projectM-4"); @@ -134,7 +134,6 @@ fn main() { } } } else { - // Dynamic linking if 'static' feature is not enabled if profile == "release" { println!("cargo:rustc-link-lib=dylib=projectM-4"); if cfg!(feature = "playlist") { From 844457ad6dd45acdec9e0cc82fce37b3c05877ac Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 3 Nov 2024 10:26:06 -0800 Subject: [PATCH 5/5] fix lifetimes --- Cargo.toml | 2 +- projectm-sys/Cargo.toml | 2 +- projectm-sys/build.rs | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 86233fc..b474664 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" [dependencies] libc = "0.2" #projectm-sys = { path = "projectm-sys", version = "1.0.9-rc.1", features = ["playlist"] } -projectm-sys = { version = "1.0.10" } +projectm-sys = { version = "1.1.0-alpha.1" } rand = "0.8" [features] diff --git a/projectm-sys/Cargo.toml b/projectm-sys/Cargo.toml index 992bebc..372fb50 100644 --- a/projectm-sys/Cargo.toml +++ b/projectm-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "projectm-sys" -version = "1.0.10" +version = "1.1.0-alpha.1" edition = "2021" rust-version = "1.65" authors = ["AnomieVision ", "Mischa Spiegelmock "] diff --git a/projectm-sys/build.rs b/projectm-sys/build.rs index f922170..cdc7f5f 100644 --- a/projectm-sys/build.rs +++ b/projectm-sys/build.rs @@ -12,6 +12,7 @@ fn enable_playlist() -> &'static str { "OFF" } } + // Are we linking to shared or static libraries? fn build_shared_libs_flag() -> &'static str { if cfg!(feature = "static") { @@ -71,22 +72,28 @@ fn main() { // Define the installation path for vcpkg let vcpkg_installed = vcpkg_root.join("installed").join("x64-windows-static-md"); + let vcpkg_installed_str = vcpkg_installed.to_str().unwrap(); + + // Define projectM_Eval_DIR and store in a variable + let projectm_eval_dir = projectm_path.join("vendor").join("projectm-eval"); + let projectm_eval_dir_str = projectm_eval_dir.to_str().unwrap(); + + // Convert vcpkg_toolchain to string + let vcpkg_toolchain_str = vcpkg_toolchain.to_str().unwrap(); // Configure and build libprojectM using CMake for Windows - let mut cmake_config = cmake::Config::new(&projectm_path) + let mut cmake_config = cmake::Config::new(&projectm_path); + cmake_config .generator("Visual Studio 17 2022") - .define("CMAKE_TOOLCHAIN_FILE", &vcpkg_toolchain) + .define("CMAKE_TOOLCHAIN_FILE", vcpkg_toolchain_str) .define("VCPKG_TARGET_TRIPLET", "x64-windows-static-md") .define( "CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$:Debug>DLL", ) .define("ENABLE_PLAYLIST", enable_playlist_flag) - .define( - "projectM_Eval_DIR", - &projectm_path.join("vendor").join("projectm-eval"), - ) - .define("CMAKE_PREFIX_PATH", &vcpkg_installed) + .define("projectM_Eval_DIR", projectm_eval_dir_str) + .define("CMAKE_PREFIX_PATH", vcpkg_installed_str) .define("CMAKE_VERBOSE_MAKEFILE", "ON") .define("BUILD_TESTING", "OFF") .define("BUILD_EXAMPLES", "OFF")