-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Cannot use target_compatible_with to ignore MacOS only targets #12897
Comments
I can reproduce this: it looks like
I'm passing this off the @gregestren to see if there's a way to restructure the target skipping to ignore analysis failures in dependencies, but I'm not sure this is possible. |
I think it's reasonable to calculate target incompatibility before its deps are analyzed (at least direct incompatibility). But we need to know the current platform, which generally comes through toolchain resolution. Does the current toolchain resolution logic provide that before trying to find (non-existent) toolchains? i.e. the unresolved computation produces platform info? |
The target platform is loaded before toolchains are actually resolved, but I'm not sure there's a good way to pass that information back out to ConfiguredTargetFunction along with the resolution error. There are a lot of arguments for making all toolchains optional (and letting rules themselves throw errors if they need a toolchain that doesn't exist), and this seems to be one of them. |
Do you think bazel/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java Line 50 in 8346ea4
bazel/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java Lines 212 to 216 in 8346ea4
If so, the other challenge would be to short-circuit return a Re: generalizing optional toolchains, @katre offered to write up deeper thoughts on that. CC @philsc for FYI, or if I'm getting anything wrong. |
I think that would work to get a target platform. I can't say about the logic for the incompatible platform provider. |
To be clear, I'd really like to prototype this but I don't have time at the moment. I am keeping this issue in my back burner memory - I know it's important to work out first bugs on a new feature to really make the feature land well. |
I'll take a stab at your proposed idea this weekend and report back with what I find. It sounds reasonable, but also sounds like it could mean moving the entire logic to a completely different spot. |
Awesome, thanks! I think if injected carefully the change won't be overly invasive. But yeah it's a bit delicate to nudge all the parts exactly right. |
I spent a couple of hours on this without much progress. I think constructing the However, what I'm struggling with is how to compare that against the |
This might call for some virtual pair programming. Could you share with me a branch with your code? I'd also need to look down at the code level to sort through this stuff. |
Here are my hacks from last weekend: https://github.com/philsc/bazel/tree/unreviewed/objc_library Specifically, I think this is the last place where we can evaluate incompatibility: (Or we could add something inside of i had trouble going from |
Hi 👋! Running into this issue as well, is there any progress on this? Thanks!! |
@philsc were you waiting for followup from me? |
Not really, no. I've just been extremely lazy in regards to bazel these past few months :P |
Apologies for the delay. Last weekend was too busy, but this weekend I'm planning to look at this again. |
Thanks! 🙏 |
I'm starting to remember why I didn't solve this the last time I looked into it. |
I feel like I'm close. @gregestren , I need a way to convert the In Any thoughts you have would be much appreciated! |
Actually, it looks like the following code works to determine the equivalent So I think we have a way to detect direct incompatibility. Now we just need to call |
That all looks about right to me. I'd even bypass bazel/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java Lines 848 to 854 in b3aacbb
In short, construct a I think that would produce slightly less code (although I could be wrong). |
Here's another example of translating bazel/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java Line 68 in e362fc9
bazel/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java Lines 142 to 147 in e362fc9
That example further casts into |
Sorry for dropping the ball on this ticket. It's been a busy few months. I'm resuming work on this at the end of August. If anyone else wants to take it over in the meantime, I can totally understand that. |
I updated my proof-of-concept at https://github.com/philsc/bazel/tree/unreviewed/objc_library. |
I created a draft PR after rebasing on latest master. Still need to actually incorporate Greg's feedback. |
Thanks for the update! Happy to provide any more feedback as needed! |
Note to self: test how this refactor behaves with config_setting(
name = "compiler_gcc",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "gcc",
},
)
cc_library(
name = "gcc-only-lib",
target_compatible_with = select({
":compiler_gcc": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
...
) |
Note that the refactoring done in 72787a1 doesn't solve this problem in all cases. Consider
In this case, objc_library's self-transition on --cpu leads to a transition on --platforms, and then ble's target platform is actually target_compatible_with macos again (regardless of the value for --platforms passed on the command line). So a toolchain is once again required. |
Ah dang. Looks like the |
Filed #16099 as a follow-up. |
* Without this CL `bazel test --config linux base/...` fails. * Follow-up to cl/510039062. It is nice to use `target_compatible_with` instead of tags=["manual"]. Previously `target_compatible_with` did not work as expected. + bazelbuild/bazel#12897 PiperOrigin-RevId: 510166116
Description of the problem:
I'm trying to use the
target_compatible_with
attribute to automatically skip MacOS only targets on other platforms, but I just get an error every time. I have a simpleobjc_library
rule withtarget_compatible_with = [ "@platforms//os:macos" ]
but whenever I runbazel build //...:all
on non MacOS platforms I get this:Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Any
objc_library
rule fails instead of being ignored.I added a simple example here: jagobagascon/bazel-target-compatible
It's just an empty
objc_library
rule but you can se how the Ubuntu build fails while the MacOS just works: jagobagascon/bazel-target-compatible/actions/runs/512144112What operating system are you running Bazel on?
I'm running it on a Docker image based on
ubuntu:focal-20200423
, but it also happens on a GitHub-hostedubuntu-18.04
.What's the output of
bazel info release
?release 4.0.0
The text was updated successfully, but these errors were encountered: