Cross-building Scala libraries

227 views Asked by At

I would like to cross-build some of my Bazel targets to Scala 2.12 and 2.13. As a further point of complexity, I need to be able to express cross-target dependencies (eg. some 2.13 target may have a Bazel dependency on a 2.12 target).

Note: this isn't a regular library dependency (eg. with the dependency 2.12-built JAR showing up on the class path when compiling the 2.13 JAR), as that would almost surely result in issues due to having two incompatible versions of the Scala standard library on the class path. Rather, this is just a case where I need the dependency JAR built so I can use it in some integration tests in the 2.13 target.

What I've found online so far...

  • This issue from rules_scala seems it doesn't support baking the Scala version into the target and instead you have to pick the Scala version globally.
  • This Databricks post has a cross-building section that is exactly what I think I would like (eg. one target generated per library per supported Scala version), but the snippets in that post don't seem to be backed by any runnable Bazel code.
  • This later post by Databricks also hints at a cross_scala_lib rule, but also doesn't have any accompanying code.
1

There are 1 answers

0
Eugene Yokota On BEST ANSWER

Wrote a blog post cross build anything with Bazel using Scala cross building as example in both traditional WORKSPACE way and the new MODULE.bazel way.

See https://github.com/eed3si9n/gigahorse/pull/85 for a working example.