alexarchambault / mill-native-image

Apache License 2.0
18 stars 6 forks source link

Is it possible to force Native Image to build on Docker #15

Closed carlosedp closed 1 year ago

carlosedp commented 2 years ago

I'm developing on a Mac and if I use the plugin, the Native Image if build for my platform (MacOS).

I see the plugin has infrastructure to build on Docker and since Docker runs on a Linux VM in Mac (and Windows too), can I "force" the plugin to build in Docker so I get a Linux binary instead of a MacOS one?

Thanks

alexarchambault commented 1 year ago

Yes, Scala CLI does this in its build around here. You have to make nativeImageDockerParams return Some(…).

I'm not used to run it on macOS though (and don't have a working docker command on my current machine to test), Scala CLI uses it on its Linux CI to make sure the Linux binary doesn't depend on GHA workers details.

carlosedp commented 1 year ago

Got it... I defined nativeImageDockerParams and have to run mill backend.writeNativeImageScript generate-nativeimage.sh "". Then I run the generated script and it builds the binary. Right?

carlosedp commented 1 year ago

Actually found-out that just defining nativeImageDockerParams section like scala-cli does, makes the native image to be built in Docker itself.

I've used your plugin to create another plugin that packs the native image in a Docker image: https://index.scala-lang.org/carlosedp/mill-docker-nativeimage Amazing work Alex.

carlosedp commented 1 year ago

In my build.sc I did an env var check that allows me to build either in Docker or locally. Here's for reference: https://github.com/carlosedp/zio-scalajs-stack/blob/6cf6eaa4d25040f9940a4b52745170a94a2adc7f/build.sc#L120

Thanks again!