Skip to content

Commit

Permalink
Use git submodule reference to libprojectM
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Mar 10, 2024
1 parent e55bd80 commit 72c5a8b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "projectm-sys/libprojectM"]
path = projectm-sys/libprojectM
url = https://github.com/projectM-visualizer/projectm.git
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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.1.0", features = ["playlist"] }
rand = "0.8.5"

[features]
Expand Down
10 changes: 5 additions & 5 deletions projectm-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "projectm-sys"
version = "1.0.8"
version = "1.1.0"
edition = "2021"
rust-version = "1.65"
authors = ["AnomieVision <anomievision@gmail.com.com>"]
authors = ["AnomieVision <anomievision@gmail.com.com>", "Mischa Spiegelmock <me@mish.dev>"]
description = "Bindings for ProjectM"
license = "LGPL-3.0-or-later"
repository = "https://github.com/anomievision/projectm-sys"
repository = "https://github.com/projectM-visualizer/projectm-rs"
documentation = "https://docs.rs/projectm-sys/latest"
keywords = ["visualization", "audio", "sound", "projectm"]
categories = ["multimedia", "multimedia::video", "multimedia::audio"]
Expand All @@ -17,9 +17,9 @@ links = "projectm"

[build-dependencies]
cmake = "0.1.50"
bindgen = "0.66.1"
bindgen = "0.69.4"
lazy_static = "1.4.0"

[features]
default = ["playlist"]
playlist = []
playlist = []
57 changes: 35 additions & 22 deletions projectm-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
#[macro_use]
extern crate lazy_static;

use std::{env, path::Path, process::Command};
use lazy_static::lazy_static;
use std::env;
use std::path::PathBuf;
use std::process::{Command, Stdio};

mod build_bindgen;
use crate::build_bindgen::bindgen;

lazy_static! {
static ref PROJECTM_BUILD: String = format!("{}/projectm", env::var("OUT_DIR").unwrap());
fn update_submodules() -> Result<(), Box<dyn std::error::Error>> {
let status = Command::new("git")
.args(["submodule", "update", "--init", "--recursive"])
.stdout(Stdio::inherit()) // Optionally output stdout/stderr to help with debugging
.stderr(Stdio::inherit())
.status()?;

if !status.success() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
"Submodule update failed",
)));
}

Ok(())
}

fn main() {
if !Path::new(PROJECTM_BUILD.as_str()).exists() {
let _ = Command::new("git")
.args([
"-c",
"advice.detachedHead=false",
"clone",
"--recurse-submodules",
"--depth=1",
"--branch",
"v4.0.0",
"https://github.com/projectM-visualizer/projectm.git",
&PROJECTM_BUILD,
])
.status();
let projectm_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("libprojectM");

// Ensure the submodule is updated and initialized
if !projectm_path.exists() {
println!("cargo:warning=The libprojectM submodule is not checked out. Please run 'git submodule update --init --recursive' and try building again.");
std::process::exit(1);
}

// Attempt to update and initialize submodules recursively
if let Err(e) = update_submodules() {
println!("cargo:warning=Failed to update submodules: {}", e);
std::process::exit(1);
}

// Feature: enable-playlist
Expand All @@ -37,7 +50,7 @@ fn main() {
}

#[cfg(target_os = "windows")]
let dst = cmake::Config::new(PROJECTM_BUILD.as_str())
let dst = cmake::Config::new(&*projectm_path)
.generator("Visual Studio 17 2022")
.define(
"CMAKE_TOOLCHAIN_FILE",
Expand All @@ -55,17 +68,17 @@ fn main() {
.build();

#[cfg(target_os = "linux")]
let dst = cmake::Config::new(PROJECTM_BUILD.as_str())
let dst = cmake::Config::new(&*projectm_path)
.define("ENABLE_PLAYLIST", enable_playlist().as_str())
.build();

#[cfg(target_os = "macos")]
let dst = cmake::Config::new(PROJECTM_BUILD.as_str())
let dst = cmake::Config::new(&*projectm_path)
.define("ENABLE_PLAYLIST", enable_playlist().as_str())
.build();

#[cfg(target_os = "emscripten")]
let dst = cmake::Config::new(PROJECTM_BUILD.as_str())
let dst = cmake::Config::new(&*projectm_path)
.define("ENABLE_PLAYLIST", enable_playlist().as_str())
.define("ENABLE_EMSCRIPTEN", "ON")
.build();
Expand Down
1 change: 1 addition & 0 deletions projectm-sys/libprojectM
Submodule libprojectM added at 50c64d

0 comments on commit 72c5a8b

Please sign in to comment.