Using multiple toolchains in a rule

41 views
Skip to first unread message

facundo...@gmail.com

unread,
Mar 5, 2019, 5:23:53 PM3/5/19
to bazel-discuss
Hello,

I'm using bazel and rules_haskell to build a Haskell project called inline-java [1]. The project allows to embed and execute java source code in Haskell modules.

Some of the rules in this project need to use both a Haskell and a Java compiler. So far we had been tweaking the Haskell toolchain to include the java compiler in the visible binaries. This approach, however, has stopped working for technical reasons [2].

Before I try to come up with another adhoc solution, I'd like to know if there is a preferred way to combine two toolchains, like the Java and the Haskell toolchains, so the binaries of both are visible when building.

Ideally, this toolchains could be specified per-rule-instance, so we don't need to expose the Java toolchain in places where it isn't needed.

Thanks,
Facundo

[1] https://github.com/tweag/inline-java
[2] https://github.com/tweag/rules_haskell/issues/713

John Cater

unread,
Mar 8, 2019, 10:27:50 AM3/8/19
to facundo...@gmail.com, bazel-discuss
Currently, this is tricky. The good news is that soon it will be much easier.

Using the toolchains and platforms features, it is possible to declare that a rule requires multiple toolchain types. In this case, when a target is configured, there must be at least one execution platform that is compatible with a registered toolchain of each type. Each resolved toolchain will be available in 'ctx.toolchain["toolchain_type"]'.

Two caveats:
1. It isn't possible currently to have optional toolchains: they are required or they are not. See https://github.com/bazelbuild/bazel/issues/3601 if you want to comment on the feature request for this.
2. Not all rules currently are exposed via toolchain type and toolchain resolution. Java rules don't yet, and so your request is going to be more tricky.

The good news is that the work to convert Java rules to use toolchain resolution is in progress, and should be done in the next few Bazel releases. If you have something that is working for you now, I suggest waiting for that before trying difficult workarounds for getting a Java toolchain.

John Cater


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/752a1c95-0e1f-48d8-aa98-2235ba0867a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages