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: multiplatform support #5055

Closed
laszlocsomor opened this issue Apr 19, 2018 · 9 comments
Closed

bazelrc: multiplatform support #5055

laszlocsomor opened this issue Apr 19, 2018 · 9 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request

Comments

@laszlocsomor
Copy link
Contributor

laszlocsomor commented Apr 19, 2018

Description of the problem / feature request:

I'd like to have some mechanism to use platform-specific flags in bazelrc files.

Feature requests: what underlying problem are you trying to solve with this feature?

Motivation is to let checked-in, project-specific bazelrc files work on all platforms. Flags dealing with paths (e.g. --output_user_root), envvars (e.g. --test_env), and external programs or shells (e.g. --workspace_status_command) are all platform-specific.

@cvcal
Copy link
Contributor

cvcal commented Apr 19, 2018

We've talked about different solutions to this problem in the past, but the easiest solution is to accept multiple rc files (#4502), which will let users keep platform specific flags in the global rc while keeping project specific flags in a workspace rc file. The workspace one can be shared between different platforms.

Other solutions we've considered include checking for a "<platform>.bazelrc" filename, or making the rc file syntax more complicated so it can include some flags on some platforms and not others. Neither of these options seem to solve a problem that #4502 doesn't already address, though, and 4502 has other reasons for needing to happen.

Thoughts?

@cvcal
Copy link
Contributor

cvcal commented Apr 19, 2018

The general platform issue for bazel flags is very much not solved, the solution I mentioned leaves us in basically the following state:

  • host platform: goes in global bazelrc
  • execution platform: if host, in global bazelrc, if remote, likely in the workspace file.
  • target platform: the workspace rc file can contain --config definitions that correspond to the different configurations needed.

I realize this is not ideal, but the "right" solution is not clear to me. The fixes in the other issue will only get us out of the unusable into the "works, I guess" territory.

@ittaiz
Copy link
Member

ittaiz commented Apr 19, 2018 via email

@laszlocsomor
Copy link
Contributor Author

Thoughts?

I don't really have any, you're the domain expert. :)

The fixes in the other issue will only get us out of the unusable into the "works, I guess" territory.

SGTM.

@davido
Copy link
Contributor

davido commented Apr 20, 2018

... and external programs or shells (e.g. --workspace_status_command) are all platform-specific

This is indeed a serious problem. Gerrit Code Review has this content of tools/bazel.rc (committed in the repository):

build --workspace_status_command=./tools/workspace-status.sh

Stamping machinery shells out to cmd.exe on Windows, so that we have to provide a different script: bazel build --workspace_status_command=./tools/workspace-status.cmd .... There is currently no way to specify different option, except to overwrite it on bazel invocation.

One way to fix it is what Buck is doing in genrule by offering cmd_exe: platform specific attributes/options. So that at least for status command it could be fixed by adding platform specific option, Bazel detects the current platform and uses the rights script:

build --workspace_status_command=./tools/workspace-status.sh --workspace_status_command_exe=./tools/workspace-status.cmd

@c-parsons c-parsons added P3 We're not considering working on this, but happy to review a PR. (No assignee) category: extensibility > toolchains labels Apr 21, 2018
@laszlocsomor laszlocsomor added untriaged team-Bazel General Bazel product/strategy issues and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Feb 21, 2019
@dslomov dslomov added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website and removed team-Bazel General Bazel product/strategy issues category: extensibility > toolchains labels Jul 23, 2019
@meteorcloudy
Copy link
Member

Other solutions we've considered include checking for a ".bazelrc" filename, or making the rc file syntax more complicated so it can include some flags on some platforms and not others. Neither of these options seem to solve a problem that #4502 doesn't already address, though,

Although #4502 is closed, we still don't have a solution to add platform specific flags without passing different build options on different platforms (such as --config=windows, --config=macos). I think we still need to come up with a solution for this.

@philwo philwo added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Jul 29, 2019
@meteorcloudy meteorcloudy self-assigned this Aug 26, 2019
meteorcloudy added a commit to meteorcloudy/bazel that referenced this issue 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 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:
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    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, macos, windows or freebsd. It's equivalent to add
    --config=linux on Linux platforms and --config=windows on Windows, etc.

    Fixes bazelbuild/bazel#5055

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

    PiperOrigin-RevId: 265641013
@ZhenshengLee
Copy link

Although this issue is closed, we cannot use cutom platform specific_config setting like

test:@local_config_platform//:host --test_env=LD_LIBRARY_PATH=/gw_demo/target/xlab/sysroot/lib:$LD_LIBRARY_PATH

Correct me if I am wrong. @meteorcloudy
I think we still need to come up with a solution for this.

@meteorcloudy
Copy link
Member

If @local_config_platform//:host always means whatever host platform you are current on, why not just test <flags> so that it always applys?

@ZhenshengLee
Copy link

If @local_config_platform//:host always means whatever host platform you are current on, why not just test <flags> so that it always applys?

Oh, I mean the actual platform specific config, is that I can do the following

build:@tools/platforms//:platform1  ...blablabla configs
build:@tools/platforms//:platform2  ...blablabla configs
test:@tools/platforms//:platform1  ...blablabla configs
test:@tools/platforms//:platform2  ...blablabla configs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants