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

openjdk8 compile statically #85902

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

hlolli
Copy link
Member

@hlolli hlolli commented Apr 24, 2020

EDITED 28/04/2020: I was able to solve the static compilation problem. With these changes I can finally compile graalvm native images. I didn't pay much attention to linting etc, so don't hesitate to ask questions about my decision or potential blunders. I will very likely need to make similar changes to jdk11, but this brings me step closer to getting graalvm 20 to compile on nixpkgs.

Preface: plz help and/or look over, I've been struggling with this for few days. I've been able to build openjdk8 statically with patches pointed out here graalvm/openjdk8-jvmci-builder#11 (comment) I've been successfull with both musl and gcc (I think I'll be focusing on gcc since the official CE is distributed with gcc, but this could be irrelevant). Ending with the same error over and over
[deleted]

Motivation for this change

As part of upgrading graalvm8, I will need to use statically compiled openjdk8 as basis for jvmci8 to build native-image/substratevm. I believe the same applies for openjdk11, but I haven't reached that far yet.

Things done
  • Added optional attribute "static" to openjdk8

  • Added patches needed to compile statically in gcc and musl (gcc should work fine as I write this, musl I haven't tested for few days, darwin-clang I never tried so far).

  • Bumped openjdk8 and adoptjdk-bin both to 252-b09

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)

  • Built on platform(s)

    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)

  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"

  • Tested execution of all binary files (usually in ./result/bin/)

  • Determined the impact on package closure size (by running nix path-info -S before and after)

  • Ensured that relevant documentation is up to date

  • Fits CONTRIBUTING.md.

@doronbehar
Copy link
Contributor

Maybe that's not a helpful advice but still: why aren't you using https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/static.nix ? At least to place there the dependencies you override... And there's also pkgsStatic.

@hlolli
Copy link
Member Author

hlolli commented Apr 26, 2020

@doronbehar I tested both with pkgsStatic and pkgsMusl but it doesn't matter in terms of this bug, and I think it doesn't make sense to call these packages as they increase the package size substantially, calling the dependencies individually, makes it possible to use the current stdenv throughout.

@hlolli
Copy link
Member Author

hlolli commented Apr 27, 2020

I think I've discovered the reason: oracle/graal#1755 (comment)

 a JDK built with --enable-static-build=yes should not even run. In any case, when building a labsjdk binary, we actually build the JDK twice. First with --enable-static-build=yes and then with --enable-static-build=no. The .a files from the first build are preserved and then overlayed on the result of the second built.

PR ready for review (description is modified above)

@hlolli hlolli changed the title (WIP)[help-wanted] openjdk8 compile statically openjdk8 compile statically Apr 27, 2020
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/issue-building-graalvm-19-2-1-dependency-for-the-clj-kondo-package/6932/4

Copy link
Contributor

@skykanin skykanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiled openjdk8 using static = true and it worked just fine on my laptop (although it took some time 😄 as to be expected). Also tested out resulting java and javac binaries with a simple hello world program. LGTM 👍

@FRidh FRidh added this to the 20.09 milestone Aug 15, 2020
@FRidh FRidh modified the milestones: 20.09, 21.03 Dec 20, 2020
@stale
Copy link

stale bot commented Jun 18, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 18, 2021
@Artturin Artturin modified the milestones: 21.05, 23.05 Dec 31, 2022
@stale stale bot removed 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md labels Dec 31, 2022
@Artturin Artturin marked this pull request as draft January 3, 2023 02:01
@Artturin Artturin removed this from the 23.05 milestone Jan 3, 2023
@Artturin
Copy link
Member

Artturin commented Jan 3, 2023

feel free to upstream the patches and rebase if you or someone wants to get this in nixpkgs

@Artturin Artturin added 6.topic: static 6.topic: java Including JDK, tooling, other languages, other VMs labels Jan 3, 2023
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants