Sign inSign up

tweag/jarify

By tweag

Updated almost 9 years ago

Transmutation of native binaries into JVM apps.

Image
0

2.0K

tweag/jarify repository overview

clodl: self-contained dynamic libraries

clodl computes the closure of a shared object. That is, given a shared library or a position independent executable (PIE), it returns a single, self-contained file packing all dependencies. Think of the result as a poor man's container image. Compared to containers:

  • closures do not provide isolation (e.g. separate process, network, filesystem namespaces),
  • but closures do allow for loading into the same address space as an existing process.

Executing a closure in the address space of an existing process enables lightweight high-speed interop between the closure and the rest of the process. The closure can natively invoke any function in the process without marshalling/unmarshalling any arguments, and vice versa.

clodl is useful for "jarifying" native binaries. Provided shim Java code, closures can be packed inside a JAR and then loaded at runtime into the JVM. This makes JAR's an alternative packaging format to publish and deploy native binaries.

Example

clodl is implemented as a set of Bazel build rules. It integrates with your Bazel build system, e.g. as follows:

cc_binary(
  name = "hello.so",
  srcs = ["*.c"],
  linkedshared = 1,
)

library_closure(
  name = "hello-closure",
  srcs = ["hello.so"],
  testonly = True,
)

java_binary(
  name = "hello-jar",
  resources = [":hello-closure"],
  main_class = ...,
  srcs = ...,
  runtime_deps = ...,
)

Building it

Requirements:

To build and test:

$ bazel test //...

Usage

Any position independent (dynamically linked) executable (PIE) can be "closed" using clodl.

On OS X, all executables are PIE.

To create a PIE on Linux and other platforms, pass the -pie flag to the linker. Currently, we furthermore require "origin processing" to be turned on. Here is the full set of options to pass to ld:

$ gcc -pie -Wl,-z,origin -Wl,-rpath,$ORIGIN ...

Some distributions create position independent executables by default (Ubuntu and Debian on some architectures).

License

Copyright (c) 2015-2018 EURL Tweag.

All rights reserved.

clodl is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Tweag I/O

clodl is maintained by Tweag I/O.

Have questions? Need help? Tweet at @tweagio.

Tag summary

Content type

Image

Digest

Size

723 MB

Last updated

almost 9 years ago

docker pull tweag/jarify