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

Fix static building for ocaml-ng #73820

Merged
merged 16 commits into from Dec 2, 2019
Merged

Conversation

balsoft
Copy link
Member

@balsoft balsoft commented Nov 20, 2019

Motivation for this change

Currently attempting to build pkgsStatic.ocaml and friends fails miserably. This PR:

  • Adds a static adapter that fixes ocaml and some subset of ocamlPackages
  • Fixes some individual packages from ocamlPackages

I am not sure that the adapter should go in top-level/static.nix, if it belongs in development/compilers/ocaml/generic.nix, then it's pretty easy to move it there.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @vbgl @regnat

@balsoft balsoft changed the title Static fixes Fix static building for ocaml-ng Nov 20, 2019
@vbgl
Copy link
Contributor

vbgl commented Nov 21, 2019

Naive question after a quick look at the changes: why is findlib often both in buildInputs and nativeBuildInputs?

@balsoft
Copy link
Member Author

balsoft commented Nov 21, 2019

@vbgl Because it doesn't appear to be working otherwise :)

My guess is that it needs to find both host and target libraries, thus requiring both host and target findlib.

@@ -52,7 +52,7 @@ stdenv.mkDerivation rec {
];

nativeBuildInputs = [ ocaml findlib ocamlbuild cc-wrapper ];
buildInputs = [ ocamlbuild findlib topkg cpuid ocb-stubblr ];
buildInputs = [ ocamlbuild findlib topkg cpuid ocb-stubblr ppx_deriving ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ppx_deriving should be propagated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke jackline, see: https://hydra.nixos.org/build/107730405

Will fix there: #74437

@anmonteiro
Copy link
Member

@balsoft commit 7263951 mentions it fixes the static build of OCaml for versions <= 4.07. I got OCaml 4.08 and 4.09 going under musl with the following (I think they switched the build to autoconf since 4.08):

(_: super:
    {
      ocaml = super.ocaml.overrideDerivation (o: {
        preConfigure = ''
          configureFlagsArray+=("CC=$CC" "AS=$AS" "PARTIALLD=$LD -r")
        '';
        configureFlags = (lib.remove "--no-shared-libs" o.configureFlags) ++ [
          "--disable-shared"
           "--host ${o.stdenv.hostPlatform.config}"
          "--target ${o.stdenv.targetPlatform.config}"
        ];
      });
    })

Ideally this would make it upstream to nixpkgs -- I'm looking for pointers on how to add these flags conditionally based on the OCaml version.

@vbgl
Copy link
Contributor

vbgl commented Jan 1, 2020

The configureFlags attribute of the derivation for the OCaml compilers has a “flag” function that should help to deal with the discrepancies between old and new configure flags:

@anmonteiro
Copy link
Member

I'm happy to submit a PR adding support for OCaml >= 4.08, but I'm still having an issue where I can't use packages that build with topkg. I keep getting e.g.:


building
No such package: topkg
File "./pkg/pkg.ml", line 4, characters 5-10:
4 | open Topkg
         ^^^^^
Error: Unbound module Topkg
builder for '/nix/store/7gfy9f8ai9bwbv1q112v3d40nwgas8w4-ocaml4.09.0-fmt-0.8.5-x86_64-unknown-linux-musl.drv' failed with exit code 2

Any pointers on what to look for here would be appreciated. I tried messing with nativeBuildInputs (added both topkg and findlib) but it doesn't seem to change anything.

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

Successfully merging this pull request may close these issues.

None yet

5 participants