sbt / sbt-jni

SBT Plugin to ease working with JNI
BSD 3-Clause "New" or "Revised" License
126 stars 28 forks source link

Cargo workspace #185

Closed datben closed 11 months ago

datben commented 11 months ago

Hello, could you tell me how to configure sbt-jni with a cargo workspace and not a simple cargo lib, i did not find any example about this

pomadchin commented 11 months ago

Hi @datben, it should work with whatever is in the i.e. native dir; just put / modify a generated Cargo.toml in it.

https://github.com/sbt/sbt-jni#cargo

Have you tried it? If it does not work a bug report will be very helpful.

datben commented 11 months ago

Ty @pomadchin , indeed my cargo.toml was miss configured, it seems to work now, ty for your time !

datben commented 11 months ago

Hello @pomadchin, i have another issue, i'd like to build multiple library with jni in one workspace, however i got a message telling me that only one library can be build: [warn] More than one file was created during compilation, only the first one (/builds/defi/solana-scala/jni-integration/target/native/x86_64-linux/bin/release/libwhirlpool_native.so) will be used.

pomadchin commented 11 months ago

@datben I think I'd need a reproducible example project to help with this one

datben commented 11 months ago

I'll try to make one since i can't share the code

datben commented 11 months ago

@pomadchin could you try to compile this https://github.com/datben/jni-test with sbt compile? this message should appear [warn] More than one file was created during compilation, only the first one (/jni-test/jni-integration/target/native/x86_64-linux/bin/release/liba.so) will be used.

pomadchin commented 11 months ago

Oh that's a known limitation, we expect the underlying library to produce a single dylib. That's a good question what to do with multiple / how to handle it, so any suggestions and PRs are welcome.

I believe all of the supported build tools have this limitation.

pomadchin commented 11 months ago

That's the origin of the message: https://github.com/sbt/sbt-jni/blob/main/plugin/src/main/scala/com/github/sbt/jni/build/Cargo.scala#L56-L62

datben commented 11 months ago

ok, so i guess the only solution is too split each crate for now

pomadchin commented 11 months ago

Or figure out what we really need to do here in case of multiple libs present.

Mb there is a room for improvement 🤔

datben commented 11 months ago

Is there a specific reason why 'lib' has to be 'File' and can't be 'List[File]'? i dont see where the output of nativeCompile is used

pomadchin commented 11 months ago

@datben you know it looks like nothing prevents us from packing more libs into a jar 🤷 I'll bring up a PR and we see what breaks.