You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Let targets set what platforms they build for #6519
P3We're not considering working on this, but happy to review a PR. (No assignee)staleIssues or PRs that are stale (no activity for 30 days)team-Configurabilityplatforms, toolchains, cquery, select(), config transitionstype: feature request
$ cat a/BUILD
cc_binary(name = "app_for_mac", platforms = ["//platforms:mac"])
$ bazel build //a:app_for_mac # Automatically builds for a Mac, no command line flags!
This syntax is theoretical; it may not look exactly like this. The point is rules can embed which platforms they target and all the correct toolchains get linked in without having to specify anything at the command line.
Furthermore, different rules needing different toolchains (e.g. $ bazel build //a:all) will all independently do the right thing.
This is v0 because it may have performance consequences. This also doesn't cover non-platform settings (like app version, enable/disable feature X), which will be covered elsewhere in the roadmap.
Reacted by Chris Eason, Nathan Liebrecht, Greg Horn, Zhongming Qu, Preston Van Loon, Trevor Hickey, Rajiv Shah, Rohan Agarwal, Mathieu Boespflug, marcohu and 11 more
Reacted by Trevor Hickey
Reacted by Greg Horn, Preston Van Loon, Trevor Hickey and Lukas Herman
Reacted by Greg Horn, Per Grön, dmitrychepel, Preston Van Loon, Trevor Hickey, Lukas Herman and Tomasz Cybulski
Reacted by Trevor Hickey, Lukas Herman and Nathaniel Brough
Prerequisite work is still happening, so marking as a P3 now. This means we're not actively working on this yet. Will upgrade priority once the prereqs are out of the way.
Still blocked on prerequisites of basic platform & toolchain support. I'd still estimate a "second half of the year" time frame for starting to experiment with this, unless there's enough enthusiastic interest to jump on board even without concern about the scaling & caching concerns.
Technically I think really interested users will be able to explore this in the next month or two by manually combining together platform/toolchain support and Starlark transitions.
@gregestren Hi Greg, can you elaborate on how we can achieve multi-platform builds via transitions?
I'm building a small kernel using Bazel as the build engine. The boot-loader is being written targeting UEFI, which uses a PE COFF toolchain (basically targeting Windows via CLang/LLVM), and I want the kernel executables itself to be in ELF format (x86_64-none-elf).
At the moment, I have no clear path to go about it, was thinking more in the lines of having two separate Bazel build steps, and then combining the data into a boot disk, but if I could do everything inside Bazel it will be so much easier.
Building in separate steps is indeed an option if it comes to that. A major inspiration of these new APIs is to not have to resort to that, so we're on the same page there.
What BUILD rules are you using to represent the boot-loader and kernel executables and what flags are you using to switch the toolchain?
I suspect we can get a clear path for your use case.
At the moment they are just plain cc_binary and cc_library rules. You can have a look at the repository.
I'm not doing anything fancy at the moment, just settings the --crosstool-top switch to point to my custom toolchain that can build UEFI applications. I still need to separate out the various pieces, I'm just not sure what is the correct direction forward. What would be you're opinion on how I should handle this? I saw the configuration and build road-map on the Bazel website, and I'm quite excited for the option to use platforms inside the cc_binary and cc_library rules.
Also, this is just a pet project to build a small "DOS" like operating system, nothing serious.
Also, to add to the above, the uefi part needs to be built with the PE COFF toolchain, while the kernel and architecture parts I need in ELF format.
Thinking of it, I’m using LLVM and LLD, maybe I should try playing with creating a macro wrapping the cc rules for the UEFI and Kernel parts, where the macro itselfs sets copts to specify what linker to use.
@wpieterse2825: Have you taken a look at #7260? Once you write toolchain() targets for your existing cc_toolchain() declarations, you can use the flag to enable platform-based cc toolchain resolution now, which might be simpler than using copts and crosstool_top. All of the missing features of full multiplatform builds are still present, of course, but it moves you closer to that world.
I did try and do that, defining the various architectures and firmware targets. You can have a look here. But when I try and build only with platforms, without specifying the --cpu parameter, it always tries to build with the MSVC toolchain, which obviously causes problems when linking the binary. I could not figure it out at the time, will give it a try again and let you know my results.
@katre I did what you suggested and it worked. Could finally remove the --cpu flag from my .bazelrc file as everything is now compiled with platforms. Thanks.
Trying to get Bazel to directly support multiple values for --platforms is semantically very confusing, so we've made the decision to leave the specific semantics up to rule authors, who know their users' needs and ecosystems better.
Rule authors can also add custom flags for multi-platform support, like --android_platforms, where that makes sense (for example, Android uses this to create a fat APK from a single android_binary target).
The check is performed in PlatformConfiguration.reportInvalidOptions which uses PlatformOptions, however the instance it receives has .platforms already normalised so extraneous platforms are silently ignored (previously a warning was emitted).
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.
@hisener could you please elaborate more on your use case?
This issue is very old and mostly out of date? The community is now in favor of using Bazel Transitions to set the target platform for each individual target.
So let's say if you have a cc_binary that you want to build for a specific target, you can do something like this
Popular rules, such as rules_go, offer platform transitions as a direct attribute for more convenience. There are also things like with_cfg to scope down the transitions easier.
When I subscribed to this issue, our use case was using different JDKs for some targets. It's not possible out of the box. We ended up using with_cfg as you mentioned. However, there are a bunch of gotchas, e.g., env_inherit doesn't work in some cases.
Thus, I think having something built-in to define a target's intended platform is still valuable.
However, there are a bunch of gotchas, e.g., env_inherit doesn't work in some cases.
with_cfg should support env_inherit and generally aims to shield you from such transition gotchas. Could you file an issue for this over on the with_cfg.bzl repo?
with_cfg should support env_inherit and generally aims to shield you from such transition gotchas. Could you file an issue for this over on the with_cfg.bzl repo?
Yes, it's on my list for a while. 😞 I'll try to find some time.
env_inherit on java_test is backed by RunEnvironmentInfo in Bazel 7 and higher and with_cfg forwards this provider, so I would expect that to work without the hack necessary for native java_test.
I think since the direction for configuring targeted platforms has been decided to be using transitions, and viable transition machinery do exist today, it's safe to close this issue to reduce noise (some information from 2018-2019 is no longer applicable to 2026). We can iron out the UX in newer issues that are more focused on the exact problem rather than this broad topic.
There are some remaining TODOs from this issue, though:
Actually rename the flag to --platform (flag migrations are hard, sorry), leaving --platforms as a deprecated legacy name.
Actually remove --platforms.
But other than that, we should move the with_cfg conversation to a different place and close this one.
P3We're not considering working on this, but happy to review a PR. (No assignee)staleIssues or PRs that are stale (no activity for 30 days)team-Configurabilityplatforms, toolchains, cquery, select(), config transitionstype: feature request
Activity
gregestren commentedon Oct 25, 2018
Prerequisite work is still happening, so marking as a P3 now. This means we're not actively working on this yet. Will upgrade priority once the prereqs are out of the way.
gregestren commentedon Apr 26, 2019
April '19 update:
Still blocked on prerequisites of basic platform & toolchain support. I'd still estimate a "second half of the year" time frame for starting to experiment with this, unless there's enough enthusiastic interest to jump on board even without concern about the scaling & caching concerns.
Technically I think really interested users will be able to explore this in the next month or two by manually combining together platform/toolchain support and Starlark transitions.
steel-exodus commentedon May 5, 2019
@gregestren Hi Greg, can you elaborate on how we can achieve multi-platform builds via transitions?
I'm building a small kernel using Bazel as the build engine. The boot-loader is being written targeting UEFI, which uses a PE COFF toolchain (basically targeting Windows via CLang/LLVM), and I want the kernel executables itself to be in ELF format (x86_64-none-elf).
At the moment, I have no clear path to go about it, was thinking more in the lines of having two separate Bazel build steps, and then combining the data into a boot disk, but if I could do everything inside Bazel it will be so much easier.
gregestren commentedon May 6, 2019
Hey @wpieterse2825,
Building in separate steps is indeed an option if it comes to that. A major inspiration of these new APIs is to not have to resort to that, so we're on the same page there.
What BUILD rules are you using to represent the boot-loader and kernel executables and what flags are you using to switch the toolchain?
I suspect we can get a clear path for your use case.
steel-exodus commentedon May 7, 2019
@gregestren Thanks for the reply Greg.
At the moment they are just plain
cc_binaryandcc_libraryrules. You can have a look at the repository.I'm not doing anything fancy at the moment, just settings the
--crosstool-topswitch to point to my custom toolchain that can build UEFI applications. I still need to separate out the various pieces, I'm just not sure what is the correct direction forward. What would be you're opinion on how I should handle this? I saw the configuration and build road-map on the Bazel website, and I'm quite excited for the option to use platforms inside thecc_binaryandcc_libraryrules.Also, this is just a pet project to build a small "DOS" like operating system, nothing serious.
steel-exodus commentedon May 7, 2019
Also, to add to the above, the
uefipart needs to be built with the PE COFF toolchain, while thekernelandarchitectureparts I need in ELF format.Thinking of it, I’m using LLVM and LLD, maybe I should try playing with creating a macro wrapping the cc rules for the UEFI and Kernel parts, where the macro itselfs sets copts to specify what linker to use.
katre commentedon May 7, 2019
@wpieterse2825: Have you taken a look at #7260? Once you write
toolchain()targets for your existingcc_toolchain()declarations, you can use the flag to enable platform-based cc toolchain resolution now, which might be simpler than usingcoptsandcrosstool_top. All of the missing features of full multiplatform builds are still present, of course, but it moves you closer to that world.steel-exodus commentedon May 7, 2019
Hi @katre, thanks for mentioning it.
I did try and do that, defining the various architectures and firmware targets. You can have a look here. But when I try and build only with platforms, without specifying the
--cpuparameter, it always tries to build with the MSVC toolchain, which obviously causes problems when linking the binary. I could not figure it out at the time, will give it a try again and let you know my results.steel-exodus commentedon May 7, 2019
@katre I did what you suggested and it worked. Could finally remove the
--cpuflag from my.bazelrcfile as everything is now compiled with platforms. Thanks.katre commentedon May 7, 2019
Excellent, I'm glad it's working, we're trying hard to get this ready enough to enable by default.
21 remaining items
sluongng commentedon Nov 27, 2023
Hey folks, any update on support for multiple target platforms?
Today we are seeing this warning
and the code for this warning points back to this issue.
katre commentedon Nov 27, 2023
Trying to get Bazel to directly support multiple values for
--platformsis semantically very confusing, so we've made the decision to leave the specific semantics up to rule authors, who know their users' needs and ecosystems better.To that end, my concrete recommendations are:
platformand/orplatformsattributes to appropriate rules, using the features from https://github.com/bazelbuild/proposals/blob/main/designs/2023-06-08-standard-platform-transitions.md, once we get those released (we're setting up the release process for that now, please imagine the sound of bureaucracy happening in the background).--android_platforms, where that makes sense (for example, Android uses this to create a fat APK from a singleandroid_binarytarget).--platformsflag to be less confusing (The platforms flag should be single-valued #19807):--platform(flag migrations are hard, sorry), leaving--platformsas a deprecated legacy name.--platforms.Silic0nS0ldier commentedon Nov 7, 2024
I think I spied a regression in the
--platformsinvalid options handling due to 81acd2a#diff-a437b5091032394bcb6af037a2c2ffc063f330a9092144f498edb2feda14d782R252.The check is performed in
PlatformConfiguration.reportInvalidOptionswhich usesPlatformOptions, however the instance it receives has.platformsalready normalised so extraneous platforms are silently ignored (previously a warning was emitted).katre commentedon Nov 7, 2024
Yes, there's a lot of confusion about the right way to handle this.
github-actions commentedon Jan 12, 2026
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.
hisener commentedon Jan 12, 2026
I think we should keep this feature request open.
sluongng commentedon Jan 12, 2026
@hisener could you please elaborate more on your use case?
This issue is very old and mostly out of date? The community is now in favor of using Bazel Transitions to set the target platform for each individual target.
So let's say if you have a
cc_binarythat you want to build for a specific target, you can do something like thisPopular rules, such as rules_go, offer platform transitions as a direct attribute for more convenience. There are also things like with_cfg to scope down the transitions easier.
So I don't see a reason to keep this one open.
hisener commentedon Jan 12, 2026
When I subscribed to this issue, our use case was using different JDKs for some targets. It's not possible out of the box. We ended up using with_cfg as you mentioned. However, there are a bunch of gotchas, e.g.,
env_inheritdoesn't work in some cases.Thus, I think having something built-in to define a target's intended platform is still valuable.
fmeum commentedon Jan 12, 2026
with_cfg should support
env_inheritand generally aims to shield you from such transition gotchas. Could you file an issue for this over on the with_cfg.bzl repo?hisener commentedon Jan 12, 2026
Yes, it's on my list for a while. 😞 I'll try to find some time.
This is what I wrote in October:
fmeum commentedon Jan 12, 2026
env_inheritonjava_testis backed byRunEnvironmentInfoin Bazel 7 and higher and with_cfg forwards this provider, so I would expect that to work without the hack necessary for nativejava_test.sluongng commentedon Jan 12, 2026
I think since the direction for configuring targeted platforms has been decided to be using transitions, and viable transition machinery do exist today, it's safe to close this issue to reduce noise (some information from 2018-2019 is no longer applicable to 2026). We can iron out the UX in newer issues that are more focused on the exact problem rather than this broad topic.
There are some remaining TODOs from this issue, though:
But other than that, we should move the with_cfg conversation to a different place and close this one.
gregestren commentedon Jan 12, 2026
Agreed on closing for more focused requests. (and thanks for supporting that conclusion @hisener ).
Acknowledged that there are various ways to kind of achieve this functionality and a canonical best practice API remains elusive.