Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions lsl-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
use std::env;
use std::path::Path;

fn main() {
// TODO: find out if liblsl already present on system and usable (if so, link to that instead)
// println!("cargo:warning={}", "rebuilding...");
// Check for system liblsl
if link_to_system_liblsl() {
return;
}

println!("cargo:warning={}", "rebuilding...");
build_liblsl();
}

// Try to link to a system-installed dynamic liblsl
fn link_to_system_liblsl() -> bool {
// If lsl path set with environment variable
if let Ok(lib_path) = env::var("LIBLSL_LIB_DIR") {
println!("cargo:rustc-link-search=native={}", lib_path);
println!("cargo:rustc-link-lib=dylib=lsl");
println!("liblsl at {}", lib_path);
return true;
}

// Check homebrew path on macOS
#[cfg(target_os = "macos")]
{
if let Ok(homebrew) = env::var("HOMEBREW_PREFIX") {
let path = &format!("{}/lib", homebrew);
let lib_file = Path::new(path).join("liblsl.dylib");
if lib_file.exists() {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-lib=dylib=lsl");
println!("liblsl at {}", lib_file.display());
return true;
}
}
}
// TODO: automatic finding for Linux and Windows
// Fallback to building from source
false
}

// Build the liblsl library from source using cmake
fn build_liblsl() {
let target = env::var("TARGET").unwrap();
Expand Down