mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
feat: added python glue, still needs some tweaking in the building of the dylib
This commit is contained in:
parent
f0003f04bd
commit
13a4163d1e
3 changed files with 44 additions and 14 deletions
|
@ -44,12 +44,17 @@ rmpv = { version = "1", optional = true }
|
|||
napi = { version = "2", features = ["full"], optional = true }
|
||||
napi-derive = { version="2", optional = true}
|
||||
futures = { version = "0.3.28", optional = true }
|
||||
# glue (python)
|
||||
pyo3 = { version = "0.20", features = ["extension-module"], optional = true}
|
||||
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"], optional = true }
|
||||
[build-dependencies]
|
||||
# glue (java)
|
||||
flapigen = { version = "0.6.0", optional = true }
|
||||
rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7", optional = true }
|
||||
# glue (js)
|
||||
napi-build = { version = "2", optional = true }
|
||||
# glue (python)
|
||||
pyo3-build-config = { version = "0.19.2", optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -57,3 +62,4 @@ lua = ["mlua", "thiserror", "derive_more", "lazy_static", "tracing-subscriber"]
|
|||
java = ["lazy_static", "jni", "jni-sys", "flapigen", "rifgen", "log"]
|
||||
java-artifact = ["java"] # also builds the jar
|
||||
js = ["napi-build", "tracing-subscriber", "rmpv", "napi", "napi-derive", "futures"]
|
||||
python = ["pyo3", "pyo3-asyncio", "tracing-subscriber", "pyo3-build-config"]
|
||||
|
|
43
build.rs
43
build.rs
|
@ -1,24 +1,37 @@
|
|||
#[cfg(feature = "js")]
|
||||
extern crate napi_build;
|
||||
|
||||
#[cfg(feature = "python")]
|
||||
extern crate pyo3_build_config;
|
||||
|
||||
/// The main method of the buildscript, required by some glue modules.
|
||||
fn main() {
|
||||
#[cfg(feature = "java")] {
|
||||
#[cfg(feature = "java")]
|
||||
{
|
||||
let pkg = "com.codemp.jni".to_string();
|
||||
let pkg_folder = pkg.replace('.', "/"); // java moment
|
||||
|
||||
let out_dir = std::env::var("OUT_DIR").expect("cargo did not provide OUT_DIR");
|
||||
let out_dir = std::path::Path::new(&out_dir);
|
||||
let generated_glue_file = out_dir.join("generated_glue.in");
|
||||
let src_dir = std::path::Path::new("src")
|
||||
.join("ffi")
|
||||
.join("java");
|
||||
let src_dir = std::path::Path::new("src").join("ffi").join("java");
|
||||
let typemap_file = src_dir.join("typemap.in");
|
||||
rifgen::Generator::new(rifgen::TypeCases::CamelCase, rifgen::Language::Java, vec![src_dir])
|
||||
.generate_interface(&generated_glue_file);
|
||||
rifgen::Generator::new(
|
||||
rifgen::TypeCases::CamelCase,
|
||||
rifgen::Language::Java,
|
||||
vec![src_dir],
|
||||
)
|
||||
.generate_interface(&generated_glue_file);
|
||||
|
||||
// build java source path
|
||||
let target = out_dir.parent().unwrap().parent().unwrap().parent().unwrap().to_path_buf(); // target/debug
|
||||
let target = out_dir
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.to_path_buf(); // target/debug
|
||||
|
||||
let mut java_target = target.clone(); // target/debug/java
|
||||
java_target.push("java");
|
||||
|
@ -37,10 +50,11 @@ fn main() {
|
|||
java_gen.expand_many(
|
||||
"codemp-intellij",
|
||||
&[&generated_glue_file, &typemap_file],
|
||||
out_dir.join("glue.rs")
|
||||
out_dir.join("glue.rs"),
|
||||
);
|
||||
|
||||
#[cfg(feature = "java-artifact")] {
|
||||
#[cfg(feature = "java-artifact")]
|
||||
{
|
||||
// panic if no jdk
|
||||
std::process::Command::new("javac")
|
||||
.arg("--version")
|
||||
|
@ -64,7 +78,8 @@ fn main() {
|
|||
jar_file.push("codemp-java.jar");
|
||||
|
||||
let mut jar_cmd = std::process::Command::new("jar");
|
||||
jar_cmd.current_dir(&java_compiled)
|
||||
jar_cmd
|
||||
.current_dir(&java_compiled)
|
||||
.arg("cf")
|
||||
.arg(jar_file.as_os_str());
|
||||
for java_file in java_compiled.read_dir().unwrap().filter_map(|e| e.ok()) {
|
||||
|
@ -78,9 +93,15 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "js")] {
|
||||
#[cfg(feature = "js")]
|
||||
{
|
||||
napi_build::setup();
|
||||
}
|
||||
|
||||
#[cfg(feature = "python")]
|
||||
{
|
||||
pyo3_build_config::add_extension_module_link_args();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "java")]
|
||||
|
|
|
@ -6,3 +6,6 @@ pub mod lua;
|
|||
|
||||
#[cfg(feature = "js")]
|
||||
pub mod js;
|
||||
|
||||
#[cfg(feature = "python")]
|
||||
pub mod python;
|
||||
|
|
Loading…
Reference in a new issue