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

gradle: auto-detect native version and patch file-events #277721

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

liff
Copy link
Contributor

@liff liff commented Dec 30, 2023

Description of changes

Drop the requirement to specify the version of the native-platform library at Nix level. We use the non-platform-specific native-platform-<version>.jar to resolve the version of that library at fixup.

Hoping that we might be able to use nix-update-script to automate updates, but have not tested that yet.

I also noticed there is a bundled file-events library that requires libstdc++, so added a similar patch for that.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@liff liff requested a review from lorenzleutgeb December 30, 2023 12:54
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 11-100 10.rebuild-linux: 11-100 labels Dec 30, 2023
@liff
Copy link
Contributor Author

liff commented Feb 1, 2024

@lorenzleutgeb sorry to bother, but pinging in case you have time to take a peek.

@liff liff force-pushed the gradle/no-nativeVersion branch from daec92d to f7c0dfd Compare February 7, 2024 16:38
Copy link
Member

@lorenzleutgeb lorenzleutgeb left a comment

Choose a reason for hiding this comment

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

Builds and works on my machine. Thanks! I suggest to remove some redundancy (DRY, see comment) but could be merged as is.

popd
done

# The file-events library _seems_ to follow the native-platform version, but
# we won’t assume that.
fileEventsJar=$(basename $(ls -1 $out/lib/gradle/lib/file-events-*.jar | grep -Ev '.-(linux|osx|freebsd|windows)-'))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe define a function to get the version like this? It seems to be the same code in lines 81-83 above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a helper and switched to using autoPatchelf, since it does exactly what we need here.

@liff liff force-pushed the gradle/no-nativeVersion branch from f7c0dfd to 1bb4d47 Compare February 13, 2024 20:48
@liff liff requested a review from lorenzleutgeb February 13, 2024 20:50
@wegank wegank added 12.approvals: 1 This PR was reviewed and approved by one reputable person 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package labels Mar 8, 2024
@liff liff force-pushed the gradle/no-nativeVersion branch from 1bb4d47 to c326ee4 Compare March 25, 2024 07:24
@ofborg ofborg bot requested a review from lorenzleutgeb March 25, 2024 07:48
@liff liff force-pushed the gradle/no-nativeVersion branch from c326ee4 to 8e9523e Compare March 25, 2024 17:15
@liff liff force-pushed the gradle/no-nativeVersion branch from 8e9523e to 5cfb74b Compare April 3, 2024 10:07
@ofborg ofborg bot requested a review from lorenzleutgeb April 3, 2024 10:33
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Apr 4, 2024
@lorenzleutgeb
Copy link
Member

Result of nixpkgs-review pr 277721 run on x86_64-linux 1

3 packages marked as broken and skipped:
  • frostwire
  • javaPackages.openjfx15
  • openjfx15
11 packages failed to build:
  • bisq-desktop
  • corretto11
  • corretto11.debug
  • corretto17
  • corretto17.debug
  • corretto19
  • corretto19.debug
  • ganttproject-bin
  • gscan2pdf
  • gscan2pdf.man
  • moneydance
65 packages built:
  • apkleaks
  • apkleaks.dist
  • apksigcopier
  • apksigcopier.dist
  • apksigner
  • armitage
  • bluej
  • cie-middleware-linux
  • cryptomator
  • diffoscope
  • diffoscope.dist
  • diffoscope.man
  • experienced-pixel-dungeon
  • fastddsgen
  • fdroidserver
  • fdroidserver.dist
  • freenet
  • freeplane
  • ghidra
  • gradle (gradle_8)
  • gradle_6
  • gradle_7
  • greenfoot
  • jabref
  • jadx
  • openjfx11 (javaPackages.openjfx11)
  • openjfx (javaPackages.openjfx17 ,openjfx17)
  • openjfx19 (javaPackages.openjfx19)
  • openjfx20 (javaPackages.openjfx20)
  • openjfx21 (javaPackages.openjfx21)
  • openjfx22 (javaPackages.openjfx22)
  • jd-gui
  • jextract
  • jextract-21
  • key
  • kotlin-language-server
  • ma1sd
  • maptool
  • mcaselector
  • microsoft-identity-broker
  • mindustry
  • mindustry-server
  • mindustry-wayland
  • mucommander
  • ns-usbloader
  • olvid
  • pattypan
  • pdf-sign
  • pdfchain
  • pdfsam-basic
  • pdftk
  • pidginPackages.purple-signald
  • quark-goldleaf
  • rat-king-adventure
  • rkpd2
  • scenebuilder
  • scenic-view
  • shattered-pixel-dungeon
  • shorter-pixel-dungeon
  • signald
  • signaturepdf
  • sparrow
  • sparrow-unwrapped
  • stirling-pdf
  • summoning-pixel-dungeon

