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

[native-image] Cross compilation support? #407

Open
sureshg opened this issue May 6, 2018 · 63 comments
Open

[native-image] Cross compilation support? #407

sureshg opened this issue May 6, 2018 · 63 comments
Assignees
Labels

Comments

@sureshg
Copy link

sureshg commented May 6, 2018

Any plans to add cross-compilation feature to native-image? I know it's too early to ask for these kind of requirements since we don't even have a working Windows build. IMHO, this would be a nice feature (golang has nice support for it) to have especially if we want to build binaries for all platforms from a CI (Jenkins) machine.

https://medium.com/@chrisgseaton/i-dont-think-we-have-any-immediate-plans-for-cross-compilation-but-it-s-not-a-major-problem-to-bf789384beaa

@thomaswue thomaswue self-assigned this May 6, 2018
@plombardi89
Copy link

Definitely would love to see this feature! This would make it so much nicer to use Java for CLI apps and servers that need to be distributed to users on Linux, Mac and Windows.

@alza-bitz
Copy link

It would be amazing to have cross-compilation support. Is this still not planned for yet, or is it dependent on the Windows build? It would still be useful to have cross-compilation available to create Mac binaries on a (Linux) CI server, and then add support for Windows cross-compilation later?

@alza-bitz
Copy link

@thomaswue @chrisseaton I was just wondering if this is on the roadmap for 2019, or has any ETA etc? I think it would be a game-changer!

@alza-bitz
Copy link

@thomaswue @chrisseaton I was just wondering if this is on the roadmap for 2019, or has any ETA etc? I think it would be a game-changer!

Hi @thomaswue @chrisseaton since we're halfway through the year, I just thought I'd check in on this one..

Has there been any development on this issue, or any news/progress to report?

Thanks in advance! 🙂

