Skip to content

Commit

Permalink
build: fix build script to run tika-native gradle build inside OUT_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
nmammeri committed Sep 11, 2024
1 parent fb09b37 commit 474c95b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions extractous-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ use std::path::{Path, PathBuf};
use std::process::Command;

fn main() {
// Main build output directory
let out_dir = env::var("OUT_DIR").map(PathBuf::from).unwrap();
let jdk_install_dir = out_dir.join("graalvm-jdk"); // jdk install dir if no JAVA_HOME is set
let libs_out_dir = out_dir.join("libs"); // Directory to copy the built shared library to

// Set tika_native source directory and python bindings directory
let root_dir = env::var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap();
let tika_native_dir = root_dir.join("tika-native");
let tika_native_source_dir = root_dir.join("tika-native");
// canonicalize does not work on Windows because it returns UNC paths
//let python_bind_dir = fs::canonicalize("../bindings/extractous-python/python/extractous").unwrap();
let python_bind_dir = root_dir.join("../bindings/extractous-python/python/extractous");

// Use JAVA_HOME to find or install GraalVM JDK
// Main build output directory
let out_dir = env::var("OUT_DIR").map(PathBuf::from).unwrap();
let jdk_install_dir = out_dir.join("graalvm-jdk"); // out_dir subdir where jdk is downloaded
let libs_out_dir = out_dir.join("libs"); // out_dir subdir to copy the built libs to
let tika_native_dir = out_dir.join("tika-native"); // out_dir subdir where the gradle build is run

// Try to find a GraalVM JDK or install one if not found
let graalvm_home = get_graalvm_home(&jdk_install_dir);

// Because build script are not allowed to change files outside of OUT_DIR
// we need to copy the tika-native source directory to OUT_DIR and call gradle build there
fs_extra::dir::copy(&tika_native_source_dir, &out_dir, &fs_extra::dir::CopyOptions::new())
.expect("Failed to copy tika-native source to OUT_DIR");

// Just for debugging
// let graal_home = env::var("GRAALVM_HOME");
// let java_home = env::var("JAVA_HOME");
Expand All @@ -29,6 +35,7 @@ fn main() {
// println!("cargo:warning=out_dir: {}", out_dir.display());
//println!("cargo:warning=tika_native_dir: {:?}", tika_native_dir);

// Launch the gradle build
gradle_build(
&graalvm_home,
&tika_native_dir,
Expand Down

0 comments on commit 474c95b

Please sign in to comment.