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

Foreign Libraries not building on Darwin A64 #8227

Closed
yobson opened this issue Jun 17, 2022 · 12 comments
Closed

Foreign Libraries not building on Darwin A64 #8227

yobson opened this issue Jun 17, 2022 · 12 comments

Comments

@yobson
Copy link
Contributor

yobson commented Jun 17, 2022

The Bug
When trying to compile a project that produces a foreign library on an M1 MacBook Pro, you get the error:

cabal-3.6.2.0: Cannot build some foreign libraries: Building foreign libraries
is currently only supported on OSX, Linux and Windows

To Reproduce
Steps to reproduce the behavior:
Create an empty foreign library project, then simply run:

$ cabal v2-build

Expected behavior
A lovely dylib to be produced!

System information

  • OS: Mac OS 12.4
  • Processor: Apple M1 Pro
  • Cabal Version: 3.6.2.0 (ghcup)
  • Ghc Version: 8.10.7
@Mikolaj
Copy link
Member

Mikolaj commented Jun 17, 2022

IIRC, this is a (certain version of) GHC limitation. Could you kindly confirm? E.g., does it work with GHC 9.4 alpha taken from ghcup config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml?

@yobson
Copy link
Contributor Author

yobson commented Jun 17, 2022

I'm afraid it still doesn't work:

$ cabal v2-build
Resolving dependencies...
Build profile: -w ghc-9.4.0.20220523 -O2
In order, the following will be built (use -v for more details):
 - lib-test-0.1.0.0 (flib:test) (first run)
Configuring foreign library 'test' for lib-test-0.1.0.0..
cabal-3.6.2.0: Cannot build some foreign libraries: Building foreign libraries
is currently only supported on OSX, Linux and Windows

@Mikolaj
Copy link
Member

Mikolaj commented Jun 18, 2022

You are right, this needs both a new GHC and cabal, see #7764.

@Mikolaj Mikolaj added status: fixed in master The fix or feature is already included on master branch and removed blocked: info-needed labels Jun 18, 2022
@yobson
Copy link
Contributor Author

yobson commented Jun 18, 2022

I'll test tomorrow! Im guessing it will be included in next release?

@Mikolaj
Copy link
Member

Mikolaj commented Jun 18, 2022

Yes, given that it's in the pre-release, the one you can get from ghcup. Take care!

@yobson
Copy link
Contributor Author

yobson commented Jun 18, 2022

Ah! Checked now. Not working with ghc 9.4 and cabal 3.8.0.20220526. But if you are sure the fix will appear, shall I close?

@Mikolaj
Copy link
Member

Mikolaj commented Jun 18, 2022

The #7764 fix is included in the 3.8.0.20220526 pre-release. If that doesn't work for you, then your problem must be different. Can you summarise how your commandline and/or OS/arch/versions are is different from

#7763
#7837
https://gitlab.haskell.org/ghc/ghc/-/issues/20520

which all seem to be fixed?

BTW, you can try GHC 9.2.3 just in case something got broken anew in GHC 9.4 alpha?

BTW2, are you sure you are using cabal 3.8.0.20220526, if you have several installed? What does cabal --version say?

@yobson
Copy link
Contributor Author

yobson commented Jun 18, 2022

Doesn't work on 9.2.3

$ cabal --version
cabal-install version 3.8.0.20220526
compiled using version 3.8.0.20220526 of the Cabal library

Everything is the same as #7837, I'm just not sure it was fixed.

My guess is that cabal doesn't actually work out that it's still Mac os. The message says 'OSX', which predates Mac OS which predates apple silicon.

I've grepped the code base, and this message comes up at Cabal/src/Distribution/Simple/Configure.hs:2073

The code is:

goGhcPlatform :: Platform -> Maybe String
goGhcPlatform (Platform X86_64 OSX    ) = goGhcOsx     (foreignLibType flib)
goGhcPlatform (Platform _      Linux  ) = goGhcLinux   (foreignLibType flib)
goGhcPlatform (Platform I386   Windows) = goGhcWindows (foreignLibType flib)
goGhcPlatform (Platform X86_64 Windows) = goGhcWindows (foreignLibType flib)
goGhcPlatform _ = unsupported [
    "Building foreign libraries is currently only supported on OSX, "
    , "Linux and Windows"
    ]

Unless I don't know how to use git blame, it looks as though this was the very code added 7 years ago, long before apple silicon. So what I'll do is get it to ignore the architecture of Mac OS and see if it works. Hopefully it works identically to the X86_64.

@yobson
Copy link
Contributor Author

yobson commented Jun 18, 2022

It takes a looong time to build cabal, that's for sure! I got it fixed, I'm glad to say! I'm building the change in my own fork with the intent of making a pull request. If anyone knows anything about backports, that knowledge would be useful!

yobson added a commit to yobson/cabal that referenced this issue Jun 18, 2022
- Allowed building Foreign Libraries for all architecture on apple
  silicon
- Updated error message to name Mac OS instead of OSX as supported
  platform
@Mikolaj
Copy link
Member

Mikolaj commented Jun 20, 2022

Yay! I willy backport to branch 3.8 so that it's included in cabal 3.8.

@Mikolaj Mikolaj added attention: pr-welcome and removed status: fixed in master The fix or feature is already included on master branch labels Jun 20, 2022
mergify bot added a commit that referenced this issue Jun 22, 2022
Apple Silicon Foreign Library Support (#8227)
mergify bot pushed a commit that referenced this issue Jun 22, 2022
- Allowed building Foreign Libraries for all architecture on apple
  silicon
- Updated error message to name Mac OS instead of OSX as supported
  platform

(cherry picked from commit 99f928e)
Mikolaj added a commit that referenced this issue Jun 22, 2022
Apple Silicon Foreign Library Support (#8227) (backport #8232)
@ulysses4ever
Copy link
Collaborator

#8232 and #8243 both landed. Should this be closed?

@Mikolaj
Copy link
Member

Mikolaj commented Jul 2, 2022

Oh, yes, I think it's an oversight. Thanks a lot @yobson!

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

No branches or pull requests

3 participants