jank-lang / jank

The native Clojure dialect hosted on LLVM
https://jank-lang.org
Mozilla Public License 2.0
1.69k stars 50 forks source link

Implement resource bundling and loading into the executable #91

Open jeaye opened 2 months ago

jeaye commented 2 months ago

This is a very handy feature of the JVM and JAR file structure. We can replicate it in C++, but it will require some platform-specific tooling. Some cursory search shows that ld can do this for us: https://stackoverflow.com/a/11622727

Interestingly, the asm then required to access the objects will need to be JIT compiled, so we'll have to see how well that works and if the symbols can be found.

I think there are other approaches which don't embed resource into the executable itself, such as AppImages, but they're even less cross-platform. I would like for jank's AOT compiled programs to just be standalone, but I will settle for AppImages if necessary.

So, the way this would look is that jank needs to:

  1. Know the resource paths
  2. Provide some functions á la io/resource
  3. Search the resource paths (on the fs)
  4. Fall back to searching the resource paths within the application
  5. During AOT compilation, bundle all files within the resource paths into the application and build a map of file path -> pointer+size
  6. Ensure all of this works on Linux and macOS (Windows will need special handling and is not a high priority for jank at this time)