-
Notifications
You must be signed in to change notification settings - Fork 238
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
Properly set DYLD_LIBRARY_PATH for macOS wheel delocation #816
Comments
This is macOS protection for malware injection. To disable it there is a need to run the system in a special mode which is impossible on CI. To pass these variables to
Did you try to use I use such a script to prepare libraries https://github.com/Czaki/imagecodecs_build/blob/fc23628c5eb90dfa63b854dc0d091d91151c9f2b/build_utils/fix_macos_lib.sh but fixing it on libraries update is painful. |
Good to know.
That's not very convenient. Yes, I could do it, but it's a bit finicky with dependencies on other environment variables and it's somewhat ugly too. I would prefer a separate config setting that takes care of all that automatically. BTW took me a while and many force-pushes to my test branch to figure out why |
I think that You may create PR. Your solution looks better than my and you still have access to logs to copy sample error messages. |
The question would be what path we should set this to. Setting it to |
Hi @phoerious! I'm not sure why CIBW_ENVIRONMENT wouldn't work in this case. While there might be malware protections at the runner level, I don't know of any malware protections on macOS that would interfere with CIBW_ENVIRONMENT, given that your script above works. What kind of errors are you seeing when you try this route? If that doesn't work, customising |
The demonstrated build step above works as a temporary solution. There are no errors, but it clutters my workflow definition. |
Could you make a PR setting CIBW_ENVIRONMENT (CIBW_ENVIRONMENT_MACOS?) and then point us at the failed build logs? I am curious to know why this doesn't work, it does basically the same thing as your workaround, AFAICT. |
I created a branch on my own repository for demonstration purposes (that's easiest, since I have everything there to build a wheel with native dependencies). I reduced the workflow file to only the steps needed to build and delocate the wheel on macOS. I tried setting You can see that And finally, here's where the build fails, because the library search path is empty: The same is reproducible with |
It looks like MacOS differently treats the environment variable and prepends the command with the variable only for this command.
So possible workaround on the side if cibuildwheel could check if Knowledge from this thread should be transferred to documentation. |
Ah, I see, macOS strips that env var out after each subprocess launch. So I guess that the /bin/sh that we launch to run In that case, my recommendation would be to set CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
DYLD_LIBRARY_PATH=$LIBRARY_PATH delocate-listdeps &&
DYLD_LIBRARY_PATH=$LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} Being set by the shell process, delocate should get the environment variable. That should alleviate the need for your extra step, I think, @phoerious. I agree, something should be added to the documentation. How does this look as a faq.md entry: Passing DYLD_LIBRARY_PATH to delocatemacOS has built-in System Integrity protections which limits the use of To work around this, use a different environment variable such as CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel} |
If you write it like that, it might lead people to think that |
BTW, it's |
Thanks! Yes and good point on LIBRARY_PATH, I'd forgotten that was a special variable. I've subbed it out for something else. |
We were previously setting `DYLD_LIBRARY_PATH`, but macOS's System Integrity Protections were resulting in that environment being dropped before `delocate` was run, causing an incorrect version of `liblz4` to be found and vendored. See pypa/cibuildwheel#816 Signed-off-by: Matt Wozniski <[email protected]>
We were previously setting `DYLD_LIBRARY_PATH`, but macOS's System Integrity Protections were resulting in that environment being dropped before `delocate` was run, causing an incorrect version of `liblz4` to be found and vendored. See pypa/cibuildwheel#816 Signed-off-by: Matt Wozniski <[email protected]>
We were previously setting `DYLD_LIBRARY_PATH`, but macOS's System Integrity Protections were resulting in that environment being dropped before `delocate` was run, causing an incorrect version of `liblz4` to be found and vendored. See pypa/cibuildwheel#816 Signed-off-by: Matt Wozniski <[email protected]>
We were previously setting `DYLD_LIBRARY_PATH`, but macOS's System Integrity Protections were resulting in that environment being dropped before `delocate` was run, causing an incorrect version of `liblz4` to be found and vendored. See pypa/cibuildwheel#816 Also, set `PKG_CONFIG_PATH` so that `pkg-config` knows to pick up the `liblz4` that we've built, and add a `find` to our macOS `before-all` command so that our logs show what has been installed. Signed-off-by: Matt Wozniski <[email protected]>
We were previously setting `DYLD_LIBRARY_PATH`, but macOS's System Integrity Protections were resulting in that environment variable being dropped before `delocate` was run, causing an incorrect version of `liblz4` to be found and vendored. See pypa/cibuildwheel#816 Per that issue (and the docs), the workaround is overriding the `delocate` call to pass `DYLD_LIBRARY_PATH` directly to it. While we're at it, set `PKG_CONFIG_PATH` so that `pkg-config` knows to pick up the `liblz4` that we've built, and add a `find` to our macOS `before-all` command so that our logs show what has been installed. There's one thing I still don't understand: why we need to set `DYLD_LIBRARY_PATH` at all. I would expect `delocate` to find the right `liblz4` via the rpath that we're setting, but it doesn't... Signed-off-by: Matt Wozniski <[email protected]>
We were previously setting `DYLD_LIBRARY_PATH`, but macOS's System Integrity Protections were resulting in that environment variable being dropped before `delocate` was run, causing an incorrect version of `liblz4` to be found and vendored. See pypa/cibuildwheel#816 Per that issue (and the docs), the workaround is overriding the `delocate` call to pass `DYLD_LIBRARY_PATH` directly to it. While we're at it, set `PKG_CONFIG_PATH` so that `pkg-config` knows to pick up the `liblz4` that we've built, and add a `find` to our macOS `before-all` command so that our logs show what has been installed. There's one thing I still don't understand: why we need to set `DYLD_LIBRARY_PATH` at all. I would expect `delocate` to find the right `liblz4` via the rpath that we're setting, but it doesn't... Signed-off-by: Matt Wozniski <[email protected]>
I have a Github Action Workflow that builds wheels with native extensions for Linux, macOS, and Windows. External native dependencies for the macOS builds are installed via Vcpkg, so I need to set the
CPATH
andLIBRARY_PATH
environment variables to/usr/local/share/vcpkg/installed/x64-osx/include
and/usr/local/share/vcpkg/installed/x64-osx/lib
in order for clang to find the headers and*.dylib
binaries.The resulting macOS binaries have shared library dependencies starting with
@rpath
placeholders. Since there is notRPATH
hardcoded in the binaries themselves,delocate-wheel
needs a properly configuredDYLD_LIBRARY_PATH
for resolving these. Unfortunately, I seem to be unable to set either ofDYLD_LIBRARY_PATH
andLD_LIBRARY_PATH
on a Workflow job, so this variable is always unset, no matter what (I couldn't find any documentation, but it's probably a built-in precaution). I also tried setting it indirectly viaCIBW_ENVIRONMENT
, but without success.My workaround is to add a step like that:
It would be great if cibuildwheel could take care of that on its own. This issue pertains mainly to macOS, but may apply to Linux as well (not tested, because I install dependencies directly via
yum
there).The text was updated successfully, but these errors were encountered: