-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 static compilation support #5970
Conversation
bb4b54f
to
f6189fb
Compare
To the confused ones: yes, macOS doesn't support building fully static binaries; Apple doesn't provide static system libraries... Do all libraries get linked statically? even when shared libraries are available? If so, then this looks like an acceptable solution. |
Well either way, this should check the darwin flag on the compiled module (this will break cross-compiling). I think I understand now what this PR is trying to do: leave in asking pkg-config for static libraries but don't force static linking. I'd much prefer to explicitly whitelist relevant libraries for dynamic linking - instead of implicitly falling back to dynamic libraries where static aren't available. I don't know much about OSX and I can't remember the details of exactly how this part of the compiler behaves (even though I added the flag), so I might be talking out of my arse. |
Cross compilation builds an object file. It's unaffected by the static flag. There are static libraries on macOS, just not for the core system libs (e.g. It would be great to support linking statically what can be by asking |
@ysbaddaden Yes, they do. Crystal currently provides absolute paths to static libraries if they are found as recommended by Apple when wishing to link statically. I've tested this while creating a pull request for MacPorts to add Crystal. I also had to modify the Link attributes of OpenSSL's libcrypto and libssl to plain |
It'll output the wrong link command though. There's a reason the entire rest of the function (and compiler) uses
I understand that, but currently this PR means that it will fall back to dynamic linking for any librarary, instead of just the select few for which static versions don't exist. That's bad behaviour. |
f6189fb
to
7095b4c
Compare
@RX14 I've updated the code to use |
7095b4c
to
b45c1dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@straight-shoota I think combining this PR with the other one would be a good idea. Basically, allow static linking as much as possible while showing a warning. Even if the binary isn't 100% statically linked, it's still very helpful due to Crystal's dependence on third-party libs such as libgc. |
This pull request is, by far, more useful than merely disabling static compilation on macOS. We can have third party libraries to be statically linked, leaving only the system shared libraries out. I believe this is what we should aim for with the static flag on macOS. |
Perhaps |
Yes, |
Nothing since 2 years, the PR as-is doesn't bring much. Also, |
The
-static
flag isn't supported on macOS, but a build can be created which only dynamically links the system library. Also, readline implicitly depends on ncurses and so linking it is required when creating a static build or else you get missing symbol errors.