Skip to content

Commit

Permalink
fix(dmd/binary): Ensure autoPatchelfHook is able to find `libgcc_s.…
Browse files Browse the repository at this point in the history
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
  • Loading branch information
PetarKirov committed Sep 20, 2023
1 parent 00ab6c7 commit 51483cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkgs/dmd/binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tzdata,
autoPatchelfHook,
fixDarwinDylibNames,
glibc,
gccForLibs,
version,
hashes,
}: let
Expand Down Expand Up @@ -37,7 +37,7 @@ in
lib.optional hostPlatform.isLinux autoPatchelfHook
++ lib.optional hostPlatform.isDarwin fixDarwinDylibNames;

propagatedBuildInputs = [curl tzdata] ++ lib.optional hostPlatform.isLinux glibc;
propagatedBuildInputs = [curl tzdata] ++ lib.optional hostPlatform.isLinux gccForLibs.libgcc;

installPhase = ''
runHook preInstall
Expand Down

0 comments on commit 51483cb

Please sign in to comment.