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

bazelrc: support --enable_platform_specific_config #9246

Closed
wants to merge 2 commits into from

Conversation

meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Aug 26, 2019

When the value of this flag is true, a host platform specific config
section will be enabled if it exists. Bazel recognizes your host
platform as linux, osx, windows or freebsd. It's equivalent to add
--config=linux on Linux platforms and --config=windows on Windows, etc.

Fixes #5055

RELNOTES[NEW]: Platform-specific bazelrc: with --enable_platform_specific_config you can
enable flags in bazelrc according to your host platform.
GOOGLE:

When the value of this flag is true, a host platform specific config
section will be enabled if it exists. Bazel recognizes your host
platform as linux, osx, windows or freebsd. It's equivalent to add
--config=linux on Linux platforms and --config=windows on Windows, etc.

Fixes bazelbuild#5055

RELNOTES[NEW]: Support --enable_platform_specific_config, you can use
this flag to enable flags in bazelrc according to your host platform.
GOOGLE:
@laszlocsomor
Copy link
Contributor

RELNOTES[NEW]: Support --enable_platform_specific_config, you can use
this flag to enable flags in bazelrc according to your host platform.
GOOGLE:

How about this instead:

RELNOTES[NEW]: Platform-specific bazelrc: with --enable_platform_specific_config you can use
enable flags in bazelrc according to your host platform.

@meteorcloudy
Copy link
Member Author

Great, thanks!

OptionValueDescription enablePlatformSpecificConfigDescription,
ListMultimap<String, RcChunkOfArgs> commandToRcArgs) {
if (enablePlatformSpecificConfigDescription == null ||
!(boolean) enablePlatformSpecificConfigDescription.getValue()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this cast safe? Shouldn't it be (Boolean) and check for null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as long as there is a default value, it won't be null and will be converted to the correct type.
See

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

// Find the base set of configs. This does not include the config options that might be
// recursively included.
ImmutableList<ParsedOptionDescription> configInstances =
ImmutableList.copyOf(configValueDescription.getCanonicalInstances());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why make a copy?

(I realize this is old code, just asking.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I actually don't know the reason..

documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"When the value of this flag is true, a host platform specific config section will be "
Copy link
Contributor

Choose a reason for hiding this comment

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

When the value of this flag is true

Could be rewritten as "If true".

... a host platform specific config section will be enabled if it exists

I find that confusing. Using active voice and straight word order feels clearer to me. How about: "... Bazel picks up host-OS-specific config lines from the bazelrc files."

I feel like an example would greatly help too: "For example, if the host OS is Linux and you run bazel build, Bazel would pick up lines starting with build:linux"

linux, osx, windows

macOS is the official name so let's use "macos" instead of "osx".

It's equivalent to add --config=linux on Linux platforms and --config=windows on Windows, etc.

We could be a little clearer here: "Enabling this flag is equivalent to using --config=linux on Linux, --config=windows on Windows, etc."

Putting it together:

If true, Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS identifiers are linux, macos, windows, and freebsd. Enabling this flag is equivalent to using --config=linux on Linux, --config=windows on Windows, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, thanks for helping with the documentation. This is great improvement!

As for the name for mac, it seems we still use osx in a lot of places in our code base. For example,

actual = "@platforms//os:osx",

It prefer to keep the consistence util we decided to migrate everything to macos. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please ask the Apple team what's their preference?

Copy link
Contributor

@laszlocsomor laszlocsomor left a comment

Choose a reason for hiding this comment

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

LGTM modulo the "osx" vs "macos" question.

OptionValueDescription enablePlatformSpecificConfigDescription,
ListMultimap<String, RcChunkOfArgs> commandToRcArgs) {
if (enablePlatformSpecificConfigDescription == null ||
!(boolean) enablePlatformSpecificConfigDescription.getValue()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"When the value of this flag is true, a host platform specific config section will be "
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please ask the Apple team what's their preference?

@philwo
Copy link
Member

philwo commented Aug 27, 2019

This was merged via 5975545.

@philwo philwo closed this Aug 27, 2019
@gunan
Copy link

gunan commented Nov 19, 2019

This looks quite useful to me.
Is there documentation on how to use this?

@meteorcloudy
Copy link
Member Author

@gunan The documentation is here: https://docs.bazel.build/versions/master/command-line-reference.html#flag--enable_platform_specific_config

Here is an example in .bazelrc file:

--enable_platform_specific_config
build:windows --workspace_status_command=command.bat
build:linux --workspace_status_command=command.sh
build:macos --workspace_status_command=command.sh

Then the corresponding option will be enabled for each platform. Be aware, Bazel will only enable those options based on your host platform, instead of execution platform or target platform.

@gunan
Copy link

gunan commented Nov 19, 2019

Is there a way to use this to change definition of certain build configs?

such as:
I want --config=avx to be "--copt=-mavx" in linux, but "--copt=/arch=AVX" on windows.

@meteorcloudy
Copy link
Member Author

No, there is no way to do that currently. But it sounds like a very useful feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bazelrc: multiplatform support
5 participants