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

genrule chooses script based on host platform rather than execution platform #18584

Closed
jayconrod opened this issue Jun 5, 2023 · 2 comments
Closed
Assignees
Labels
team-Remote-Exec Issues and PRs for the Execution (Remote) team type: bug

Comments

@jayconrod
Copy link
Contributor

jayconrod commented Jun 5, 2023

Description of the bug:

I have a macOS host machine, and I'm using a remote execution service with Windows executors.

This works for normal actions (at least those that avoid Bash or are conscious to use Powershell), but it fails for genrule. genrule has attributes cmd_ps, cmd_sh, cmd_bat, cmd. Bazel selects either cmd_ps or cmd_bat if the host machine is Windows and falls back to cmd.

It should select the script based on the execution platform, not the host platform.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Below is a small example, as self-contained as I could get it. To reproduce, you'll need a remote execution service with Windows machines though, which I expect is rare.

-- BUILD --
genrule(
    name = "hello",
    outs = ["hello.txt"],
    cmd = "do_not_run",
    cmd_ps = "Set-Content -Path $@ -Value 'hello'",
)

platform(
    name = "windows_amd64",
    constraint_values = [
        "@platforms//os:windows",
        "@platforms//cpu:x86_64",
    ],
    exec_properties = {
        "Pool": "windows",
    },
)
-- .bazelrc --
build:engflow --remote_cache=grpcs://kyanite.cluster.engflow.com
build:engflow --remote_executor=grpcs://kyanite.cluster.engflow.com
build:engflow --bes_backend=grpcs://kyanite.cluster.engflow.com
build:engflow --bes_results_url=https://kyanite.cluster.engflow.com/invocation/
build:engflow --tls_client_certificate=/Users/jay/.secrets/kyanite.crt
build:engflow --tls_client_key=/Users/jay/.secrets/kyanite.key

build:windows --platforms=//:windows_amd64
build:windows --host_platform=//:windows_amd64

Run with:

bazel build --verbose_failures --subcommands --config=engflow --config=windows //:hello

Error output:

SUBCOMMAND: # //:hello [action 'Executing genrule //:hello', configuration: d4de5ce9c2e00ceef8dc814dd8ca9ff265a3fbf8cd39f29d25d353798e0aaa0a, execution platform: //:windows_amd64]
(cd /private/var/tmp/_bazel_jay/6ed3f141bd98e3e79c69ec8eab59bdfb/execroot/__main__ && \
  exec env - \
    PATH=/Users/jay/Library/Caches/bazelisk/downloads/bazelbuild/bazel-6.2.1-darwin-arm64/bin:/Users/jay/bin:/opt/go/installed/bin:/opt/google-cloud-sdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/apache-maven-3.8.6/bin:/opt/prometheus-2.37.0-rc.0.darwin-arm64:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jay/go/bin:/Users/jay/Code/depot_tools:/opt/homebrew/opt/[email protected]/libexec/bin \
  c:/tools/msys64/usr/bin/bash.exe -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; do_not_run')
# Configuration: d4de5ce9c2e00ceef8dc814dd8ca9ff265a3fbf8cd39f29d25d353798e0aaa0a
# Execution platform: //:windows_amd64
ERROR: /Users/jay/Code/scratch/BUILD:1:8: Executing genrule //:hello failed: (Exit 34): Remote Execution Failure:
Internal: ChALVi9MaQ9CrKDcc0LvhbMMGiUKINzUijJzaXveNWnRcW7SmwOuDFuRH4-t-7h1pNt9R0fHEKAB: ERROR: external/bazel/src/main/native/windows/process.cc(202): CreateProcessW("c:\tools\msys64\usr\bin\bash.exe" -c "source external/bazel_tools/tools/genrule/genrule-setup.sh; do_not_run"): The system cannot find the file specified.
 (error: 2)

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 6.2.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

n/a

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

n/a

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

Not as far as I know

Have you found anything relevant by searching the web?

no

Any other information, logs, or outputs that you want to share?

Loosely related issues

@Pavank1992 Pavank1992 added the team-Remote-Exec Issues and PRs for the Execution (Remote) team label Jun 6, 2023
@wilwell wilwell removed the untriaged label Jun 6, 2023
@tjgq
Copy link
Contributor

tjgq commented Jun 6, 2023

This is probably because of this TODO. I'll look into fixing it.

tjgq added a commit to tjgq/bazel that referenced this issue Jun 6, 2023
Currently the host platform is used, which fails when using a Windows remote
executor from a non-Windows host.

Also change GenRuleWindowsConfiguredTargetTest to run on every host platform.

Fixes bazelbuild#18584.
tjgq added a commit to tjgq/bazel that referenced this issue Jun 6, 2023
Currently the host platform is used, which fails when using a Windows remote
executor from a non-Windows host.

Also change GenRuleWindowsConfiguredTargetTest to run on every host platform.

Fixes bazelbuild#18584.
@jayconrod
Copy link
Contributor Author

Thanks! Really appreciate the quick fix. I've verified this works in our remote cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Remote-Exec Issues and PRs for the Execution (Remote) team type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants