diff --git a/Cargo.toml b/Cargo.toml index 9dc90ce..b474664 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,10 @@ 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] default = ["playlist"] -playlist = ["projectm-sys/playlist"] \ No newline at end of file +playlist = ["projectm-sys/playlist"] +static = ["projectm-sys/static"] 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" diff --git a/projectm-sys/Cargo.toml b/projectm-sys/Cargo.toml index 54a1eda..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 "] @@ -47,3 +47,5 @@ lazy_static = "1.4.0" [features] default = ["playlist"] playlist = [] +static = [] + diff --git a/projectm-sys/build.rs b/projectm-sys/build.rs index 43d20ee..cdc7f5f 100644 --- a/projectm-sys/build.rs +++ b/projectm-sys/build.rs @@ -4,11 +4,29 @@ use std::path::PathBuf; mod build_bindgen; use crate::build_bindgen::bindgen; +// Functions to determine feature flags +fn enable_playlist() -> &'static str { + if cfg!(feature = "playlist") { + "ON" + } else { + "OFF" + } +} + +// Are we linking to shared or static libraries? +fn build_shared_libs_flag() -> &'static str { + if cfg!(feature = "static") { + "OFF" // Disable shared libs to enable static linking + } else { + "ON" // Enable shared libs + } +} + fn main() { - // Get the path to the projectM source code + // Path to the projectM source code let projectm_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("libprojectM"); - // Check if the libprojectM source code exists + // Verify the existence of the libprojectM directory if !projectm_path.exists() { println!("cargo:warning=The libprojectM source code is missing."); println!( @@ -18,16 +36,13 @@ fn main() { std::process::exit(1); } - // Determine if the 'playlist' feature is enabled - let enable_playlist = if cfg!(feature = "playlist") { - "ON" - } else { - "OFF" - }; + // Determine feature flags + let enable_playlist_flag = enable_playlist(); + let build_shared_libs = build_shared_libs_flag(); let dst; - // Platform-specific configurations + // Platform-specific CMake configurations if cfg!(target_os = "windows") { // Ensure VCPKG installation root is set let vcpkg_root = match env::var("VCPKG_INSTALLATION_ROOT") { @@ -55,80 +70,118 @@ fn main() { // Set VCPKG_ROOT for CMake env::set_var("VCPKG_ROOT", &vcpkg_root); - // Optionally set CMAKE_PREFIX_PATH + // 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 - dst = 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) - .define( - "projectM_Eval_DIR", - &projectm_path.join("vendor").join("projectm-eval"), - ) - .define("CMAKE_PREFIX_PATH", &vcpkg_installed) + .define("ENABLE_PLAYLIST", enable_playlist_flag) + .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") - .build(); + .define("BUILD_SHARED_LIBS", build_shared_libs); // static/dynamic + + dst = cmake_config.build(); } else if cfg!(target_os = "emscripten") { // Configure and build libprojectM using CMake for Emscripten dst = cmake::Config::new(&projectm_path) - .define("ENABLE_PLAYLIST", enable_playlist) + .define("ENABLE_PLAYLIST", enable_playlist_flag) .define("BUILD_TESTING", "OFF") .define("BUILD_EXAMPLES", "OFF") .define("ENABLE_EMSCRIPTEN", "ON") + .define("BUILD_SHARED_LIBS", build_shared_libs) // static/dynamic .build(); } else { - // Configure and build libprojectM using CMake for other platforms + // Configure and build libprojectM using CMake for other platforms (Linux, macOS) dst = cmake::Config::new(&projectm_path) - .define("ENABLE_PLAYLIST", enable_playlist) + .define("ENABLE_PLAYLIST", enable_playlist_flag) .define("BUILD_TESTING", "OFF") .define("BUILD_EXAMPLES", "OFF") + .define("BUILD_SHARED_LIBS", build_shared_libs) // static/dynamic .build(); } // Specify the library search path println!("cargo:rustc-link-search=native={}/lib", dst.display()); - // Determine the library name based on the build profile + // Determine the build profile (release or debug) let profile = env::var("PROFILE").unwrap_or_else(|_| "release".to_string()); - // Platform-specific library linking + // Platform and feature-specific library linking if cfg!(target_os = "windows") || cfg!(target_os = "emscripten") { - // Use static linking for Windows and Emscripten - if profile == "release" { - println!("cargo:rustc-link-lib=static=projectM-4"); - if cfg!(feature = "playlist") { - println!("cargo:rustc-link-lib=static=projectM-4-playlist"); + // Static or Dynamic linking based on 'static' feature + if cfg!(feature = "static") { + if profile == "release" { + println!("cargo:rustc-link-lib=static=projectM-4"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=static=projectM-4-playlist"); + } + } else { + println!("cargo:rustc-link-lib=static=projectM-4d"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=static=projectM-4-playlistd"); + } } } else { - println!("cargo:rustc-link-lib=static=projectM-4d"); - if cfg!(feature = "playlist") { - println!("cargo:rustc-link-lib=static=projectM-4-playlistd"); + if profile == "release" { + println!("cargo:rustc-link-lib=dylib=projectM-4"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); + } + } else { + println!("cargo:rustc-link-lib=dylib=projectM-4d"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); + } } } } else { - // Use dynamic linking for other platforms (Linux, macOS) - if profile == "release" { - println!("cargo:rustc-link-lib=dylib=projectM-4"); - if cfg!(feature = "playlist") { - println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); + // For other platforms (Linux, macOS) + if cfg!(feature = "static") { + if profile == "release" { + println!("cargo:rustc-link-lib=static=projectM-4"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=static=projectM-4-playlist"); + } + } else { + println!("cargo:rustc-link-lib=static=projectM-4d"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=static=projectM-4-playlistd"); + } } } else { - println!("cargo:rustc-link-lib=dylib=projectM-4d"); - if cfg!(feature = "playlist") { - println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); + if profile == "release" { + println!("cargo:rustc-link-lib=dylib=projectM-4"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=dylib=projectM-4-playlist"); + } + } else { + println!("cargo:rustc-link-lib=dylib=projectM-4d"); + if cfg!(feature = "playlist") { + println!("cargo:rustc-link-lib=dylib=projectM-4-playlistd"); + } } } } - // Run bindgen to generate Rust bindings + // Generate Rust bindings using bindgen bindgen(); -} +} \ No newline at end of file