build: fix cross-platform android builds on OS X#237
Conversation
devbww
left a comment
There was a problem hiding this comment.
Perhaps the PR title could be more descriptive of the actual change.
| "//:osx": [ | ||
| "-framework Foundation", | ||
| ], |
There was a problem hiding this comment.
This was added in #102, which references abseil/abseil-cpp#291.
Do we understand why that was wrong, or what has changed?
There was a problem hiding this comment.
What I know is what is on the associated issue, which is this change broke absl for Envoy Mobile and tensorflow builds.
Edit: If the removal causes problems for anyone I can add a bazel select to make it either opt-in or opt-out.
There was a problem hiding this comment.
From reading the history of that other PR and issue that @devbww mentioned, I think the issue was that old versions of bazel didn't automatically link with -framework Foundation, and newer bazel's may do that automatically. I'm guessing that the bazel versions that we support today all implicitly link w/ Foundation, so I think removing these explicit deps may work OK.
That said, I'm not sure we actually should do that. Today, our code explicitly references macOS TimeZone types, for example:
Line 25 in c674330
and in the spirit of include link with what you use, cctz probably should be explicit about its dep on Foundation[1], IMO.
From abseil/abseil-cpp#326, it sounds like the real issue is w/ the native android build rules. @alyssawilk did you say that you have an alternative workaround that may allow you to fix your issue while allowing CCTZ to retain its explicit dep?
[1]: We're currently linking with Foundation, but we actually only need to link with CoreFoundation (it's a lower-level library). So this dep should probably actually be -framework CoreFoundation... @alyssawilk does making that change fix your issue (probably not; but we might as well check)
There was a problem hiding this comment.
Our workaround is carrying an abseil.patch file* which removes the foundation files (which looks like what everyone else is doing). I'm now trying to get rid of that patch file, either by removing the explicit dependency or making it optional because the code is switching repos and I'm trying to clean up all the backported patches that I can. Worst case I can probably move the backported patch but I'd rather find a fix we're all Ok with, whether it be removing the dependency as outdated and known problematic, or having an opt-in bazel select. I'm happy to do whatever works best for you folks but I'd really prefer we fix abseil rather than expect everyone downstream to patch!
https://github.com/envoyproxy/envoy-mobile/blob/main/bazel/abseil.patch
There was a problem hiding this comment.
I agree that it would be good to avoid the need for everyone (anyone) to have to apply a patch in order to use abseil/cctz w/ an android build target (when compiling on macos).
I think I'd be OK with replacing the -framework Foundation explicit dep with a comment stating that we actually do need the Foundation dep, but it's added implicitly by Bazel and not listing it explicitly works around a bug in the android native deps (and link to that issue). That's basically this PR but with an additional comment.
@devbww WDYT?
@derekmauro can you confirm whether this PR, when patched in to Abseil, will pass all of Abseil's tests?
There was a problem hiding this comment.
SG thanks! I'f we're doing that as general clean up I'm inclined to do it for both, not just for the dependency my project needs. I'm very happy to revert that half if y'all prefer but I'll start with that so @derekmauro 's CI run tests both removals and optimistically hope the other ccd folks buy in on this plan.
There was a problem hiding this comment.
Forgive my naivety, but if I'm understanding correctly bazel now adds -framework Foundation, so we don't have to, even though we would prefer to (or at least CoreFoundation).
And not adding it avoids this: "the problem is when you're trying to build android libraries on a mac machine it gets confused about platforms."
That seems like a problem far removed from this change, and not even cctz specific. Is there an alternative that targets the real confusion?
devjgm
left a comment
There was a problem hiding this comment.
Thanks for the PR, Alyssa. Can you tell me how to repro the error you're seeing? I just checked out cctz on my Mac and built it w/ bazel test ... and it worked OK. What do I need to do to see the error that's being fixed here?
|
I think the attached issue explains better than I can - the problem is when you're trying to build android libraries on a mac machine it gets confused about platforms. You can repro if you check out and build envoy mobile (or tensorflow but I can't help with that one) on a mac machine without the absl patch. I'm happy to walk through repro instructions if you'd be game for trying it, or I can add a custom select so that we (and other folks who ran into the same issue) can work around the issue locally. |
|
This PR LGTM. @devbww, thoughts? |
devbww
left a comment
There was a problem hiding this comment.
Perhaps the PR title could be more descriptive of the actual change.
Sorry for the confusion, but my concern was mostly with the title (first line), not the body. It should try to summarize the actual effect.
| "//:osx": [ | ||
| "-framework Foundation", | ||
| ], |
There was a problem hiding this comment.
Forgive my naivety, but if I'm understanding correctly bazel now adds -framework Foundation, so we don't have to, even though we would prefer to (or at least CoreFoundation).
And not adding it avoids this: "the problem is when you're trying to build android libraries on a mac machine it gets confused about platforms."
That seems like a problem far removed from this change, and not even cctz specific. Is there an alternative that targets the real confusion?
BUILD
Outdated
| # it is no longer explicitly added as a linkopt as bazel adds it | ||
| # automatically. See https://github.com/abseil/abseil-cpp/issues/326 for details. |
There was a problem hiding this comment.
"as bazel adds it automatically"
If that is the case, why doesn't the problem remain no matter what cctz does?
If bazel only does it in more limited circumstances, couldn't we use the same, limited circumstances (e.g., better discrimination between execution and target platforms)?
There was a problem hiding this comment.
the way bazel adds it doesn't cause problems for android builds on macos as shown by commenting out this block upstream fixing everyone's builds
Given this fixes known bugs for multiple downstream customers and the only down-side is an implicit rather than explicit dependency, would it be possible to file a tracking issue for you folks to investigate what bazel does and add back a (working) explicit dependency? I don't know enough about bazel internals to know what they're doing and how it works but I know from again the multiple reports of breakage with explicit includes that there is a real problem I would like to fix, without the perfect solution stopping a known improvement.
devbww
left a comment
There was a problem hiding this comment.
Thanks.
I also removed "attempting to" from the PR title.
BUILD
Outdated
| # Note that OS X and iOS both have a dependency on CoreFoundation but it is | ||
| # no longer explicitly added as a linkopt as that causes problems | ||
| # cross-compiling android builds on OSX, and bazel will add it | ||
| # automatically. |
There was a problem hiding this comment.
OK, thanks. If you have the stamina for one more edit, though, I'd suggest ...
# OS X and iOS no longer use `linkopts = ["-framework CoreFoundation"]`
# as (1) bazel adds it automatically, and (2) it caused problems when
# cross-compiling for Android.
There was a problem hiding this comment.
SGTM! I have no preference on phrasing so happy to land whatever works for you folks
This also allows us to remove the mobile override and its patch because the new version of abseil-cpp pulls in google/cctz#237. Fixes envoyproxy/envoy-mobile#136. Signed-off-by: JP Simard <jp@jpsim.com>
* build(deps): bump abseil-cpp to latest version This also allows us to remove the mobile override and its patch because the new version of abseil-cpp pulls in google/cctz#237. Fixes envoyproxy/envoy-mobile#136. Signed-off-by: JP Simard <jp@jpsim.com>
|
Im a bit confused with this PR. I see many comments cited Bazel implicitly adding https://cs.opensource.google/search?q=%22-framework%22&sq=&ss=bazel%2Fbazel My personal guess is that on MacOS, the default cc toolchain Bazel uses is the host's local cc toolchain (xcode clang). This toolchain is poorly configured and has leaks that may automatically include the framework where needed. However, when you switch to using a more hermetic, air-tight cc toolchain (such as https://github.com/uber/bazel-zig-cc), the missing of implicit As suggested in envoyproxy/envoy#24782, this PR might be a bit rushed and android issue might be unrelated/tangent to the linkopts flag. I would urge folks to reconsider and perhaps, revert this PR. |
|
@alyssawilk ... please comment. Thanks. |
|
Sorry would reverting the PR require everyone to maintain the workaround patches they used to? I'm not understand what changed to make the prior behavior less problematic than it was. |
|
I'm not sure what changed either, but there's definitely a problem here. I have a real program running on macOS 13 / M1 that crashes due to this issue. We don't see this issue in Kokoro which uses Intel Macs. Is it possible that the "default Bazel behavior" wasn't a Bazel behavior at all, but actually some default in Xcode? |
This breaks toolchains that don't add the implicit Foundation linkopt. I can no longer reproduce this building envoy for Android so I'm not sure if we mis-diagnosed the issue, or if it was fixed another way. This reverts commit 5417654.
|
I submitted a revert for this here #264 |
This breaks toolchains that don't add the implicit Foundation linkopt. I can no longer reproduce this building envoy for Android so I'm not sure if we mis-diagnosed the issue, or if it was fixed another way. This reverts commit 5417654.
Fixing abseil/abseil-cpp#326 by removing a non-working Foundation linkopt for OS X and iOS.
Foundation should now be implicitly added by modern versions of bazel so this will hopefully not be problematic for builds previously affected by abseil/abseil-cpp#291
This change is
co-authored-by: devbww