Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

refactor(java-bindings): add test #154

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
working-directory: packages/rust-core
run: |
cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 300 --run-types doctests --run-types lib --run-types tests --out xml
env:
RUST_BACKTRACE: full

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java-bindings-build-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
shell: bash
run: |
./mvnw verify org.sonatype.plugins:nexus-staging-maven-plugin:deploy \
-DskipTests=true \
-DskipTests \
-Djni.classifier=${{ matrix.classifier }} \
-Dcargo-build.profile=release \
-DaltStagingDirectory=local-staging \
Expand Down
101 changes: 58 additions & 43 deletions packages/rust-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packages/rust-core/java/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ num_cpus.workspace = true
tokio.workspace = true
thiserror.workspace = true

jni = "0.21.1"
jni = { version = "0.21.1", features = [] }

[dev-dependencies]
lazy_static.workspace = true
# https://github.com/rust-lang/cargo/issues/2911#issuecomment-749580481
flappy-java-bindings = { path = ".", features = ["build-java-support"] }


[lints]
workspace = true

[features]
build-java-support = ["jni/invocation"]
2 changes: 1 addition & 1 deletion packages/rust-core/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ To load the shared library correctly, you can choose one of the following approa
You can use Maven to build both Rust dynamic lib and JAR files with one command now:

```shell
./mvnw clean package -DskipTests=true
./mvnw clean package -DskipTests
```

## Run tests
Expand Down
63 changes: 63 additions & 0 deletions packages/rust-core/java/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#[cfg(feature = "build-java-support")]
fn build_java() {
use std::{env, path::PathBuf, process::Command};

let java_src_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
println!("src dir {:?}", java_src_dir);

let mut java_src_mvnw = java_src_dir.clone();
java_src_mvnw.push(
#[cfg(target_os = "windows")]
"mvnw.bat",
#[cfg(not(target_os = "windows"))]
"mvnw",
);

let java_build_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

println!("build dir {:?}", java_build_dir);

let mut binding = Command::new(java_src_mvnw.clone());
let command = binding
.args(["package", "-DskipTests", "-Dgpg.skip"])
.current_dir(java_src_dir.clone());

println!("command {:?}", command);

let result = command.spawn().unwrap().wait().unwrap();

if result.success() {
let mut source_dir = java_src_dir;
let version_u8 = Command::new(java_src_mvnw)
.args([
"help:evaluate",
"-Dexpression=project.version",
"-q",
"-DforceStdout",
])
.output()
.unwrap()
.stdout;
let version = String::from_utf8_lossy(&version_u8);
let trimed_version = version.trim();

source_dir.push("target");
source_dir.push(format!("flappy-java-bindings-{}.jar", trimed_version));

let mut target_dir = java_build_dir;
target_dir.push("flappy-java-bindings-latest.jar");

println!("cargo:warning=build ok {:?}", target_dir);
std::fs::copy(source_dir, target_dir).unwrap();
} else {
panic!("build error");
}
}

fn main() {
println!("cargo:warning=build maven");
println!("cargo:rerun-if-changed=src/main");

#[cfg(feature = "build-java-support")]
build_java();
}
Loading
Loading