From 061f70f8f76249394cff90019ce36593d42a1bb8 Mon Sep 17 00:00:00 2001 From: Guillaume Girol Date: Thu, 5 Aug 2021 12:00:00 +0000 Subject: [PATCH] ocaml: fix static compilation on recent versions --- pkgs/development/compilers/ocaml/generic.nix | 12 +++++++++++- pkgs/top-level/static.nix | 15 +-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/pkgs/development/compilers/ocaml/generic.nix b/pkgs/development/compilers/ocaml/generic.nix index 2dd959600eac..fb1eddc6a622 100644 --- a/pkgs/development/compilers/ocaml/generic.nix +++ b/pkgs/development/compilers/ocaml/generic.nix @@ -56,7 +56,15 @@ stdenv.mkDerivation (args // { ++ optional aflSupport (flags "--with-afl" "-afl-instrument") ++ optional flambdaSupport (flags "--enable-flambda" "-flambda") ++ optional spaceTimeSupport (flags "--enable-spacetime" "-spacetime") - ; + ++ optional (stdenv.hostPlatform.isStatic && (lib.versionOlder version "4.08")) "-no-shared-libs" + ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform && lib.versionOlder version "4.08") [ + "-host ${stdenv.hostPlatform.config}" + "-target ${stdenv.targetPlatform.config}" + ]; + dontAddStaticConfigureFlags = lib.versionOlder version "4.08"; + configurePlatforms = lib.optionals (lib.versionAtLeast version "4.08") [ "host" "target" ]; + # x86_64-unknown-linux-musl-ld: -r and -pie may not be used together + hardeningDisable = lib.optional (lib.versionAtLeast version "4.09" && stdenv.hostPlatform.isMusl) "pie"; buildFlags = [ "world" ] ++ optionals useNativeCompilers [ "bootstrap" "world.opt" ]; buildInputs = optional (!lib.versionAtLeast version "4.07") ncurses @@ -70,6 +78,8 @@ stdenv.mkDerivation (args // { # Do what upstream does by default now: https://github.com/ocaml/ocaml/pull/10176 # This is required for aarch64-darwin, everything else works as is. AS="${stdenv.cc}/bin/cc -c" ASPP="${stdenv.cc}/bin/cc -c" + '' + optionalString (lib.versionOlder version "4.08" && stdenv.hostPlatform.isStatic) '' + configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r") ''; postBuild = '' mkdir -p $out/include diff --git a/pkgs/top-level/static.nix b/pkgs/top-level/static.nix index 73fe6dbc8363..344ce47fc2ae 100644 --- a/pkgs/top-level/static.nix +++ b/pkgs/top-level/static.nix @@ -61,20 +61,7 @@ self: super: let super // { lablgtk = null; # Currently xlibs cause infinite recursion - ocaml = ((super.ocaml.override { useX11 = false; }).overrideAttrs (o: { - configurePlatforms = [ ]; - dontUpdateAutotoolsGnuConfigScripts = true; - })).overrideDerivation (o: { - preConfigure = '' - configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r") - ''; - dontAddStaticConfigureFlags = true; - configureFlags = [ - "--no-shared-libs" - "-host ${o.stdenv.hostPlatform.config}" - "-target ${o.stdenv.targetPlatform.config}" - ]; - }); + ocaml = super.ocaml.override { useX11 = false; }; }; in {