Skip to content

Set the CLASSPATH in a wrapper for binaries #179

@facundominguez

Description

@facundominguez

We can build Haskell binaries that use inline-java. However, initializing the JVM in these programs requires specifying the paths to all the jar files that are needed by the Java part of the program.

Currently, inline-java achieves this by making a fat jar of the java dependencies as in

data = [":jar_deploy.jar"],

then we pass the path to the fat jar to the jvm as in

let jarPath = Runfiles.rlocation r "io_tweag_inline_java/benchmarks/wizzardo-http/jar_deploy.jar"
cpArg = "-Djava.class.path=" <> fromString jarPath

Fat jars, however, aren't always ideal, and there is some boilerplate to using these in BUILD files.

It would be nice defining a rule in inline-java to create script wrappers around binaries, which sets the classpath before calling the executable. Something like

haskell_binary(
  name = "hello-hs"
  deps = haskell_deps + some_java_deps,
  ...
)

classpath_wrapper(
  name = "hello-hs-wrapper"
  dep = ":hello-hs"
)

we can then run in the command line bazel-bin/hello-hs-wrapper.sh to execute the program with an environment variable like INLINE_JAVA_CLASSPATH=paths/to/jars/in/runfiles.

tweag/rules_haskell#1483 would be blocking this feature, which otherwise could be implemented with transitive_runtime_jars.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions