Closed Fuuzetsu closed 6 years ago
This is for most part a discussion PR about what approaches we want to take, whether changes in sparkle/inline-java would make things easier &c.
Closing in favour of solution through https://github.com/tweag/rules_haskell/issues/80
Delete the bazel branch?
I'll be updating it with new solution soon hopefully.
For the most part this should be self-explanatory but there are a couple of things that need to be talked about and resolved in the future one way or another, be it in sparkle/inline-java or rules_haskell.
inline-java
relies onjavac
. We can provide this trivially through nix. In practice however that's quite useless: in sparkle we wantjavac
with Java part ofsparkle
in the CLASSPATH. This is because we want to compile Java bytecode during GHC compilation that depends on it. The existing cabal way is to rungradle
build before GHC runs, extract and set CLASSPATH that way. With bazel we do not have the luxury of Cabal's setup hooks. This is an awful way to begin with: running another build system during Haskell compilation just seems wrong but the problem remains.bazel
: after all that's the big part of the appeal:bazel
has rules for multiple languages so we should be able to use them. This means that ideally we do not want to just say "OK, let's just use nix to compile the Java part: it has the authoritative access to the jars and we can easily refer to them by absolute path by wrapping javac". While this could work, it gives too much to do for nix.rules_haskell
: we don't want to have to have specific Java handling in Haskell rules. It's an implementation detail of inline-java that it's done this way and it'd be wrong to put in code to accommodate this library.javac
that has a CLASSPATH already set. Then when it comes time to actually use it, we make sure that the jars are in place throughrule_haskell
sdata
section.Sparkle.hs
. Currently it relies onPaths_
to find sparkle jar which is a Cabal feature. I have put in a workaround where cabal users can keep relying on it but others can use a differentmain
which requires that this is passed in.bazel build
and./bazel-bin/sparkle
but doesn't work if we try tobazel run
. I could not figure out how to get the latter working.w.r.t.
javac
: the problem in general is that we want to define a toolchain from a rule that's using the toolchain. I think the best way to solve this would be to use two toolchains:We could have a third toolchain which is just GHC only but it adds a chance that we mix GHC being used &c. (which may be OK).
I am unsure if this approach is doable, I have not explored it yet. It would likely require defining some sparkle_toolchain with appropriate rules_haskell toolchain type.
There was also talk about inline-java instead outputting Java files that we could then compile. In theory this would be the nicest way for us as long as we know what it outputs. I don't see however how it would work in practice: as far as I understand, the Haskell compilation relies on the bytecode being produced during compilation and it's used for things (type inferrence?). Further our existing Haskell rules can't accommodate such a stop-start approach: they always expect that a library is produced in the end. We would need some custom rule that only spits out the generated Java files, we'd have to compile those then we still have to figure out how to supply it back to GHC for the rest of the compilation.