feat: java now works

This commit is contained in:
zaaarf 2024-03-09 23:57:20 +01:00
parent 23db5af4d2
commit 71006696ee
2 changed files with 20 additions and 13 deletions

View file

@ -39,5 +39,5 @@ flapigen = { version = "0.6.0", optional = true }
rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7", optional = true } rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7", optional = true }
[features] [features]
default = ["java"] default = []
java = ["lazy_static", "jni", "jni-sys", "flapigen", "rifgen", "log"] java = ["lazy_static", "jni", "jni-sys", "flapigen", "rifgen", "log"]

View file

@ -15,10 +15,12 @@ fn main() {
.generate_interface(&generated_glue_file); .generate_interface(&generated_glue_file);
// build java source path // build java source path
let target = out_dir.parent().unwrap().parent().unwrap().parent().unwrap().to_path_buf(); let target = out_dir.parent().unwrap().parent().unwrap().parent().unwrap().to_path_buf(); // target/debug
let mut java_target = target.clone();
let mut java_target = target.clone(); // target/debug/java
java_target.push("java"); java_target.push("java");
let mut pkg_path = java_target.clone();
let mut pkg_path = java_target.clone(); // target/debug/java/src/com/codemp/intellij
pkg_path.push("src"); pkg_path.push("src");
pkg_path.push(pkg_folder); pkg_path.push(pkg_folder);
@ -38,7 +40,7 @@ fn main() {
//TODO panic if no jdk //TODO panic if no jdk
// compile java code // compile java code
let mut java_compiled = java_target.clone(); let mut java_compiled = java_target.clone(); // target/debug/java/classes
java_compiled.push("classes"); java_compiled.push("classes");
recreate_path(&java_compiled); recreate_path(&java_compiled);
@ -47,17 +49,22 @@ fn main() {
for java_file in pkg_path.read_dir().unwrap().filter_map(|e| e.ok()) { for java_file in pkg_path.read_dir().unwrap().filter_map(|e| e.ok()) {
javac_cmd.arg(java_file.path().as_os_str()); javac_cmd.arg(java_file.path().as_os_str());
} }
javac_cmd.status().expect("failed to run javac");
// jar it! FIXME // jar it!
let mut jar_file = target.clone(); let mut jar_file = target.clone(); // target/debug/codemp-java.jar
jar_file.push("codemp-java.jar"); jar_file.push("codemp-java.jar");
let mut jar_cmd = std::process::Command::new("jar"); let mut jar_cmd = std::process::Command::new("jar");
jar_cmd.arg("cf").arg(jar_file.as_os_str()); jar_cmd.current_dir(&java_compiled)
jar_cmd.arg("-C").arg(java_compiled.as_os_str()); .arg("cf")
.arg(jar_file.as_os_str());
for java_file in java_compiled.read_dir().unwrap().filter_map(|e| e.ok()) { for java_file in java_compiled.read_dir().unwrap().filter_map(|e| e.ok()) {
jar_cmd.arg(java_file.path().as_os_str()); let relative_path = java_file.path().clone();
let relative_path = relative_path.strip_prefix(&java_compiled).unwrap();
jar_cmd.arg(relative_path.as_os_str());
} }
jar_cmd.spawn().expect("failed to run jar!"); jar_cmd.status().expect("failed to run jar!");
println!("cargo:rerun-if-changed={}", generated_glue_file.display()); println!("cargo:rerun-if-changed={}", generated_glue_file.display());
} }