Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Experiment with jpackage to create executable binaries #3201

Closed
wants to merge 4 commits into from

Conversation

lefou
Copy link
Member

@lefou lefou commented Jun 6, 2024

Still in experimenting phase

Created a new module JpackageModule, which wraps around the jpackage tool, that's part of newer JDK releases and is used to produced native executables and distributable packages.

Although, there are some configuration points, in most cases, it should be as easy usable as assembly.

> mill show foo.jpackage
[1/1] show > [93/93] foo.jpackageAppImage 
".../out/foo/jpackageAppImage.dest/out/foo/bin/foo"

> file out/foo/jpackageAppImage.dest/image/foo/bin/foo
out/foo/jpackageAppImage.dest/out/foo/bin/foo: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, not stripped

@lefou lefou changed the title Experiment with jpackage to create executable binaries [WIP] Experiment with jpackage to create executable binaries Jun 6, 2024
@lefou
Copy link
Member Author

lefou commented Jun 6, 2024

Based on https://dotnet.social/@fornever/112560707798240443, which points to https://fornever.me/en/posts/2024-06-05.scala-jpackage-publishing.html, I tried to implement a generic jpackage target that can produce self-contained executables for any JavaModule (or ScalaModule). This is a WIP PR just to see what works.

lihaoyi added a commit that referenced this pull request Dec 2, 2024
This intended to close #3638.

The `JlinkModule` creates a runtime image in two steps:
1. it creates a `jlink.jmod` file for the module containing the
`mainClass` using the
[`jmod`](https://docs.oracle.com/en/java/javase/23/docs/specs/man/jmod.html)
tool;
2. it then uses the
[jlink](https://docs.oracle.com/en/java/javase/23/docs/specs/man/jlink.html)
tool, to link the previously created `jlink.jmod` with a runtime image.

The generated runtime image can be executed with:
```sh
./out/foo/jlinkAppImage.dest/jlink-runtime/bin/jlink
```

As for the `JpackageModule` implementation, I decided to reuse most of
the `JpackageModule` code @lefou
[linked](#3201) to the original
issue. Of course his code completely avoids the `jmod` dance by using
[`jpackage`](https://docs.oracle.com/en/java/javase/23/docs/specs/man/jpackage.html)
to create a native package/installer directly.

`jpackage` supports up to 3 different package/installer outputs on
macOS:
```sh
jpackageType = "dmg"
./out/foo/jpackageAppImage.dest/image/foo-1.0.dmg

jpackageType = "pkg"
./out/foo/jpackageAppImage.dest/image/foo-1.0.pkg

jpackageType = "app-image"
./out/foo/jpackageAppImage.dest/image/foo.app
```

Would be interested to hear your thoughts on the slight difference
between how the 2 traits are implemented.

---------

Co-authored-by: Li Haoyi <[email protected]>
@lefou
Copy link
Member Author

lefou commented Jan 5, 2025

Merged as part of #4038

@lefou lefou closed this Jan 5, 2025
@lefou lefou added this to the 0.12.4 milestone Jan 5, 2025
jodersky pushed a commit to jodersky/mill that referenced this pull request Jan 14, 2025
This intended to close com-lihaoyi#3638.

The `JlinkModule` creates a runtime image in two steps:
1. it creates a `jlink.jmod` file for the module containing the
`mainClass` using the
[`jmod`](https://docs.oracle.com/en/java/javase/23/docs/specs/man/jmod.html)
tool;
2. it then uses the
[jlink](https://docs.oracle.com/en/java/javase/23/docs/specs/man/jlink.html)
tool, to link the previously created `jlink.jmod` with a runtime image.

The generated runtime image can be executed with:
```sh
./out/foo/jlinkAppImage.dest/jlink-runtime/bin/jlink
```

As for the `JpackageModule` implementation, I decided to reuse most of
the `JpackageModule` code @lefou
[linked](com-lihaoyi#3201) to the original
issue. Of course his code completely avoids the `jmod` dance by using
[`jpackage`](https://docs.oracle.com/en/java/javase/23/docs/specs/man/jpackage.html)
to create a native package/installer directly.

`jpackage` supports up to 3 different package/installer outputs on
macOS:
```sh
jpackageType = "dmg"
./out/foo/jpackageAppImage.dest/image/foo-1.0.dmg

jpackageType = "pkg"
./out/foo/jpackageAppImage.dest/image/foo-1.0.pkg

jpackageType = "app-image"
./out/foo/jpackageAppImage.dest/image/foo.app
```

Would be interested to hear your thoughts on the slight difference
between how the 2 traits are implemented.

---------

Co-authored-by: Li Haoyi <[email protected]>
@lihaoyi lihaoyi deleted the jpackage branch January 27, 2025 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant