From 474c95bb0fcf997df9c88c47624658b086bc3719 Mon Sep 17 00:00:00 2001 From: nmammeri Date: Wed, 11 Sep 2024 15:09:34 +0200 Subject: [PATCH] build: fix build script to run tika-native gradle build inside OUT_DIR --- extractous-core/build.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/extractous-core/build.rs b/extractous-core/build.rs index 2336b4a..72c5b1e 100644 --- a/extractous-core/build.rs +++ b/extractous-core/build.rs @@ -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"); @@ -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,