-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix potentially broken support for macOS #515
Conversation
b28c79d
to
423b60f
Compare
@stefanprodan can you confirm this solves all your miseries? |
It doesn't
|
Could you try updating your |
@aryan9600 as I posted in the issue, my env is set to:
|
This works:
|
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \ | ||
ifdef MAC_M1 | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ |
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.
Is this breaking on macOS Intel? If not I would replace MAC_M1
with Darwin
.
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.
Don't have an Intel mac to test it on, I'm afraid. This seemed the safer way to go, since the current Makefile works on Intel Macs.
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.
@squaremo can you please test this on your mac?
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.
My mac may not be the best for testing this, since it's not a newcomer to the libgit2 battlefront. I've got libraries, pkg-config files, and env entries littered everywhere. Indeed, make run
works with the changes, without the changes, and when I remove everything except for go run ./main.go
.
I would like to understand why -rpath
works where LD_LIBRARY_PATH
doesn't, since these do pretty similar things. That explanation could usefully go in the commit message :-)
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.
I'm not an expert on dynamic linking, but I'll try to explain what I think is going on.
> otool -L bin/manager
bin/manager:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1853.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 60157.30.13)
@rpath/libgit2.1.1.dylib (compatibility version 1.1.0, current version 1.1.1)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
The thing of our interest is @rpath/libgit2.1.1.dylib
. From this article about @rpath
:
Starting in 10.5, Apple provides
@rpath
, which is a solution to this. When placed at the front of an install name, this asks the dynamic linker to search a list of locations for the library.
So, at runtime when our binary tries to load libgit2.1.1.dylib
, it tries to search for it in the dirs that fall under @rpath
. Presumably, the linker ignores LD_LIBRARY_PATH
because of the usage of @rpath
.
Why this is happening only on M1 and not on Intel, is beyond my understanding I'm afraid.
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.
I spun up my very old Intel Mac running macOS 10.13. The old Makefile
errored out with the same error whereas the new Makefile
works just the same as it does on macOS arm64. I'm starting to think that it was working on Intel Macs accidentally rather than the way it was intended to. It might be something to do with the go version like you said (i ran go 1.17 on both laptops). Let me try running it using go 1.16 on my Intel Mac and get back to you.
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.
I'm starting to think that it was working on Intel Macs accidentally
I think it is less likely to be to do with the CPU, and more to do with the individual machines on which it gets run; or failing that explanation, the OS version.
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.
Same error on macOS 10.13 running go 1.16 :)
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.
I think it used to work for us because we've installed libgit2 with brew, back when the version matched what Flux wants.
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.
I think it used to work for us because we've installed libgit2 with brew, back when the version matched what Flux wants.
Yeah I think you're right -- we both did this, and that's pretty much the pool of test machines accounted for :-)
(By the way, I verified that it was working by coincidence by moving /usr/local/lib/libgit2.* out of the way -- the executable then fails to start.)
@aryan9600 I think you can reframe this PR as "Work by design rather than by coincidence, on MacOS" :-) (And you don't need to have a special case for M1 Macs, to answer the original question ...)
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.
LGTM
Thanks @aryan9600 🥇
PS. Please squash your commits. image-automation-controller needs the same changes, please open a PR there.
c4f70f3
to
1952754
Compare
.. and give the resulting commit a message that describes why this change is being made. |
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: fluxcd#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]>
1952754
to
ef711cd
Compare
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: fluxcd#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]>
ef711cd
to
64bb84a
Compare
tried and this works for my intel MacOS 11.6.1 |
Thanks @cwyl02 for testing this on Intel 🏅 |
With the last changes, it correctly detects my OpenSSL installation without requiring any changes to my shell environment (on Apple M1): I would like to make the additional suggestion to introduce a |
Discussed this further with @aryan9600, and the proposed changes in #515 (comment) can be combined with getting the changes in from fluxcd/helm-controller#369. |
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: fluxcd#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]>
64bb84a
to
d174bc9
Compare
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: fluxcd/source-controller#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]>
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: fluxcd#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]> Signed-off-by: pa250194 <[email protected]>
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: fluxcd/source-controller#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]>
Make changes to Makefile, so that
libgit2.1.1.dylib
can be found at runtime when running on a Mac M1. Closes #506.