Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose a build system #4

Closed
4 of 6 tasks
tresf opened this issue Mar 25, 2019 · 2 comments
Closed
4 of 6 tasks

Choose a build system #4

tresf opened this issue Mar 25, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request in-progress question Support question, not a bug

Comments

@tresf
Copy link

tresf commented Mar 25, 2019

@bmhm has been very helpful in giving us some examples on how to create a JNI project with Maven with a working proof-of-concept here: https://github.com/bmhm/native-example

  • Decide if the project use Maven, Gradle or something else
    • Note, some early work for Maven support is available in 2.8.1-experimental branch, authored kindly by @vogt31337
  • Decide if we keep cmake or do we leverage Maven's native build capabilities directly
    • // edit by @bmhm: As discussed, we stick to cmake because of MacOS builds

Note, the temporarily cmake branch has a boilerplate for native and cross-compiling. This will be merged back into mainline once the above decisions are made.

Further TODO for the maven-cmake-branch:

  • move the java parts to src/main/java
  • restructure into submodules, so there can be multiple build jobs (one for each platform).
  • find and replace hardcoded occurrences of linux_64.
  • ask @tresf or @woodrowbarlow how to fix that UnsatisfiedLinkError in my previous comment.
@tresf tresf self-assigned this Mar 25, 2019
@tresf tresf added the question Support question, not a bug label Mar 25, 2019
@bmarwell bmarwell added enhancement New feature or request in-progress labels Mar 27, 2019
@bmarwell
Copy link

As discussed, I based a new example on the existing cmake branch authored by @woodrowbarlow. You can find it here:
https://github.com/java-native/java-simple-serial-connector/tree/maven-cmake

Caveats

I added a test, but it crashes with java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getNativeLibraryVersion()Ljava/lang/String;

Although the method exists:

$ nm -D target/classes/META-INF/lib/linux_64/libjssc.so | grep "Java_.*getNativeLibr"
0000000000005c20 T _Z55Java_jssc_SerialNativeInterface_getNativeLibraryVersionP7JNIEnv_P8_jobject

Generated files

I deleted all generated files (.so, .dll, .h, etc.).
I found that there was a manually added line in the .h file by @scream3r:

#undef jSSC_NATIVE_LIB_VERSION
#define jSSC_NATIVE_LIB_VERSION "2.8"

Meaning it wasn't truly generated after all.

Directory structure

I converted some directories to the maven standard directory layout. If you haven't seen it before, please take a quick look.

Built files go to target/ and get removed on a clean build (mvn clean install).

JDK compatiblity

I set some properties to force java 1.6, as requested. javah does not exist in JDK 9 updwards, so I had to add a profile where the maven compiler plugin does this job instead.

cmake invocation

cmake can only generate headers from jar files, which doesn't help us very much. We had to repackage the jar. So I decided to let maven do all the stuff it can do nicely first (executing cmake-generate, compiling, generating headers), then executing cmake-compile. This seems to work nicely.

native-lib-loader

I started using https://github.com/scijava/native-lib-loader because it has some sane fail-safes and is well tested.

cmake will put it's files to target/classes/META-INF/lib/<platform>/libjssc.<ext> accordingly, so native-lib-loader can find them.

bmarwell added a commit that referenced this issue Apr 2, 2019
…run-plugin.

  - Options from previous cmake-plugin-execution added.
  - Working directories added.
  - Environment variables still need to be done.
  - Added another test which currently fails (to highlight a known problem).
  - Not tested on MacOS or Windows.
@tresf
Copy link
Author

tresf commented Apr 5, 2019

  • move the java parts to src/main/java

^-- This has FIXMES in the code. We'll do this eventually but we'd like to move over open PRs before we do any major refactoring. This is a followup task.

restructure into submodules, so there can be multiple build jobs (one for each platform).

This concern is still valid, but has less to do with the build system and more to do with how we store the binaries.

  • Choose a build system

We've chosen maven for now. WIP is happening in a few branches until they're merged to master. For now, see #14 and #18. They should be merged to master as soon as humanly possible. 😄

@tresf tresf closed this as completed Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in-progress question Support question, not a bug
Projects
None yet
Development

No branches or pull requests

3 participants