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

Skip adding -lstatic to libtest and libstd on Darwin #1620

Merged

Conversation

gferon
Copy link
Contributor

@gferon gferon commented Nov 2, 2022

This is one way to fix #1573, which I have a feeling can be wrong. The binaries produced with this patch contain all required symbols and are working fine on macOS.

@gferon gferon force-pushed the fix-libtest-libstd-runtime-error-macos branch from f8251fa to 149c67d Compare November 2, 2022 10:31
@gferon
Copy link
Contributor Author

gferon commented Nov 2, 2022

Looks like the CI failure is unrelated to this change 🤔

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.

It seems a little weird that we'd express "don't dynamically link libstd" by saying "don't statically link libstd", but, if it seems to work (which CI shows it does), that seems better than the status quo...

Would it be possible to get a couple of tests test showing the desired end-effect here?

  1. Our existing binaries all successfully run on CI at the moment - do you have an example that fails without this patch?
  2. Could we add a sh_test which runs otool -L on a produced rust_binary and shows that it doesn't dynamically link the libraries we don't expect to be dynamically linked?

@gferon
Copy link
Contributor Author

gferon commented Dec 15, 2022

You're right, this would be much better if the issue was documented and a test would prevent any regression. I'll remove the patch on our codebase and try to come up with a minimal non-working example ASAP!

@gferon gferon closed this Mar 22, 2023
@gferon gferon reopened this Mar 22, 2023
@gferon
Copy link
Contributor Author

gferon commented Mar 22, 2023

@illicitonion since I'm currently working on upstreaming all of our custom patches, I unburried this one from the past. I added a test to demonstrate the issue, and I can confirm the test fails without the patch and passes otherwise.

Could we add a sh_test which runs otool -L on a produced rust_binary and shows that it doesn't dynamically link the libraries we don't expect to be dynamically linked?

I added a sh_test that just runs the test binary, which has the same effect.

@gferon gferon changed the title Skip adding -lstatic to libtest and libstd on macOS Skip adding -lstatic to libtest and libstd on Darwin Mar 22, 2023
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.

This looks great, thanks so much! One small comment about the test, then let's get this merged!

#!/bin/sh
set -e

$1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you instead run otool -L "$1" and verify (by grep or whatever) that it doesn't contain "libstd" or "libtest"?

I want us to be sure that we're actually statically linking stuff, rather than setting up rpaths or whatever so that in the bazel-bin tree the binary happens to work but if you moved it somewhere else or copied it to another machine it would fail to.

You can use target_compatible_with to make sure this test only runs on darwin where otool will be present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Just pushed a new commit.

@illicitonion
Copy link
Collaborator

Thanks!

@illicitonion illicitonion merged commit fd10963 into bazelbuild:main Mar 22, 2023
@gferon gferon deleted the fix-libtest-libstd-runtime-error-macos branch March 22, 2023 16:28
nyurik pushed a commit to nyurik/rules_rust that referenced this pull request Mar 28, 2023
This is one way to fix bazelbuild#1573, which I have a feeling can be wrong. The binaries produced with this patch contain all required symbols and are working fine on macOS.
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

Successfully merging this pull request may close these issues.

libtest/libstd being dynamically linked on macos
3 participants