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

openjdk: enable bootstrapping on ARM #65247

Merged
merged 10 commits into from Aug 20, 2019
Merged

Conversation

lopsided98
Copy link
Contributor

@lopsided98 lopsided98 commented Jul 22, 2019

Motivation for this change

I started out with the goal of adding support for 32-bit ARM to adoptopenjdk-bin, but then quickly realized that this binary package could be used to bootstrap the OpenJDK build on these platforms. This led to me also making a lot of changes to clean up the OpenJDK packages.

Things done

This PR makes openjdk8 and openjdk11 use adoptopenjdk-bin for bootstrapping. AdoptOpenJDK is a well-known organization that provides prebuilt OpenJDK binaries for many architectures. Their build scripts are open source and their infrastructure is publicly visible, which I believe makes Nix's OpenJDK bootstrapping process more transparent and trustworthy than the status quo, which uses a bootstrapping tarball of undocumented origin. From a technical standpoint, AdoptOpenJDK binaries make it easier to bootstrap OpenJDK on more platforms.

While I was working on this, I tried to clean up parts of the packages that I believe are no longer necessary or could be done better, but in doing so I there is the possibility that I broke something. Are there any particularly problematic packages I should test?

Testing
x86_64-linux i686-linux aarch64-linux armv6l-linux armv7l-linux
openjdk8 ✔️ ✔️ ✔️ 🚫 🚫
openjdk8_headless ✔️ ✔️ ✔️ 🚫 🚫
openjdk11 ✔️ 1 ✔️ ✔️ ✔️
openjdk11_headless ✔️ ✔️ ✔️ ✔️ ✔️
bazel ✔️ ✔️
jmeter ✔️
jetbrains.idea-community2 ✔️
javaPackages ✔️

✔️ = builds and runs
❌ = fails to build
🚫 = not supported
blank = not tested

1openjfx11 (and therefore openjdk11) fails to build on i686-linux for non-obvious reasons, even without this PR, and I did not try to fix it.

2Overridden to use OpenJDK 11 built from source

I do not have the ability to test on macOS, but I did not really touch anything Darwin related.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nix-review --run "nix-review wip"
  • Tested execution of binary files (usually in ./result/bin/) (I didn't test every single binary)
  • 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.

@lopsided98
Copy link
Contributor Author

Some other notes:

openjfx11 does not support ARM, but Debian has some patches that add support. I spent a little time trying to integrate them, but gave up because my aarch64 machines don't have enough RAM and there were strange errors on 32-bit ARM.

OpenJDK 8 does not directly support ARM, but there is an upstream branch (which is used by AdoptOpenJDK for their builds) which supports aarch64. Again, Debian has some patches that make it work on 32-bit ARM, but I did not try to integrate them.

@lheckemann
Copy link
Member

gave up because my aarch64 machines don't have enough RAM

Are you aware of the community builder? https://github.com/nix-community/aarch64-build-box

@lopsided98
Copy link
Contributor Author

Yes, I thought about trying the community builder, but I was getting kind of tired of working on this PR and I didn't really like the idea of cluttering nixpkgs with a bunch of patches for a feature that likely gets little use.

Copy link
Member

@timokau timokau left a comment

Choose a reason for hiding this comment

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

LGTM after some superficial review. I don't know anything about jdk bootstrapping, so I can't greenlight this on my own in good conscience. But this looks like a great improvement, thank you for this!

Some nitpicks included.

rm $out/lib/libfreetype.so

# for backward compatibility
ln -s $out $out/jre
Copy link
Member

Choose a reason for hiding this comment

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

Do we not need this backwards compatibility any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't figure out what the backwards compatibility concern was here, since openjdk11 does not have this symlink. Also, users are unlikely to use adoptopenjdk directly anymore, so I felt that backwards compatibility was less important.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe @taku0 who added the line initially has an opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oracle JDK and other JDKs had jre folder and some packages depend on it. I forgot which packages depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If openjdk11 doesn't have it, and no one's complaining, then I don't think adoptopenjdk needs it either.

@timokau
Copy link
Member

timokau commented Aug 7, 2019

CC @taku0 who init'ed adoptopenjdk and may be able to provide a more useful review. Also @bennofs, @tomfitzhenry, @wkennington, @NeQuissimus, @thoughtpolice as a semi-random sample of people intereseted in (adopt-)openjdk according to git shortlog. Hopefully we'll be able to keep this from bitrotting too badly :)

@taku0
Copy link
Contributor

taku0 commented Aug 10, 2019

Running a simple AWT application results in NullPointerException:

Caused by: java.lang.NullPointerException
        at java.desktop/sun.awt.FontConfiguration.getVersion(Unknown Source)
        at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(Unknown Source)
        at java.desktop/sun.awt.FontConfiguration.init(Unknown Source)
        at java.desktop/sun.awt.X11FontManager.createFontConfiguration(Unknown Source)
        at java.desktop/sun.font.SunFontManager$2.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/sun.font.SunFontManager.<init>(Unknown Source)
        at java.desktop/sun.awt.FcFontManager.<init>(Unknown Source)
        at java.desktop/sun.awt.X11FontManager.<init>(Unknown Source)
        ... 73 more

May or may not related to adoptium/temurin-build#693.

Reverting autoPatchelf to manual patchelf and adding fontconfig to the buildInput fixes this (I don't know why).
https://gist.github.com/taku0/74fe5aba9e9230b363dc8a19fc7c07f1

@lopsided98
Copy link
Contributor Author

I fixed the fontconfig issue. There are a few other libraries that could use a similar fix (e.g. gtk3), but they shouldn't cause any crashes, just missing features such as native look and feel. Now that we have normal OpenJDK builds for all platforms that AdoptOpenJDK supports, very few users will need to use AdoptOpenJDK, so these features will probably not be missed.

I have tested with the example @taku0 posted, as well with some JavaFX examples I found here: https://github.com/callicoder/javafx-examples

@flokli flokli requested a review from andir August 12, 2019 11:01
@grahamc
Copy link
Member

grahamc commented Aug 12, 2019

@GrahamcOfBorg eval

@timokau
Copy link
Member

timokau commented Aug 14, 2019

@lopsided98 would you mind rebasing this on current master? I don't know why ofBorg complains about a chromium trace, I can only assume it was an issue with the version of master this PR was branched off of.

@lopsided98
Copy link
Contributor Author

I rebased it, but it didn't fix anything. I think ofborg merges the PR into master before testing, so it shouldn't matter what commit it is based on.

@timokau
Copy link
Member

timokau commented Aug 15, 2019

Okay looks like this line is causing the trace:

] ++ optionals (!stdenv.cc.isClang && (versionRange "71" "72")) [

Which complains because the current oldest chromium version in nixpkgs is 76, so there is no point in keeping that old patch.

What I don't understand is why the trace only appears on this PR. It should pop up every time you eval chromium on a non-clang machine (e.g. x86 linux). What would make more sense is the patch below that, which is aarch64 specific. Aarch64 chromium probably wasn't eval'd by ofBorg before because the jdk was unfree and the aarch64 specific patch is also for an outdated version. But that is not the one the trace complains about.

@lopsided98 maybe just remove both outdated patches?

(CC chromium maintainers @bendlas @ivan)

@timokau
Copy link
Member

timokau commented Aug 16, 2019

I would argue that other chromium changes don't need to be included in this PR, removing the patches was only necessary to appease ofBorg. Any other cleanup can be done in followup PRs.

Any objections to merging this as-is? @taku0 I'd especially appreciate a final comment from you, since you did a lot of the prior work and had some comments that are (I think) resolved.

@ivan
Copy link
Member

ivan commented Aug 16, 2019

I am a nixpkgs chromium maintainer and that chromium change is fine with me.

@timokau
Copy link
Member

timokau commented Aug 16, 2019

I just noticed this targets master. It should probably target staging instead, both for the relatively high rebuild count and the additional testing.

@taku0
Copy link
Contributor

taku0 commented Aug 16, 2019

AdoptOpenJDK seems to be fine.

@timokau
Copy link
Member

timokau commented Aug 19, 2019

@volth for what it's worth, I built jvmci8 on x86 locally. Not sure if I tested it on aarch64. I suspect ofBorg will time out.

@lopsided98
Copy link
Contributor Author

I haven't really addressed the valgrind-light availability check, because I don't know that the proper solution is. Other than that I think this is ready.

@lheckemann lheckemann added this to the 19.09 milestone Aug 20, 2019
@timokau
Copy link
Member

timokau commented Aug 20, 2019

@matthewbauer @volth objections to merge?

@timokau
Copy link
Member

timokau commented Aug 20, 2019

graalvm builds on x86 (while eating a TON of ram, wow). Thanks again @lopsided98 for taking on this PR.

@timokau timokau merged commit c5c4720 into NixOS:staging Aug 20, 2019
@lopsided98 lopsided98 deleted the openjdk-arm branch August 27, 2019 18:18
@FRidh
Copy link
Member

FRidh commented Aug 31, 2019

This broke the tarball job on staging. Please fix because it would block the next staging -> staging-next merge.
https://hydra.nixos.org/build/98995742

@timokau
Copy link
Member

timokau commented Aug 31, 2019

Apparently for some reason openjdk11.meta.license cannot be found (no attribute license). Not sure why, but a hotfix would probably be to specify the license in jfx11 explicitly. I don't currently have time to make a PR, will you take this on @lopsided98?

@lopsided98
Copy link
Contributor Author

lopsided98 commented Aug 31, 2019

openjdk11 on macOS is a Zulu JDK build (https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/openjdk/darwin/11.nix) which does not have a license attribute. It's probably less error prone to just give OpenJFX its own license attribute, but I'll add the license to the macOS JDK as well.

On a related note, it would probably make sense to use AdoptOpenJDK instead of Zulu on macOS, but I don't have any macOS machines so I can't do it myself.

@lopsided98 lopsided98 mentioned this pull request Aug 31, 2019
10 tasks
@lopsided98
Copy link
Contributor Author

See #67839

@timokau
Copy link
Member

timokau commented Sep 1, 2019

@grahamc shouldn't ofBorg have caught this? Its essentially an eval failure on mac, isn't it?

@vcunat
Copy link
Member

vcunat commented Sep 8, 2019

Any idea why this MR introduced this channel-blocking breakage? #68307

@fgaz
Copy link
Member

fgaz commented Sep 10, 2019

I think this PR broke all gradle-based packages, specifically commit de5e65a (found by bisecting).

I am getting this error:

> Task :PD-classes:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':PD-classes:compileJava'.
> Could not find tools.jar. Please check that /nix/store/6l52g0dy4v2wrxjwrphcsl7wzf3brb9w-openjdk-8u212-ga-jre/lib/openjdk/jre contains a valid JDK installation.

For some reason gradle seems to use the jre instead of the jdk regardless of the java parameter.

@lopsided98
Copy link
Contributor Author

@fgaz #68442 should fix it

preFixup = ''
prefix=$jre stripDirs "$STRIP" "$stripDebugList" "''${stripDebugFlags:--S}"
patchELF $jre
propagatedBuildInputs+=" $jre"
Copy link
Member

@Ma27 Ma27 Sep 15, 2019

Choose a reason for hiding this comment

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

The JRE inputs need to be propagated to jdk as well to ensure that the setJavaClassPath hook is used.
This breaks for instance scalafmt and scalafix:

related to ZHF #68361

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