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

exec_compatible_with targets which can be built but don't match --platforms cause errors #11729

Closed
illicitonion opened this issue Jul 8, 2020 · 6 comments

Comments

@illicitonion
Copy link
Contributor

illicitonion commented Jul 8, 2020

Given this BUILD file:

cc_binary(
    name = "uname_linux",
    srcs = ["uname.c"],
    exec_compatible_with = ["@platforms//os:linux"],
)

cc_binary(
    name = "uname_macos",
    srcs = ["uname.c"],
    exec_compatible_with = ["@platforms//os:macos"],
)

Running:

bazel build \
  --incompatible_enable_cc_toolchain_resolution \
  --extra_toolchains=linux_toolchain,macos_toolchain \
  --extra_execution_platforms=linux_platform,macos_platform \
  //...

tells me:

ERROR: While resolving toolchains for target //compiles_platform_specific_c:uname_linux: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type.

Accordingly, it appears I need to tag these as manual, and explicitly build each one in its own invocation of Bazel with the right --platforms flag set.

I know that #10945 intends to skip incompatible targets, but are there plans to be able to build compatible-but-distinctly-configured targets? As far as I can tell if these are in the middle of the graph (i.e. some rule depends on them both), this works fine, but if they're explicit roots of the graph, it fails.

@katre
Copy link
Member

katre commented Jul 8, 2020

I'm unclear what you are asking for here. We have plans at some point to allow targets to specify their own target platform, and this will work with the current work for target platform compatibility in #10945. In general, with multi-configuration builds, trying to build //... in a single invocation will fail, because there's only one top-level configuration available.

@illicitonion
Copy link
Contributor Author

Yeah, having targets able to specify their own target platforms is really what I'm looking for - so if I'm building for Linux, but have a target which wants to build targeting MacOS, and my execution config would allow that, it will build despite my configuration. Is there an issue or something tracking that? It feels potentially separate to #10945 (but I could see how they'd end up in the same PR)

@katre
Copy link
Member

katre commented Jul 8, 2020

We don't have plans to implement this at the current time, because we are worried about the effect in large repos (such as google's internal repo).

I think the solution in #10945 will fix this for you by allowing you to specify target constraints and skip building invalid targets.

@illicitonion
Copy link
Contributor Author

That would be sufficient for us to work around not being able to bazel test //..., but it means that CI which could otherwise run bazel test //... will now need to run bazel test //... --config=macos and bazel test //... --config=linux separately, which is a shame considering the opportunity for parallelism within a single bazel invocation, and may end up with us double-building any non-platform-specific targets.

@katre
Copy link
Member

katre commented Jul 8, 2020

That makes sense. I found the roadmap item for this feature: #6519. As I said, we don't currently have a plan to implement this in the near future.

@illicitonion
Copy link
Contributor Author

Fantastic, thanks - closing as duplicate of #6519 (even if it has no short-term plans :))

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

No branches or pull requests

2 participants