Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #29 from treyzania/master
Browse files Browse the repository at this point in the history
Made the build script more flexible across different platforms.
  • Loading branch information
kud1ing committed Nov 23, 2017
2 parents becb4bb + 4c2bd12 commit fe0c731
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
Empty file modified LICENSE-APACHE 100755 → 100644
Empty file.
Empty file modified LICENSE-MIT 100755 → 100644
Empty file.
52 changes: 44 additions & 8 deletions build.rs
@@ -1,19 +1,55 @@
use std::env;

#[cfg(target_os = "linux")]
fn find_default_java_home() -> String {
String::from("/usr/lib/jvm/default-java") // This might just be Debian, not sure.
}

#[cfg(target_os = "macos")]
fn find_default_java_home() -> String {
/*
* FIXME Find version dynamically.
* Use: /usr/libexec/java_home -v 1.8
*
* Someone that uses macOS should figure this out.
*/
String::from("/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home")
}

#[cfg(target_os = "windows")]
fn find_default_java_home() -> String {
/*
* Windows is silly about how it handles programs. 32-bit programs install to
* `Program Files (x86)` on 64-bit machines, but programs that match bitness install to the
* normal `Program Files` directory.
*
* Someone that actually uses Windows should figure this out.
*/
String::from("C:\\Program Files\\Java\\jre8") // FIXME Find version dynamically.
}

fn main() {

// Try to determine the Java home directory so that we can link to `libjvm`.
let java_home =
env::var("JAVA_HOME")
.ok()
.unwrap_or("/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home".to_string());
let java_home = env::var("JAVA_HOME").ok().unwrap_or(find_default_java_home());

// I don't have this on my machine, so I'm not 100% sure what it does.
print!("cargo:rustc-link-search=native=");
println!("{}/jre/lib/server", java_home);

print!("cargo:rustc-link-search=native=");
println!("{}/jre/lib/amd64/server", java_home);
if cfg!(target_arch = "x86_64") {
print!("cargo:rustc-link-search=native=");
println!("{}/jre/lib/amd64/server", java_home);
} else if cfg!(target_arch = "x86") {
print!("cargo:rustc-link-search=native=");
println!("{}/jre/lib/i386/server", java_home);
} else {
panic!("rucaja is not currently supported on your architecture")
}

/*
* We still need to do annoying things like setting LD_LIBRARY_PATH when we run the executable.
* It might be better to determine all this at runtime after all.
*/

print!("cargo:rustc-link-search=native=");
println!("{}/jre/lib/i386/server", java_home);
}

0 comments on commit fe0c731

Please sign in to comment.