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

Support native bignum (including static builds). #1568

Closed
wants to merge 2 commits into from

Conversation

mklca
Copy link
Contributor

@mklca mklca commented Jul 31, 2022

Enable BIGNUM_BACKEND=native support for GHC to avoid statically linking GMP (this could violate the LGPLv3 licensing of GMP).

The second patch corrects a typo in #1430.

@mklca
Copy link
Contributor Author

mklca commented Jul 31, 2022

I've got a working statically linked x86_64-unknown-linux-musl servant project working with these changes.

To use this in a flake, I've created a shim overlay ghcCompilerSettings:

    # overlays =
    {
      # …
      ghcCompilerSettings = let
        inherit (nixpkgs.lib.attrsets) mapAttrs recursiveUpdate;
        inherit (nixpkgs.lib.strings) hasPrefix;

        ghcOverrides = compiler-nix-name: attrs: attrs // {
          enableRelocatedStaticLibs = !attrs.enableShared or false;
          enableShared = attrs.enableShared or true;
        } // (if hasPrefix "ghc" compiler-nix-name && !hasPrefix "ghc8" compiler-nix-name then {
          enableNativeBignum = true;
        } else {
          enableIntegerSimple = true;
        });

        overrideHaskellNixCompilers = baseOverrides: pkgs: recursiveUpdate pkgs {
          haskell-nix.compiler =
            mapAttrs
            (cn: cpkg: cpkg.override (ghcOverrides cn baseOverrides))
            (nixpkgs.lib.attrsets.filterAttrs (
              n: nixpkgs.lib.trivial.const (n == haskellConfig.compiler-nix-name))
              pkgs.haskell-nix.compiler);
        };

        crossOverrides = {
          musl64 = {
            enableShared = false;
          };
        };
      in final: prev: recursiveUpdate (overrideHaskellNixCompilers {} prev) {
        pkgsCross = mapAttrs (n: v: overrideHaskellNixCompilers (crossOverrides.${n} or {}) v) prev.pkgsCross;
      };
      # …
    }

and then set up nixpkgs like this:

    import nixpkgs {
      inherit system;

      overlays = [
        haskellNix.overlay
        self.overlays.ghcCompilerSettings
        self.overlays.default
      ];
    }

@hamishmack
Copy link
Collaborator

bors try

iohk-bors bot added a commit that referenced this pull request Aug 1, 2022
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Aug 1, 2022

try

Timed out.

@hamishmack
Copy link
Collaborator

Merged in #1569.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants