rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

Add unit test for precompiled native libraries

Open seanmcl opened this issue 8 years ago • 13 comments

With precompiled libraries java_* rules put the library on java.library.path. scala_* rules currently do not.

seanmcl avatar Feb 10 '17 19:02 seanmcl

Can one of the admins verify this patch?

bazel-io avatar Feb 10 '17 19:02 bazel-io

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

googlebot avatar Feb 10 '17 19:02 googlebot

I signed it!

seanmcl avatar Feb 10 '17 19:02 seanmcl

CLAs look good, thanks!

googlebot avatar Feb 10 '17 19:02 googlebot

Any update on this?

ashwin153 avatar Mar 06 '19 02:03 ashwin153

Probably pretty easy to solve by adding a data dependency, but I don’t have this problem so I haven’t looked at solving it.

johnynek avatar Mar 06 '19 03:03 johnynek

I have the same issue, and puting the cc_library target as data do not solve it. I don't know if it changes anything, but in my case the so is embedded in third party jar. When using it in a scala_binary it works fine, but from within a scala_test it does not appear in java.library.path. Well to be more precise, when I print java.library.path, the jar that's supposed to contain the so does appear in java.class.path, however I still have an java.lang.UnsatisfiedLinkError with a message that states that the library is not in the java.library.path.

I created a repository to expose a minimal version of the problem : https://github.com/lgirault/jni_scala_test

I'm still fiddling with this test and what's strange is that when invoking "bazel test", the test fails but when executing the subcommand obtained by using the "-s" flags, the test works !

lgirault avatar Jan 11 '21 13:01 lgirault

@lgirault I've pushed small example of JNI in Scala and Java, see if it helps: https://github.com/liucijus/bazel-jni-demo

liucijus avatar Jan 13 '21 09:01 liucijus

Great ! now it works ! This is a bit frustrating that I need to add a gen_rule to extract the so from the jar but it seems unavoidable. I've updated my repo so that it shows the working example. Thank you very much !

lgirault avatar Jan 13 '21 14:01 lgirault

@lgirault any chance you can send a docs PR for this issue?

ittaiz avatar Jan 15 '21 06:01 ittaiz

I can, but I'm not sure the working thing I wrote thanks to @liucijus example is the best practice. I have a genrule that extract the so library packaged by my third party dependency. Furthermore using bazel-deps my "public" target is "//3rdparty/jvm/com/eclipsesource/j2v8:j2v8_linux_x86_64" while the gen rule needs to point to the internal target "//external:jar/com/eclipsesource/j2v8/j2v8_linux_x86_64" to work. Or you just want the doc for the "simpler" use case where you have a cc_target as in @liucijus exemple ?

lgirault avatar Jan 15 '21 09:01 lgirault

I think the simple case would help others yeah. Thanks!

On Fri, 15 Jan 2021 at 11:03 Loïc Girault [email protected] wrote:

I can, but I'm not sure the working thing I wrote thanks to @liucijus https://github.com/liucijus example is the best practice. I have a genrule that extract the so library packaged by my third party dependency https://github.com/lgirault/jni_scala_test/blob/main/src/scala/com/mediarithmics/lib/v8/BUILD.bazel#L3. Furthermore using bazel-deps my "public" target is "//3rdparty/jvm/com/eclipsesource/j2v8:j2v8_linux_x86_64" while the gen rule needs to point to the internal target "//external:jar/com/eclipsesource/j2v8/j2v8_linux_x86_64" to work. Or you just want the doc for the "simpler" use case where you have a cc_target as in @liucijus https://github.com/liucijus exemple ?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/pull/140#issuecomment-760765996, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKQQF2DJWC2KYW2O7MTJD3S2AAFDANCNFSM4C7XBEGA .

--

Ittai Zeidman

40 Hanamal street, Tel Aviv, Israel

http://www.wix.com

ittaiz avatar Jan 15 '21 09:01 ittaiz

here it is https://github.com/bazelbuild/rules_scala/pull/1182 @liucijus example speaks for itself, hence the documentation is quite short and references the example (submitted along the doc). I completed it with a scala_test target.

lgirault avatar Jan 15 '21 09:01 lgirault

closing as stale, feel free to reopen

liucijus avatar Jan 31 '24 14:01 liucijus