@lorenzleutgeb
Copy link
Member

Successes

Results gradle{,_{6,7}}/bin/gradle all execute fine.

Failures

gscan2pdf

2/1171 tests failed, I don't see how they are related. See gscan2pdf.log.

corretto*

Compilations warnings (errors?) don't see how these are related:

ganttproject-bin, moneydance

Logs are empty.

@lorenzleutgeb
Copy link
Member

@ofborg build gscan2pdf bisq-desktop corretto11 corretto17 corretto19 ganttproject-bin moneydance

Copy link
Contributor

@raphiz raphiz left a comment

Choose a reason for hiding this comment

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

I had a look at the code and tried it out and it looks great 👍️

I also grepped through all jar files in the latest gradle distribution (gradle-8.7-bin.zip) and found some other native libraries - not sure if we should/must patch them as well:

  • libjansi.so in jansi-1.18.jar and kotlin-compiler-embeddable-1.9.22.jar
  • liblz4-java.so in kotlin-compiler-embeddable-1.9.22.jar

I haven't had any issues so far without it being patched 🤷

shift
local candidates="$@"

jar="$(basename $(ls -1 "$@" | grep -Ev '.-(linux|osx|freebsd|windows)-'))"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can simply rely on sort for this, no?

Suggested change
jar="$(basename $(ls -1 "$@" | grep -Ev '.-(linux|osx|freebsd|windows)-'))"
jar="$(basename -a $candidates | sort | head -n1)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied.

popd
autoPatchelfInJar \
$out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \
"${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know too much about elf patching - but this looks reasonable to me🤷

mv native-platform-linux-${arch}$variant-${nativeVersion}.jar $out/lib/gradle/lib/
popd
autoPatchelfInJar \
$out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for the record - this is "just" patching the linux version (as it was done before).
As others told me, the resulting nix package works on macOS too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, patchelf is a Linux-only thing, AFAIK.

@liff
Copy link
Contributor Author

liff commented May 30, 2024

As far as I can tell, patchelf doesn’t do anything to the dynamic libraries bundled with the Kotlin compiler. I think the reason is that those libraries only require glibc.

@liff liff force-pushed the gradle/no-nativeVersion branch from 5cfb74b to 4a7a7ab Compare May 30, 2024 17:24
@liff liff requested a review from raphiz May 30, 2024 17:25
@liff liff mentioned this pull request Jun 3, 2024
13 tasks
@lorenzleutgeb
Copy link
Member

lorenzleutgeb commented Jun 3, 2024

I'd like to get this in but am a little hesitant because of the build failures. Re-running nixpkgs-review at the moment, it's not done but gscan2pdf tests fail and one probably unrelated failure for OpenJFX:

error: builder for '/nix/store/w0r4l7pk1n1dqfh3s5rxx77nilc29d5x-openjfx-modular-sdk-17.0.11-ga.drv' failed with exit code 1;
       last 30 log lines:
       > * Where:
       > Build file '/build/source/build.gradle' line: 3513
       >
       > * What went wrong:
       > A problem occurred evaluating root project 'source'.
       > > Could not resolve all files for configuration ':web:icu'.
       >    > Could not resolve :icu4c-73_1-data-bin-l.
       >      Required by:
       >          project :web
       >       > Could not resolve :icu4c-73_1-data-bin-l.
       >          > Could not get resource 'https://download.eclipse.org/eclipse/updates/4.6/R-4.6.3-201703010400/plugins/icu4c-73_1-data-bin-l.zip'.
       >             > Could not HEAD 'https://download.eclipse.org/eclipse/updates/4.6/R-4.6.3-201703010400/plugins/icu4c-73_1-data-bin-l.zip'.
       >                > download.eclipse.org

Edit: Results are in. I don't really understand what's the problem with gscan2pdf and corretto11. But corretto17 builds, so maybe we can ignore it?

Result of nixpkgs-review pr 277721 run on x86_64-linux 1

8 packages marked as broken and skipped:
  • corretto19
  • corretto19.debug
  • javaPackages.openjfx15
  • javaPackages.openjfx19
  • javaPackages.openjfx20
  • openjfx15
  • openjfx19
  • openjfx20
7 packages failed to build:
  • bluej
  • corretto11
  • corretto11.debug
  • greenfoot
  • gscan2pdf
  • gscan2pdf.man
  • scenic-view
71 packages built:
  • apkleaks
  • apkleaks.dist
  • apksigcopier
  • apksigcopier.dist
  • apksigner
  • armitage
  • autopsy
  • bisq-desktop
  • cie-middleware-linux
  • corretto17
  • corretto17.debug
  • corretto21
  • corretto21.debug
  • cryptomator
  • diffoscope
  • diffoscope.dist
  • diffoscope.man
  • experienced-pixel-dungeon
  • fastddsgen
  • fdroidserver
  • fdroidserver.dist
  • freenet
  • freeplane
  • ganttproject-bin
  • ghidra
  • ghidra-extensions.gnudisassembler
  • ghidra-extensions.machinelearning
  • ghidra-extensions.sleighdevtools
  • gradle (gradle_8)
  • gradle_6
  • gradle_7
  • jabref
  • jadx
  • openjfx11 (javaPackages.openjfx11)
  • openjfx (javaPackages.openjfx17 ,openjfx17)
  • openjfx21 (javaPackages.openjfx21)
  • openjfx22 (javaPackages.openjfx22)
  • jd-gui
  • jextract
  • jextract-21
  • key
  • kotlin-language-server
  • ma1sd
  • maptool
  • mcaselector
  • microsoft-identity-broker
  • mindustry
  • mindustry-server
  • mindustry-wayland
  • moneydance
  • mucommander
  • ns-usbloader
  • olvid
  • pattypan
  • pdf-sign
  • pdfchain
  • pdfsam-basic
  • pdftk
  • pidginPackages.purple-signald
  • quark-goldleaf
  • rat-king-adventure
  • rkpd2
  • scenebuilder
  • shattered-pixel-dungeon
  • shorter-pixel-dungeon
  • signald
  • signaturepdf
  • sparrow
  • sparrow-unwrapped
  • stirling-pdf
  • summoning-pixel-dungeon

scenic-view.log
gscan2pdf.log
corretto11.log

@lorenzleutgeb lorenzleutgeb added needs_merger (old Marvin label, do not use) 6.topic: java Including JDK, tooling, other languages, other VMs 12.approvals: 2 This PR was reviewed and approved by two reputable people 0.kind: enhancement Add something new labels Jun 3, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 4, 2024
@liff liff force-pushed the gradle/no-nativeVersion branch from 4a7a7ab to 9e7243c Compare July 20, 2024 09:26
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 20, 2024
@ofborg ofborg bot requested a review from lorenzleutgeb July 20, 2024 10:01
@adamcstephens
Copy link
Contributor

Will need a rebase if still desired.

liff added 2 commits September 9, 2024 18:21
Instead of having to know the version of native-platform at the Nix
level, we use the file `lib/native-platform-<version>.jar` to figure
out the version of the library JAR to patch.
It depends on libstdc++, so add that to its RPATH.
@liff liff force-pushed the gradle/no-nativeVersion branch from 9e7243c to bd244e7 Compare September 9, 2024 15:21
@ofborg ofborg bot requested a review from lorenzleutgeb September 9, 2024 16:24
@liff
Copy link
Contributor Author

liff commented Sep 9, 2024

@adamcstephens rebased, thanks.

@adamcstephens adamcstephens merged commit 392bc9a into NixOS:master Sep 11, 2024
24 of 26 checks passed
@liff liff deleted the gradle/no-nativeVersion branch November 14, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement Add something new 6.topic: java Including JDK, tooling, other languages, other VMs 10.rebuild-darwin: 11-100 10.rebuild-linux: 11-100 11.by: package-maintainer This PR was created by the maintainer of the package it changes 12.approvals: 2 This PR was reviewed and approved by two reputable people 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package needs_merger (old Marvin label, do not use)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants