Skip to content

haskell-modules/generic-builder.nix: work around useSystemCoreFoundationFramework hook#329526

Merged
vcunat merged 1 commit intoNixOS:staging-nextfrom
reckenrode:haskell-rpath-hackery
Jul 24, 2024
Merged

haskell-modules/generic-builder.nix: work around useSystemCoreFoundationFramework hook#329526
vcunat merged 1 commit intoNixOS:staging-nextfrom
reckenrode:haskell-rpath-hackery

Conversation

@reckenrode
Copy link
Contributor

Fixes some Haskell build failures on x86_64-darwin on staging-next #328673.

In 23.11, Darwin was changes to use the system CoreFoundation both aarch64-darwin and x86_64-darwin. The ability to change between implementations was removed, but the hook was left in place because at the time it was harmless. Unfortunately, that is no longer the case.

After the upgrade of ld64 to 951.9, it is no longer as permissive about when -rpath may be used. It no longer allows the flag to be used when targeting macOS 10.5, and it no longer allows it when merging objects. The former was an issue for certain versions of GCC (now fixed). The latter is an issue for Haskell.

When a Haskell project uses Darwin frameworks and Cabal to build, they will fail to build without this workaround, giving the following error.

ld: -rpath can only be used when creating a dynamic final linked image

This is due to an optimization Cabal performs. If the linker supports creating relocatable objects or merging them, it will do so eagerly. This causes packages such as OpenGLRaw to fail to build due using Cabal and frameworks (OpenGL), which pull in the hook.

This workaround is ugly, but it will be reverted as soon as it hits staging and replaced with the real solution, which is removing the hook. The hook is only used with the 10.12 SDK. The 11.0 and 12.3 SDKs do not support the hook, and being able to switch CoreFoundation implementations is not anticipated to be restored in the future (due to problems it causes).

Description of changes

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.11 Release Notes (or backporting 23.11 and 24.05 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.

In 23.11, Darwin was changes to use the system CoreFoundation both aarch64-darwin and x86_64-darwin. The ability to change between implementations was removed, but the hook was left in place because at the time it was harmless. Unfortunately, that is no longer the case.

After the upgrade of ld64 to 951.9, it is no longer as permissive about when `-rpath` may be used. It no longer allows the flag to be used when targeting macOS 10.5, and it no longer allows it when merging objects. The former was an issue for certain versions of GCC (now fixed). The latter is an issue for Haskell.

When a Haskell project uses Darwin frameworks and Cabal to build, they will fail to build without this workaround, giving the following error.

    ld: -rpath can only be used when creating a dynamic final linked image

This is due to an optimization Cabal [performs][1]. If the linker supports creating relocatable objects or merging them, it will do so eagerly. This causes packages such as OpenGLRaw to fail to build due using Cabal and frameworks (OpenGL), which pull in the hook.

This workaround is ugly, but it will be reverted as soon as it hits staging and replaced with the real solution, which is removing the hook. The hook is only used with the 10.12 SDK. The 11.0 and 12.3 SDKs do not support the hook, and being able to switch CoreFoundation implementations is not anticipated to be restored in the future (due to problems it causes).

[1]: https://github.com/haskell/cabal/blob/705b6ebcaed649ed1a30b138b4348d24722d610a/Cabal/src/Distribution/Simple/Program/Builtin.hs#L341-L380
@github-actions github-actions bot added the 6.topic: haskell General-purpose, statically typed, purely functional programming language label Jul 23, 2024
@reckenrode reckenrode changed the title haskell-builder.nix: work around useSystemCoreFoundationFramework hook haskell-modules/generic-builder.nix: work around useSystemCoreFoundationFramework hook Jul 23, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jul 24, 2024
@vcunat vcunat merged commit 52cd081 into NixOS:staging-next Jul 24, 2024
@vcunat
Copy link
Member

vcunat commented Jul 24, 2024

This is another example, with dozens of builds depending on it: https://hydra.nixos.org/build/267146859

@reckenrode reckenrode deleted the haskell-rpath-hackery branch July 24, 2024 05:31
reckenrode added a commit to reckenrode/nixpkgs that referenced this pull request Jul 25, 2024
Similar issue as NixOS#329526. Ruby 3.3 attempts to merge objects during the build, which fails due to stricter handling of `-rpath` in ld64.
reckenrode added a commit to reckenrode/nixpkgs that referenced this pull request Jul 26, 2024
Darwin no longer supports switching between CoreFoundation implementations as of NixOS#265102. The setup hook is vestigial and was mostly harmless until NixOS#329526 was necessitated to fix build failures on staging-next NixOS#328673.

The correct fix is to remove the hook. It’s not used by the 11.0 or 12.3 SDKs. This makes the 10.12 SDK a bit more like the other SDKs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: haskell General-purpose, statically typed, purely functional programming language 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants