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

Fix static building for ocaml-ng #73820

merged 16 commits into from Dec 2, 2019

Conversation

@balsoft
Copy link
Member

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

yorickvP and others added 7 commits Oct 31, 2019
…priate

The default has been to use buildInputs for build dependencies.
This doesn't work when cross-compiling.
This allows this package to build with eudev instead.
@balsoft balsoft changed the title Static fixes Fix static building for ocaml-ng Nov 20, 2019
@vbgl

This comment has been minimized.

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

This comment has been minimized.

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.

balsoft added 8 commits Nov 11, 2019
This commit adds a static adapter for ocaml packages and applies it to
pkgsStatic.ocaml-ng.

The adapter fixes build of ocaml itself with version <= 4.7 and also attempts
to fix builds of some packages.
@balsoft balsoft force-pushed the serokell:static-fixes branch from cd6a682 to 7263951 Nov 26, 2019
@balsoft balsoft requested a review from matthewbauer Nov 26, 2019
@matthewbauer matthewbauer merged commit 18848aa into NixOS:master Dec 2, 2019
1 check was pending
1 check was pending
grahamcofborg-eval Cloning project
Details
@@ -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 ];

This comment has been minimized.

Copy link
@vbgl

vbgl Dec 5, 2019

Contributor

ppx_deriving should be propagated.

This comment has been minimized.

Copy link
@vbgl

vbgl Dec 5, 2019

Contributor

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

Will fix there: #74437

@anmonteiro

This comment has been minimized.

Copy link
Member

anmonteiro commented Jan 1, 2020

@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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

anmonteiro commented Jan 1, 2020

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
5 participants
You can’t perform that action at this time.