diff --git a/.gitignore b/.gitignore index a211351..3c354a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ minmax-java/build minmax-java/.gradle .idea -target \ No newline at end of file +target +*.so \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c66873 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Minmax in Rust with JNI + +## How to build and run + +### Prerequisites +- Gradle +- Rust toolchain + +### Compile Rust code + +`cargo build` + +### Assemble shared library + +Copy the shared library in `target/debug/librs_wrapper.so` (or a `.dll` on windows) to a known location like the working directory or the system wide library directory. + +### Build the jar + +Use `./gradlew jar` or whatever you like I don't know. + +### Run the program + +Maybe it works now. If you get a link error you might need to set the `LD_LIBRARY_PATH` env var to the path of the shared library (on linux). Or you have to copy it to the systems library directory. Or something else. But it should work. \ No newline at end of file diff --git a/minmax-java/build.gradle b/minmax-java/build.gradle index c062119..5700a19 100644 --- a/minmax-java/build.gradle +++ b/minmax-java/build.gradle @@ -11,6 +11,12 @@ java { } } +jar { + manifest { + attributes 'Main-Class': 'ch.bbw.m411.connect4.Connect4ArenaMain' + } +} + repositories { mavenCentral() } @@ -23,4 +29,4 @@ dependencies { tasks.named('test') { useJUnitPlatform() -} +} \ No newline at end of file diff --git a/minmax-java/src/main/java/ch/bbw/m411/connect4/RustPlayer.java b/minmax-java/src/main/java/ch/bbw/m411/connect4/RustPlayer.java index 5f09555..eb872b2 100644 --- a/minmax-java/src/main/java/ch/bbw/m411/connect4/RustPlayer.java +++ b/minmax-java/src/main/java/ch/bbw/m411/connect4/RustPlayer.java @@ -3,6 +3,13 @@ package ch.bbw.m411.connect4; public class RustPlayer extends Connect4ArenaMain.DefaultPlayer { private static native int rustPlay(byte player, byte[] board); + static { + // This actually loads the shared object that we'll be creating. + // The actual location of the .so or .dll may differ based on your + // platform. + System.loadLibrary("rs_wrapper"); + } + @Override protected int play() { byte player = switch (this.myColor) {