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

Distributable Binaries for MacOS With Static Linking #8713

Open
d-xo opened this issue Jan 30, 2023 · 2 comments
Open

Distributable Binaries for MacOS With Static Linking #8713

d-xo opened this issue Jan 30, 2023 · 2 comments

Comments

@d-xo
Copy link

d-xo commented Jan 30, 2023

Apologies if this isn't the correct place to ask support questions.

I have a haskell application (hevm) that links in a few external c dependencies, and I would like to use cabal to produce self contained binaries that can be downloaded and run on a wide range of end user systems. On linux, this is pretty easy using --enable-executable-static to proudce a fully static binary (this is how we do it at the moment). On macos things are a little more complicated as fully static executables are not supported. I would like to produce a binary that links the external c dependencies statically, but keeps system provided libraries (i.e. at a minimum /usr/lib/libSystem.B.dylib) as dynamically linked.

Is there a set of config / build flags that I can pass to cabal to achieve this? afaict --enable-executable-static is not suitable for producing distributable binaries on macos as it will try to force static linking of all dependencies (including system provided ones).

@mouse07410
Copy link
Collaborator

mouse07410 commented Jan 30, 2023

In short, no.

If adding --disable-shared (and maybe --enable-static) to --enable-executable-static doesn't help - I don't know.

Also, you can try song those flags in ~/.cabal/config.

@d-xo
Copy link
Author

d-xo commented Jan 31, 2023

so after messing around for a while I think we have something working: ethereum/hevm#185.

From what we observed during our experimentation, ghc will link a library statically if it can only find static versions of that library. If it can find both static and dynamic versions it will link dynamically. We were able to write some build system scripts that leveraged this behaviour to get the output we needed, but it's pretty dirty.

Ideally this would be better supported in cabal / ghc, perhaps with some ghc flags that would give more granular control over which libs should be linked statically or dynamically, along with a cabal flag (maybe smth like --enable-macos-static), that would link everything statically except for core system libraries?

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

No branches or pull requests

2 participants