Skip to content

Use the target platform instead of execution platform when generating… - #109

Closed
sputt wants to merge 1 commit into
keith:mainfrom
sputt:toolchain-fixes
Closed

sputt wants to merge 1 commit into
keith:mainfrom
sputt:toolchain-fixes

Conversation

@sputt

@sputt sputt commented Mar 26, 2025

Copy link
Copy Markdown

When you are producing a binary for a test or executable rule, you must produce it for the current selected target platform. This is not the case for buildifier and buildifier_test.

Update the rule to accept the toolchain files via default value attributes instead of a toolchains attribute. Here's a simple example. On MacOS, you may select a Linux execution platform because your run all your actions via remote execution. However, buildifier needs to be run locally. On buildifier-prebuilt/main, this is what you'll see:

sputt@sputt-mbp2 my_repo % bazel run buildifier 
INFO: Invocation ID: 8a10fad2-96d2-4046-a397-d9afb4890323
INFO: Analyzed target //:buildifier (6 packages loaded, 17 targets configured).
INFO: Found 1 target...
Target //tools/buildifier:buildifier up-to-date:
  bazel-bin/tools/buildifier/buildifier.bash
INFO: Elapsed time: 2.240s, Critical Path: 1.56s
INFO: 4 processes: 4 internal.
INFO: Build completed successfully, 4 total actions
INFO: Running command line: bazel-bin/tools/buildifier/buildifier.bash
/private/var/tmp/_bazel_sputt/ad9530d5bab3fcac80af201dbf653279/external/buildifier_prebuilt~~buildifier_prebuilt_deps_extension~buildifier_linux_amd64/file/buildifier: /private/var/tmp/_bazel_sputt/ad9530d5bab3fcac80af201dbf653279/external/buildifier_prebuilt~~buildifier_prebuilt_deps_extension~buildifier_linux_amd64/file/buildifier: cannot execute binary file

Why is it trying to run a Linux executable locally, when my target platform is MacOS? This is because the toolchain was selected for exec and rendered into the buildifier rule. With this fix applied, we now properly see:

sputt@sputt-mbp2 my_repo % bazel run buildifier --override_module=buildifier_prebuilt=/Users/sputt/buildifier-prebuilt
INFO: Invocation ID: 28515c73-802e-4f4c-946a-c3fb1e9e1b7e
INFO: Analyzed target //:buildifier (53 packages loaded, 742 targets configured).
INFO: Found 1 target...
Target //tools/buildifier:buildifier up-to-date:
  bazel-bin/tools/buildifier/buildifier.bash
INFO: Elapsed time: 2.921s, Critical Path: 1.59s
INFO: 4 processes: 4 internal.
INFO: Build completed successfully, 4 total actions
INFO: Running command line: bazel-bin/tools/buildifier/buildifier.bash
(.venv311) sputt@sputt-mbp2 rocket % 

@sputt

sputt commented Apr 1, 2025

Copy link
Copy Markdown
Author

Suggest @keith for review

@keith

keith commented May 28, 2026

Copy link
Copy Markdown
Owner

i think i messed with this in #146, can you verify it's still an issue with that patch? if so can you add a ci test like i did on that pr to emulate it so we can make sure it doesn't regress

@keith

keith commented Jul 15, 2026

Copy link
Copy Markdown
Owner

lmk if that's still the case

@keith keith closed this Jul 15, 2026
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

Successfully merging this pull request may close these issues.

2 participants