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

Add --host_macos_minimum_os flag #13001

Closed

Conversation

keith
Copy link
Member

@keith keith commented Feb 11, 2021

This flag makes sure we set the minimum macOS version when compiling
host tools. Otherwise you can end up not sharing caches across
different OS versions.

Fixes #12988

@lberki lberki requested review from allevato and removed request for lberki February 12, 2021 07:20
Copy link
Member

@thii thii left a comment

Choose a reason for hiding this comment

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

Related change previously: #9403.

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

This seems reasonable, but I'm surprised the problem described in the linked issue hasn't been more widespread. I think I'd like @trybka to take a look at it too just to make sure this is the right way to tackle it.

@trybka
Copy link
Contributor

trybka commented Feb 12, 2021

I think this is fine? I'm not sure I entirely understand the usecase, though I can understand usecases where it might help.

This also feels like maybe not ideal, but until we have widespread execution platforms, I don't see a better alternative.

@brentleyjones
Copy link
Contributor

brentleyjones commented Feb 13, 2021

The cache sharing would be based on different Xcode versions, not OS versions.

I'm not entirely sure what targeting a newer-than-current OS version does, since it's clearly "working" as is, but it's less than ideal imo, and we should be able to target our actual minimum OS. Maybe it could affect deprecation warnings for example?

@keith
Copy link
Member Author

keith commented Feb 13, 2021

Did a bit more digging here. So it looks like it will happily create a binary for the SDK version you specify, and run it on an older version, but the downside is you get none of the protections around API usage, so there's the big risk. You won't find out until runtime on an older OS that your tools are actually incompatible in some way depending on what API they use.

@allevato
Copy link
Member

I spent some more time thinking about this because something about it still didn't feel quite right. Some random thoughts:

  • Conceptually, minimum deployment version is a property of individual targets, not of an entire build.
  • The existence of --{ios,macos,tvos,watchos}_minimum_os command line flags would seem to go against that, but their main purpose is to be set by a transition based on an attribute value on an Apple bundle rule so that they apply to the {cc,objc,swift}_library targets underneath. They can be set directly when building a *_library target from the command line, but we discourage that.
  • But, the flags also end up applying to rules like cc_binary and swift_binary, which don't have a way to set the deployment version since they also support non-Apple platforms, so they don't use the same transitions. Or perhaps stated more accurately, they don't so much "apply to {cc,swift}_binary" as they serve as a fallback value for anything in the build that isn't under a transition that sets it more specifically.

The original issue mentioned the use case being a genrule with a swift_binary tool. What if you had two or more such tools in your build that were written with different minimum deployment targets in mind? I think it's almost always fine to just go with the higher value, but if you want to build them as they were intended, you'd want to use different values for each one. In order to do that with rules like {cc,swift}_binary, you'd have to write a small rule + transition combo that sets --macos_minimum_os and then passes through the underlying binary. That's a lot of ceremony, unfortunately. But I'd like to make sure there's not a cleaner/more correct way out of this before we add a new command line flag (especially at a time when we're trying to reduce, rather than increase, the Apple API surface in Bazel core).

@keith
Copy link
Member Author

keith commented Feb 16, 2021

I think it's almost always fine to just go with the higher value

I don't think you could ever jump to just 1 value for this given that in either case of going higher or lower you could fail the build depending on the warnings / errors that were introduced with different deployment targets.

Definitely open the other suggestions here, having folks create their own transitions to solve this case is a super high barrier of entry to solve this bug so I think we should land some solution

@keith keith force-pushed the ks/add-host_macos_minimum_os-flag branch from e91a1ad to 3e84019 Compare February 23, 2021 01:51
@jin jin added platform: apple team-Rules-CPP Issues for C++ rules labels Mar 1, 2021
@aiuto aiuto added the team-Configurability platforms, toolchains, cquery, select(), config transitions label Jun 24, 2021
@aiuto
Copy link
Contributor

aiuto commented Jun 24, 2021

@gregestren @katre Could this be done without a flag? It seems very similar to the Android case.

@katre
Copy link
Member

katre commented Jun 24, 2021

Given that this is adding a host version of an existing flag, I think it makes sense.

The new Starlark flag we've added for Android's minimum SDK version is only possible because that affects the NDK, which is really a cc_toolchain, and so we added lots of select code in there to read and use the new flag. I don't think the macOS rules are that far moved to Starlark yet, so trying to use a Starlark flag isn't really appropriate there yet.

@katre katre removed the team-Configurability platforms, toolchains, cquery, select(), config transitions label Sep 8, 2021
@brentleyjones
Copy link
Contributor

@aiuto: Given @katre's and @trybka's comments, can this be merged?

@aiuto
Copy link
Contributor

aiuto commented Sep 14, 2021

@allevato @trybka Can one of you please do a review and actually approve.
And, does anyone know who @Highaboveus2 is? It looks like a random driveby.

@aiuto
Copy link
Contributor

aiuto commented Sep 14, 2021

OK. I'll do the merge.

@keith keith force-pushed the ks/add-host_macos_minimum_os-flag branch from 3e84019 to 8916c4e Compare September 21, 2021 19:50
@keith
Copy link
Member Author

keith commented Sep 21, 2021

Should be green shortly @aiuto

@brentleyjones
Copy link
Contributor

Can this be imported now? 🙏 Thanks!

@aiuto
Copy link
Contributor

aiuto commented Oct 4, 2021

This flag makes sure we set the minimum macOS version when compiling
host tools. Otherwise you can end up not sharing caches across
different OS versions.

Fixes bazelbuild#12988
@keith
Copy link
Member Author

keith commented Oct 4, 2021

Hrm, I thought that was the one I fixed last time, testing locally again

@keith keith force-pushed the ks/add-host_macos_minimum_os-flag branch from 8916c4e to 444789c Compare October 4, 2021 21:29
@keith
Copy link
Member Author

keith commented Oct 4, 2021

@aiuto which build did that failure come from? I don't see that locally anymore, did that include my more recent force push? (rebased to have CI run again for good measure)

This is what im testing with locally:

bz test src/test/java/com/google/devtools/build/lib/rules/objc:all

@aiuto
Copy link
Contributor

aiuto commented Oct 4, 2021 via email

@bazel-io bazel-io closed this in 6345c80 Oct 5, 2021
@keith keith deleted the ks/add-host_macos_minimum_os-flag branch October 5, 2021 01:10
bazel-io pushed a commit that referenced this pull request Mar 16, 2022
The flag was introduced in #13001 but not usable internally, because
the host flag was not saved when doing a transition.  Host flags
should be saved, like in:

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java#L1212

PiperOrigin-RevId: 435091962
brentleyjones pushed a commit to brentleyjones/bazel that referenced this pull request Mar 17, 2022
The flag was introduced in bazelbuild#13001 but not usable internally, because
the host flag was not saved when doing a transition.  Host flags
should be saved, like in:

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java#L1212

PiperOrigin-RevId: 435091962
(cherry picked from commit b8a2ee2)
Wyverald pushed a commit that referenced this pull request Mar 18, 2022
…#15068)

The flag was introduced in #13001 but not usable internally, because
the host flag was not saved when doing a transition.  Host flags
should be saved, like in:

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java#L1212

PiperOrigin-RevId: 435091962
(cherry picked from commit b8a2ee2)

Co-authored-by: waltl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XcodeConfigInfo.macosMinimumOsVersion is incorrectly set for host configuration
8 participants