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

ocamlPackages.ocaml: build fails on aarch64-apple-darwin #144785

Closed
lilyball opened this issue Nov 5, 2021 · 6 comments
Closed

ocamlPackages.ocaml: build fails on aarch64-apple-darwin #144785

lilyball opened this issue Nov 5, 2021 · 6 comments
Labels
0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: ocaml

Comments

@lilyball
Copy link
Member

lilyball commented Nov 5, 2021

Describe the bug

Building OCaml 4.12.0 fails on aarch64-apple-darwin (Apple Silicon). It fails most of the way through the build process. According to the build output, it runs the following:

> clang -c -O2 -fno-strict-aliasing -fwrapv -Wall -Wdeclaration-after-statement -fno-common -g  -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE   -DCAMLDLLIMPORT= -DNATIVE_CODE -DTARGET_arm64 -DMODEL_default -DSYS_macosx   -o codefrag.n.o codefrag.c
> aarch64-apple-darwin-clang -c -Wno-trigraphs -DSYS_macosx -I../runtime -DMODEL_default -o arm64.o arm64.S
/nix/store/wbwcrf1g7ywmmw2lllc26r0zcdvassiq-bash-5.1-p8/bin/bash: line 1: aarch64-apple-darwin-clang: command not found

I checked the nix log of ocaml on my x86_64-apple-darwin machine, here's the corresponding commands there:

> clang -c -O2 -fno-strict-aliasing -fwrapv -Wall -Wdeclaration-after-statement -fno-common -g  -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE   -DCAMLDLLIMPORT= -DNATIVE_CODE -DTARGET_amd64 -DMODEL_default -DSYS_macosx   -o codefrag.n.o codefrag.c
> clang -arch x86_64 -Wno-trigraphs -c -DSYS_macosx -I../runtime -DMODEL_default -o amd64.o amd64.S

So the x86-64 build runs clang -arch x86_64 as its assembler, but the aarch64 build runs aarch64-apple-darwin-clang instead, which doesn't exist. One might assume clang -arch aarch64 would have worked.

Running nix-shell -A ocaml '<nixpkgs>' --run env on both machines shows that the only reference to AS on the x86-64 machine is the line AS=as, but on the aarch64 machine it also has a preConfigure hook has an interesting definition:

'' + optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
# 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"

Of course, the build log shows aarch64-apple-darwin-clang is being invoked, not cc, and the x86-64 version isn't running as either, so I don't know how this leads to the attempted invocation of aarch64-apple-darwin-clang.

This preConfigure hook change was added in #114525, and I would assume it worked at that point, so I don't know why it's broken now.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install Nix on an aarch64-apple-darwin machine
  2. Update to current nixpkgs-unstable
  3. Run nix-build -A ocaml '<nixpkgs>'

Expected behavior

It should build correctly

Notify maintainers

@bobrik

Metadata

 ❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.1.0, macOS 12.0.1`
 - multi-user?: `yes`
 - sandbox: `relaxed`
 - version: `nix-env (Nix) 2.4pre-rc1`
 - channels(lily): `"darwin, home-manager"`
 - channels(root): `"nixpkgs-21.11pre327990.4789953e5c1"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: ocamlPackages.ocaml
# a list of nixos modules affected by the problem
module:
@lilyball lilyball added 0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: ocaml labels Nov 5, 2021
@lilyball
Copy link
Member Author

lilyball commented Nov 5, 2021

I reran the build with NIX_DEBUG=6 and attached the complete output.

ocaml build output.txt

@bobrik
Copy link
Contributor

bobrik commented Nov 5, 2021

Last successful build: https://hydra.nixos.org/build/151577668
First broken build: https://hydra.nixos.org/build/153146299

The latter provides the range of changes: c12858..f16e0e. Bisecting with --first-parent points at:

Which is great. we can find the first broken build there: https://hydra.nixos.org/build/157648264

This needs a bit more bisecting to figure out, but it definitely used to work.

@bobrik
Copy link
Contributor

bobrik commented Nov 5, 2021

#133008 looks like it could be the reason, cc @symphorien

@bobrik
Copy link
Contributor

bobrik commented Nov 6, 2021

It fails in master branch while configuring like this:

configure flags: --disable-static -prefix /nix/store/0w9n5af4m1nwps6qjxigxf6jc7h9bqww-ocaml-4.12.0 --host=aarch64-apple-darwin --target=aarch64-apple-darwin
configure: Configuring OCaml version 4.12.0
checking build system type... aarch64-apple-darwin21.1.0
checking host system type... aarch64-apple-darwin
checking target system type... aarch64-apple-darwin

With the following change it compiles:

diff --git a/pkgs/development/compilers/ocaml/generic.nix b/pkgs/development/compilers/ocaml/generic.nix
index e4cec4cf52e..ae6acfe0195 100644
--- a/pkgs/development/compilers/ocaml/generic.nix
+++ b/pkgs/development/compilers/ocaml/generic.nix
@@ -64,7 +64,6 @@ stdenv.mkDerivation (args // {
     "-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";
 
configure flags: --disable-static -prefix /nix/store/s2m7f8vxa0i9d0vyr225y70chb4clr0p-ocaml-4.12.0
configure: Configuring OCaml version 4.12.0
checking build system type... aarch64-apple-darwin21.1.0
checking host system type... aarch64-apple-darwin21.1.0
checking target system type... aarch64-apple-darwin21.1.0

Hopefully this gives somebody a clue on how to fix this properly.

@symphorien
Copy link
Member

I could build all of {pkgsStatic.,}ocaml-ng.ocamlPackages_4_{06,07,08,09,10,11,12}.dune_2 with this patch.

@symphorien
Copy link
Member

cc @vbgl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: ocaml
Projects
None yet
Development

No branches or pull requests

4 participants