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

Improve support for aarch64 #1825

Merged
merged 7 commits into from
Nov 17, 2022
Merged

Improve support for aarch64 #1825

merged 7 commits into from
Nov 17, 2022

Conversation

avdv
Copy link
Member

@avdv avdv commented Oct 27, 2022

Fixes #1823
Fixes #1809
Fixes #1821

Depends on #1808

@dpulls
Copy link

dpulls bot commented Oct 28, 2022

🎉 All dependencies have been resolved !

@phb
Copy link

phb commented Nov 3, 2022

We've tested this and it works fine, I've gotten to the point where I can see haskell packages being compiled using ghc 9.2.

There are a few other issues though

  1. It seems all ghc versions <9.2 (?) uses LLVM to compile. Bazel rules clears PATH and as such it won't find opt (from llvm) on M1 macbooks as they don't allow installing things in the system bin folders.
    I can't think of any good solutions here -- it doesn't seem right to have rules_haskell setup the path to a local installation of llvm as that kind of defeats the purpose of hermetic builds, that said, I don't want rules_haskell to download and build llvm either!
  2. haskell 9.2 doesn't really seem ready for prime-time (no lts stackage snapshot and trying one of the nightlies I'm observing build failures) (I'm not a haskell person, so sorry if my vocabulary here is totally incorrect -- just trying to fix the build of an existing project after getting M1 laptops)

(update): So it seems the errors I'm seeing when using the nightly snapshot is actually the same error previously reported as fixed here:
20085b2 but I believe later reverted here: ed9ca34

Error being this:

../../../bazel-out/darwin_arm64-fastbuild/bin/external/stackage/transformers-compat-0.7.2/transformers-compat-0.7.2/build/autogen/Paths_transformers_compat.hs:48:17: error:
    Variable not in scope: splitFileName :: FilePath -> (a, b0)
   |
48 |   let (dir,_) = splitFileName exePath
   |                 ^^^^^^^^^^^^^

../../../bazel-out/darwin_arm64-fastbuild/bin/external/stackage/transformers-compat-0.7.2/transformers-compat-0.7.2/build/autogen/Paths_transformers_compat.hs:49:16: error:
    Variable not in scope: minusFileName :: t0 -> String -> String
   |
49 |   return ((dir `minusFileName` "bin") `joinFileName` dirRel)

@avdv
Copy link
Member Author

avdv commented Nov 4, 2022

  • It seems all ghc versions <9.2 (?) uses LLVM to compile. Bazel rules clears PATH and as such it won't find opt (from llvm) on M1 macbooks as they don't allow installing things in the system bin folders.

The compiler backend is configurable. See https://downloads.haskell.org/ghc/latest/docs/users_guide/codegens.html#llvm-code-gen

So you could pass -fasm to ghc to use the native backend.

I can't think of any good solutions here -- it doesn't seem right to have rules_haskell setup the path to a local installation of llvm as that kind of defeats the purpose of hermetic builds, that said, I don't want rules_haskell to download and build llvm either!

  • haskell 9.2 doesn't really seem ready for prime-time (no lts stackage snapshot and trying one of the nightlies I'm observing build failures) (I'm not a haskell person, so sorry if my vocabulary here is totally incorrect -- just trying to fix the build of an existing project after getting M1 laptops)
    (update): So it seems the errors I'm seeing when using the nightly snapshot is actually the same error previously reported as fixed here:
    20085b2 but I believe later reverted here: ed9ca34

Yes, we need the modules to be relocatable. Unfortunately, this has been broken in Cabal since version 3.6.0 and was only recently fixed by haskell/cabal#8220.

@phb
Copy link

phb commented Nov 4, 2022

  • It seems all ghc versions <9.2 (?) uses LLVM to compile. Bazel rules clears PATH and as such it won't find opt (from llvm) on M1 macbooks as they don't allow installing things in the system bin folders.

The compiler backend is configurable. See https://downloads.haskell.org/ghc/latest/docs/users_guide/codegens.html#llvm-code-gen

So you could pass -fasm to ghc to use the native backend.

I don't believe this will work on versions prior to 9.2 as it didn't have a native backend for arm64 until then (assuming I read the release notes correctly: https://discourse.haskell.org/t/ghc-9-2-1-released/3527)

I can't think of any good solutions here -- it doesn't seem right to have rules_haskell setup the path to a local installation of llvm as that kind of defeats the purpose of hermetic builds, that said, I don't want rules_haskell to download and build llvm either!

  • haskell 9.2 doesn't really seem ready for prime-time (no lts stackage snapshot and trying one of the nightlies I'm observing build failures) (I'm not a haskell person, so sorry if my vocabulary here is totally incorrect -- just trying to fix the build of an existing project after getting M1 laptops)
    (update): So it seems the errors I'm seeing when using the nightly snapshot is actually the same error previously reported as fixed here:
    20085b2 but I believe later reverted here: ed9ca34

Yes, we need the modules to be relocatable. Unfortunately, this has been broken in Cabal since version 3.6.0 and was only recently fixed by haskell/cabal#8220.

ah, that's great news -- don't think there is much to do except to wait for that commit to end up in a cabal release then. Let me know if you have any other ideas how to work around this.

I think ghc really should have a way for the user to provide a path to the llvm installation at runtime instead of relying on PATH. That said, considering that's not available now, perhaps we could add an option to rules_haskell to extend PATH in the ghc rule for finding required tools (based on the backend selected)?

@avdv
Copy link
Member Author

avdv commented Nov 7, 2022

I think ghc really should have a way for the user to provide a path to the llvm installation at runtime instead of relying on PATH.

Well, it does. You can use the various flags to set up a specific command for a tool.

See https://downloads.haskell.org/ghc/9.2.2/docs/html/users_guide/phases.html?highlight=pgmlo#replacing-the-program-for-one-or-more-phases

@avdv avdv marked this pull request as ready for review November 7, 2022 07:54
@phb
Copy link

phb commented Nov 7, 2022

I think ghc really should have a way for the user to provide a path to the llvm installation at runtime instead of relying on PATH.

Well, it does. You can use the various flags to set up a specific command for a tool.

See https://downloads.haskell.org/ghc/9.2.2/docs/html/users_guide/phases.html?highlight=pgmlo#replacing-the-program-for-one-or-more-phases

ah, that should unblock us. Thanks for that pointer -- I think we're good!

@avdv avdv requested a review from ylecornec November 7, 2022 10:44
@avdv avdv mentioned this pull request Nov 7, 2022
@avdv avdv added merge-queue merge on green CI and removed merge-queue merge on green CI labels Nov 9, 2022
@avdv avdv requested a review from GuillaumeGen November 15, 2022 19:46
Copy link
Contributor

@GuillaumeGen GuillaumeGen left a comment

Choose a reason for hiding this comment

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

Sorry, I merged the support for GHC 9.2.5 just before reviewing this, creating conflicts. They seemed simple to solve, but you may check that I did not miss anything.
Otherwise, looks great!

avdv added 7 commits November 17, 2022 08:36
These need bit of special handling, since the content of the tarball is different
from the offical bindists and the executable file lack the executable bit.
The [`get_cpu_value` function](https://github.com/bazelbuild/bazel/blob/183c8a42950deb4865e009e83748d4e090fe46d4/tools/cpp/lib_cc_configure.bzl#L180-L209)
returns "k8" as a last resort, if other OSes have been ruled out already and the "arch" is 64bit.

Similarly, if the OS is *not* identified as Mac OS, Windows, FreeBSD or OpenBSD
it simply returns "aarch64" when "arch" is "aarch64" and we assume this to be
Linux.
... according to the os and architecture.

This way it should just work for future GHC versions, if the packaging scheme is not changed upstream.

It is still possible to override these settings if need be.

Fixes #1809
@avdv
Copy link
Member Author

avdv commented Nov 17, 2022

Thank you, @GuillaumeGen ! I manually rebased against the default branch and removed the GHC prefixes, lib and so on for GHC 9.2.5 so it is also handled generically.

@avdv avdv added the merge-queue merge on green CI label Nov 17, 2022
@mergify mergify bot merged commit 4a71029 into master Nov 17, 2022
@mergify mergify bot deleted the arm64 branch November 17, 2022 08:26
@mergify mergify bot removed the merge-queue merge on green CI label Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants