Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Simplify build using java-locator #21

Open
wants to merge 1 commit into
base: hadoop-2.7.3
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use_existing_hdfs = []
[build-dependencies]
cc = "1.0"
bindgen = "0.64.0"
java-locator = { version = "0.1.9", features = ["locate-jdk-only"] }

[dependencies]
lazy_static = "^1.4"
Expand Down
41 changes: 15 additions & 26 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,21 @@ fn get_build_flags() -> Vec<String> {
fn get_java_dependency() -> Vec<String> {
let mut result = vec![];

match env::var("JAVA_HOME") {
Ok(val) => {
result.push(format!("-I{}/include", val));
if cfg!(target_os = "linux") {
result.push(format!("-I{}/include/linux", val));
// for openjdk 8
println!(
"cargo:rustc-link-search=native={}/jre/lib/amd64/server",
val
);
// for openjdk 11, etc.
println!("cargo:rustc-link-search=native={}/lib/server", val)
} else if cfg!(target_os = "macos") {
result.push(format!("-I{}/include/darwin", val));
// for openjdk 8
println!("cargo:rustc-link-search=native={}/jre/lib/server", val);
// for openjdk 11, etc.
println!("cargo:rustc-link-search=native={}/lib/server", val);
}
// Tell cargo to tell rustc to link the system jvm shared library.
println!("cargo:rustc-link-lib=jvm");
}
Err(e) => {
panic!("JAVA_HOME shell environment must be set: {}", e);
}
}
// Include directories
let java_home = java_locator::locate_java_home()
.expect("JAVA_HOME could not be found, trying setting the variable manually");
result.push(format!("-I{java_home}/include"));
#[cfg(target_os = "linux")]
result.push(format!("-I{java_home}/include/linux"));

// libjvm link
let jvm_lib_location = java_locator::locate_jvm_dyn_library().unwrap();
println!("cargo:rustc-link-search=native={}", jvm_lib_location);
println!("cargo:rustc-link-lib=jvm");

// For tests, add libjvm path to rpath, this does not propagate upwards,
// unless building an .so, as per Cargo specs, so is only used when testing
println!("cargo:rustc-link-arg=-Wl,-rpath,{jvm_lib_location}");

result
}
Expand Down