sgammon added a commit to sgammon/elide-archive that referenced this issue Feb 6, 2020
- Support building via `native-image`
- Support pushing to container repo for native image
- No cross-platform build support yet (oracle/graal#407)
sgammon added a commit to sgammon/elide-archive that referenced this issue Feb 6, 2020
* Feature: Packaging

This changeset introduces initial packaging for Gust, and for apps
that use Gust. Changes so far:

- [x] Fixup package for eventual publish to `npm`
- [x] Add support for GitHub packages
- [x] Add support for `rules_docker` targets
- [x] Add support for tarball targets

* Update Micronaut -> 1.3.0

* Upgrade Yarn dependencies

* Upgrade Bazel dependencies

* Fixes and functionality for crosslib builds

- Fix defs when used in a cross-lib context
- Fix DOM test
- Tighten up DualStackTest

* Initial support for container targets

- Add Java container target
- Add example push command (currently blocked on
  bazelbuild/rules_docker#1413)

* Re-enable container tag via BUILD_SCM_VERSION

* Fix workspace status command file

* Working container build-and-run flow

- Ability to build Java app containers, and push them to GCR
- Tested containers locally (manually for now)

* Update fork of rules_closure

* Remove forced JDK8 build flags

* Update J2CL with static bootclasspath

* Update rules_graal with new attrs for debugging

* Initial build flow for Graal native binary targets

- Setup build lib
- Attach to Graal image
- Override default compiler path (workaround for Bazel bug)

* Re-enable disk caching in CI

* Native binary support, with container image

- Support building via `native-image`
- Support pushing to container repo for native image
- No cross-platform build support yet (oracle/graal#407)

* Fix injected testdeps

* Don't enable native targets without a flag

* Add CI routine for baking samples

* Cleaner CI flow

* Attempt GCR auth fix, flush keys

* Another credentials fix

* Fix Bazel label in regular CI job

* Try auth via gcloud

* Explicitly activate gcloud key

* Apply new auth to sample image build

* Fixup key paths in CI

* Move GCP install step up in CI flow

* Cleanup CI configs

* Use relative access to service key from env

* Unify image bake, restore Docker index pull

* Add base container build file

* Use new base container
@sureshg
Copy link
Author

sureshg commented Feb 28, 2020

@thomaswue Now we have java 11 and windows support ready, are there any plans to consider cross-compilation support in the near future?

@thomaswue
Copy link
Member

Adding the support is quite tricky. The issue is that there are parts of the JDK initialized during the native image generation process that could be platform dependent and then end up in the image. One of the alternatives could be to offer a service for creating native images. Also, maybe one could use maybe a system like GitHub actions to build images for different platforms without the need to maintain/setup those machines. Would this help for your use cases or is true cross compilation a requirement?

@xiaodong-xie
Copy link

I do think people should have mentioned this workaround elsewhere.

I am using this https://hub.docker.com/r/oracle/graalvm-ce/ docker image, to build the native-image running on Linux, on my MacBook laptop.

@sureshg
Copy link
Author

sureshg commented Feb 29, 2020

Would this help for your use cases

@thomaswue Thanks. Yeah, GitHub action would work for OSS projects. The issue is, our build system is mostly on Linux and wants to build native-images for windows and mac (mostly for CLI apps). So the cross-compilation would have definitely helped in this scenario.

@nhoughto
Copy link

Yeah it’s not really cross compilation if you need the target platform to build it, that’s just regular old compilation. If Cross compilation is a feature being targeted all the jvm weirdness will need to be solved, I guess the question is, is/when is it a priority?

@sureshg
Copy link
Author

sureshg commented Mar 1, 2020

Here is some discussion on the current limitations - https://graalvm.slack.com/archives/CN9KSFB40/p1582755160011700

@truh
Copy link

truh commented Mar 3, 2020

Here is some discussion on the current limitations - https://graalvm.slack.com/archives/CN9KSFB40/p1582755160011700

Would it be possible to share a summary of the discussion? The slack archive can only be accessed by people that are member to the workspace.

@sureshg
Copy link
Author

sureshg commented Mar 8, 2020

@truh

Christian Wimmer : 
No, cross compilation between different OS is more or less impossible in
 the current approach because OS specific JDK classes need to be loaded 
in the image generator

The biggest problem is, e.g., the file system and network stack. The JDK code
 for that is very different for Linux, MacOS, and Windows. You cannot load the 
code from two platforms at the same time, but you need to load the code from 
the platform that the image generator runs on.

@CircuitRCAY
Copy link

Anything on cross compiling between architectures? (x86_64 -> arm64, for example)

@8Keep
Copy link

8Keep commented Nov 5, 2020

This is pretty huge for me. Is there any future plan at all to find a way to do this?

@SaraDark
Copy link

+1000 to Cross compilation support

@tuhuynh27
Copy link

+10000 to Cross compilation support

loicrouchon added a commit to loicrouchon/symly that referenced this issue Nov 17, 2021
The complexity of setting a build pipeline for GraalVM native image
and having access to both macOs/linux for both x64 and ARM architecture
is too much of an overhead for a small opensource project.

This might be reconsidered in the future when availability on those
OS/arch will be more widely spread or that GraalVM will offer
cross compilation support.

See oracle/graal#407
@rmannibucau
Copy link

Hi,

from Linux/amd64 to windows|arm64 for me.

Any CI is not an option on some env so would be great to have a solution close to c++ solutions.

@xlight05
Copy link

xlight05 commented Nov 9, 2022

What is the primary source/destination architecture you would be interested in to cross-compile, is it Linux/amd64 to Linux/aarch64? Is it possible to solve your use case with the GitHub Action workaround?

@thomaswue

I think the real advantage of cross compilation comes when JVM languages/frameworks adopt GraalVM Ex - Quarkus. Lets assume I wanna deploy an azure function using my framework(which is a perfect usecase where AOT shines). As far as I know, Azure functions only supports executable with linux/amd64. The language/framework can wrap graalvm and generate that executable for the user by hiding that complexity from user.

So the github actions workaround would not work in this case as it needs to happen from the framework's side, not the users side. The closest workaround i have is building it using docker using buildx. The issue with this is the docker dependency. Still, even with docker, its hard to do the cross compilation for different operating systems.

@brainchild0
Copy link

For enterprise deployments, it may suffice in many contexts for a vendor to utilize a server for building each new release of a project. However, cross building is extremely standard for deployments of open-source platforms and packages. It is hard to see how a tool would gain much traction for open source projects these days if it constrains the target and build environment to be the same platform or machine family.

@thomaswue
Copy link
Member

@brainchild0 Agreed. We believe however that many open source (and even commercial) projects can use our GitHub Action for GraalVM to build their releases. Is this not a reasonable workaround? https://github.com/marketplace/actions/github-action-for-graalvm

We could also maybe build an Oracle cloud service for building.

@brainchild0
Copy link

brainchild0 commented Nov 29, 2022

Is this not a reasonable workaround?

@thomaswue The question has no general answer. In some cases it may be, others not. My remark directed at cases for which the answer would be negative, while acknowledging others for which it would be more optimistic.

For some open source components or platforms, you build everything in one place from scratch (or take binaries if available, but reserve the capability to build). That's just how it is.

What is worth considering is that the limitation probably will make adoption more reluctant even in border cases, due to concerns about dependence on a tool limited in broader adoptability.

We could also maybe build an Oracle cloud service for building.

Such a process is suited to projects supported by the community but still distributed as prebuilt binaries targeting major platforms. It is obviously a common case, but not the only.

@brainchild0
Copy link

Not having any useful background on the subject, I am curious to ask about feasibility for running the tool version corresponding to the target platform inside Qemu.

@rmannibucau
Copy link

We believe however that many open source (and even commercial) projects can use our GitHub Action for GraalVM to build their releases. Is this not a reasonable workaround?

No because most of this solution wouldn't be free or too expensive, plus not usable in dev - without referencing projects not using Github, including on premise projects using Gitea/Drone or alike solutions. The key point is not NOT depend on a CI to be able to build. There are cases you want the release to be signed by an employe/user and not a technical key so for these cases you need an offline solution and hopefully local only (ie not multiple VM).

@brainchild0
Copy link

There can be differences between operating systems how the JDK or third-party library dependencies are initialized and those end up snapshotted into the native image. Therefore, the problem of cross compilation for native image is more difficult to solve than cross compilation for e.g. C programs.

@thomaswue So the NI tool interrogates the memory state of the running JDK, and captures a representation for inclusion into the build target? Is the captured image specific to the application being translated, or only to the combination of kernel and machine types?

@anentropic
Copy link

anentropic commented Dec 22, 2022

What is the primary source/destination architecture you would be interested in to cross-compile, is it Linux/amd64 to Linux/aarch64? Is it possible to solve your use case with the GitHub Action workaround?

For me it would be compiling macos/aarch64 on macos/x86_64

Because GitHub actions does not have aarch64 macos runners, and for an OSS hobby project I do not want to pay for hosted Apple Silicon runners

Since all new macs are aarch64 it no longer seems worth building native images with Graal as I had been, since I can only support obsolete platforms that way

@mikehearn
Copy link
Contributor

@rmannibucau

There are cases you want the release to be signed by an employe/user and not a technical key so for these cases you need an offline solution and hopefully local only (ie not multiple VM).

It's worth separating out the build from the release here. Whilst native-image can't cross-build, Conveyor can cross-package and cross-sign and is free for open source projects. So your pipeline could look like this:

  • Develop on regular JVM.
  • Compile with native-image using a multi-platform CI system (yes I know this is painful - I built one with home hardware to do this).
  • Write a Conveyor config that pulls the artifacts from your CI outputs and then produces signed, notarized binaries and packages from whatever local hardware you have your keys on. It supports HSMs.

@rmannibucau
Copy link

@mikehearn main point is to request a solution not depending on any CI like solution which are workarounds to this issue and do not cover all build/releases cases (not merging both cases but listing both as distinct but valid).

@mikehearn
Copy link
Contributor

Yes, but that may not arrive any time soon and wouldn't solve the signing or packaging aspects, you'd still need other tools for that. I mention it here as an answer to your second part, so people who want to distribute CLI or GUI tools to desktops with local signing can know where to look.

@thomaswue
Copy link
Member

@brainchild0 The state is specific to the application being translated.

In addition to this, we are depending on the local C developer tool chain a lot, so whatever cross-compilation combination we should support also needs to be available from that tool chain.

There is also the option to build within a docker container.

So, when looking at the existing workarounds such as Docker, GitHub Actions, Conveyor and the complexity of supporting all source/target platform combinations (with 5 supported platforms that would be 25), it seems like it would not be the best prioritization of engineering effort for the project at the moment. We will look more into build server setups that we can make available. Such a scenario can have additional advantages such as faster builds.

@rmannibucau
Copy link

All the mentionned solutions are at least as bad as requiring a local stack and most are more impacting like requiring to oss the project, to pay or just to not be able to run locally. All that are blockers to a solution to this issue so please invest in cross chains more than platforms which are just the current workaround.

@brainchild0
Copy link

In addition to this, we are depending on the local C developer tool chain a lot, so whatever cross-compilation combination we should support also needs to be available from that tool chain.

Such a constraint by itself is not particularly limiting. Cross-compilation solutions have evolved quite substantially in the past decade, and the dissociation between build environment and build target is now rather common, and available without penalty.

it seems like it would not be the best prioritization of engineering effort for the project at the moment.

As previously stated, it is a matter of context and perspective . For some projects, remote builds would be a tremendous help. For others, it has no value. I think it is not completely accurate that CI is a reasonable substitute for local availability of cross-building operations, in the general case.

@NCLnclNCL
Copy link

.

@chenzhiguo
Copy link

I wonder, is there any support for cross-compilation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests