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

Enables runtime linking for darwin platforms #766

Merged
merged 1 commit into from
Jun 14, 2021
Merged

Enables runtime linking for darwin platforms #766

merged 1 commit into from
Jun 14, 2021

Conversation

csmulhern
Copy link
Contributor

Runtime linking with rpaths works correctly on darwin with only this change, for dylibs that have the correct extension (dylib) and the correct rpath configuration. Runtime linking against dynamic libraries created by bazel targets remains broken, due to them not having install names set correctly. That is fixed by using --incompatible_macos_set_install_name after bazelbuild/bazel#13427.

I have attached a zip file with a simple example workspace demonstrating this.

example.zip

Run:

(cd lib; ./build.sh)
bazel run //:main

@google-cla google-cla bot added the cla: yes label Jun 12, 2021
@UebelAndre
Copy link
Collaborator

Seems related to #540

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think this looks good but do you think you could Bazelify the example you have and add it to examples/runtime_linking or something so we can be sure to avoid potential regressions in the future 😅 🙏?

@csmulhern
Copy link
Contributor Author

My intention is to fix #621 and so this will be bazel-ified and checked by CI by those targets. The difficulty with adapting the example I have linked here is that it requires using an unreleased version of Bazel so that --incompatible_macos_set_install_name can be set. Otherwise I'd need to write a new rule that post processes cc_library targets to set the install name of the dylib, which I'm not sure is worth the effort. I wanted to submit this PR independently because it is preventing me from linking against a vulkan dylib that I am cc_importing in my project, ahead of a full fix for #621. I can also wait to submit a PR with a full fix for #621, which involves:

  1. Setting --incompatible_macos_set_install_name (which will work correctly in an upcoming release of Bazel, hopefully 4.2: Release 4.2 - June 2021 bazel#13558 (comment)).
  2. This change.
  3. The change outlined in my second paragraph here: Enable @examples//ffi/rust_calling_c/... on MacOS CI #621 (comment).

This will specifically solve the issues with the tests in @examples/ffi/rust_calling_c/BUILD.bazel on macOS.

To resolve the issues with the tests in @examples/ffi/rust_calling_c/simple/BUILD.bazel, we also need to resolve #741, which I believe should be resolved by using the dynamic library specified by the cc toolchain. I also plan to take a look at this.

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me - maybe worth a comment above the if statement explaining that darwin doesn't work before (link to PR/commit) and that it's known not to work <4.2

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks! I agree with #766 (review) but otherwise looks good and am excited to see this issue getting fixed 😄

Runtime linking with rpaths works correctly on darwin with only this
change, for dylibs that have the correct extension (dylib) and the
correct rpath configuration. Runtime linking against dynamic libraries
created by bazel targets remains broken, due to them not having install
names set correctly. That is fixed by using
--incompatible_macos_set_install_name after
bazelbuild/bazel#13427.
@csmulhern
Copy link
Contributor Author

Done.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

@UebelAndre UebelAndre merged commit 2d951b4 into bazelbuild:main Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants