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

Java toolchain: remote java tools don't work on NixOS #278

Closed
tshaynik opened this issue Nov 9, 2022 · 3 comments · Fixed by #451
Closed

Java toolchain: remote java tools don't work on NixOS #278

tshaynik opened this issue Nov 9, 2022 · 3 comments · Fixed by #451
Labels
P2 major: an upcoming release type: bug

Comments

@tshaynik
Copy link
Contributor

tshaynik commented Nov 9, 2022

Describe the bug
Java toolchain: //tests:java-runtime fails on NixOS. This is because all of the tools installed by the java toolchain (defined in toolchains/java/defautl_java_toolchain.bzl

To Reproduce

On NixOS:

$ nix develop
$ cd toolchains/java
$ bazel test //tests:

INFO: Analyzed target //tests:java-test (4 packages loaded, 772 targets configured).
INFO: Found 1 test target...
ERROR: /home/tshaynik/.cache/bazel/_bazel_tshaynik/e5bd6e49bddd284fa0b5cbd8cd3797db/external/bazel_tools/tools/jdk/BUILD:289:12: Extracting interface @bazel_tools//tools/jdk:TestRunner failed: (Exit 1): ijar failed: error executing command external/remote_java_tools_linux/java_tools/ijar/ijar external/remote_java_tools/java_tools/Runner_deploy.jar ... (remaining 3 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox
src/main/tools/linux-sandbox-pid1.cc:478: "execvp(external/remote_java_tools_linux/java_tools/ijar/ijar, 0x99dcb0)": No such file or directory
Target //tests:java-test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.212s, Critical Path: 0.01s
INFO: 4 processes: 4 internal.
FAILED: Build did NOT complete successfully
//tests:java-test                                               FAILED TO BUILD

$ bazel-java/external/remote_java_tools_linux/java_tools/ijar/ijar
zsh: no such file or directory: bazel-java/external/remote_java_tools_linux/java_tools/ijar/ijar

$ ldd bazel-java/external/remote_java_tools_linux/java_tools/ijar/ijar
        linux-vdso.so.1 (0x00007fff7a9aa000)
        libstdc++.so.6 => not found
        libm.so.6 => /nix/store/v6szn6fczjbn54h7y40aj7qjijq7j6dc-glibc-2.34-210/lib/libm.so.6 (0x00007f2efbf6c000)
        libgcc_s.so.1 => /nix/store/v6szn6fczjbn54h7y40aj7qjijq7j6dc-glibc-2.34-210/lib/libgcc_s.so.1 (0x00007f2efbf52000)
        libc.so.6 => /nix/store/v6szn6fczjbn54h7y40aj7qjijq7j6dc-glibc-2.34-210/lib/libc.so.6 (0x00007f2efbd54000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/v6szn6fczjbn54h7y40aj7qjijq7j6dc-glibc-2.34-210/lib64/ld-linux-x86-64.so.2 (0x00007f2efc047000)

Expected behavior

All binaries installed by the java toolchain should work on NixOS.
The java-test target should run correctly and pass on NixOS.

Environment

  • OS name + version: NixOS 22.05
  • Version of the code: 374f7c8 (master as of November 9, 2022)

Additional context

I was looking into an issue causing this test to fail on MacOS for #273, and I found that that test doesn't work on NixOS on master either, for unrelated reasons.
The tools affected are defined in toolchains/java/default_java_toolchain.bzl: ijar and singlejar have the same issue.
It's possible to set LDPATH as a shellHook in flake.nix:

          shellHook = ''
            export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH 
          '';

This causes ldd to resolve libstdc++.so.6 => /nix/store/8mhaj6yvvb7rq0kl5xmg6wl9myxvs804-gcc-11.3.0-lib/lib/libstdc++.so.6 (0x00007f10b2336000), but the executable still fails.

@aherrmann
Copy link
Member

This sounds like the classical NixOS dynamic loader issue, NixOS/nixpkgs#107375.
At a glance this could be a toolchain resolution issue - it picks a bindist toolchain when it should pick a nixpkgs provided one or build these tools from source;
or a patchelf issue - maybe there are extra binaries that the bazel nixpkgs expression needs to patchelf.

@tshaynik
Copy link
Contributor Author

Yeah, I've been trying to Patchelf it, but I don't think I have the args right!

@benradf benradf added P3 minor: not priorized P2 major: an upcoming release and removed P3 minor: not priorized labels Aug 3, 2023
@iphydf
Copy link

iphydf commented Nov 22, 2023

+1 to this issue.

I get this error:

/nix/store/rhvbjmcfnkg8i2dxpzr114cp1ws7f667-bash-5.2-p15/bin/bash: line 28: external/remote_java_tools_linux/java_tools/src/tools/singlejar/singlejar_local: cannot execute: required file not found

I can manually execute it like this:

$ LD_LIBRARY_PATH=/nix/store/yazs3bdl481s2kyffgsa825ihy1adn8f-gcc-12.2.0-lib/lib /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 external/remote_java_tools_linux/java_tools/src/tools/singlejar/singlejar_local 
singlejar_local: Use --output <output_jar> to specify the output file name

I can manually patchelf it like this:

nix-shell -p patchelf --run "patchelf --set-interpreter /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 --add-rpath /nix/store/yazs3bdl481s2kyffgsa825ihy1adn8f-gcc-12.2.0-lib/lib external/remote_java_tools_linux/java_tools/src/tools/singlejar/singlejar_local"

After which it works fine.

avdv added a commit that referenced this issue Nov 23, 2023
On NixOS we cannot use the pre-built `ijar` and `singlejar` tools as they are not
statically build and fail to find the dynamic linker.

Fixes #278
@mergify mergify bot closed this as completed in #451 Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 major: an upcoming release type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants