Skip to content

[Bazel] Replace the use of @bazel_tools//src/conditions:host_windows#1683

Open
stevenlr wants to merge 1 commit intoemscripten-core:mainfrom
stevenlr:bazel_host_windows_constraint
Open

[Bazel] Replace the use of @bazel_tools//src/conditions:host_windows#1683
stevenlr wants to merge 1 commit intoemscripten-core:mainfrom
stevenlr:bazel_host_windows_constraint

Conversation

@stevenlr
Copy link
Contributor

This is a followup of #1682.

This has been deprecated and will be removed in Bazel 10.

This implementation of the platform information retrieval is similar to what is done in Skylib (see https://github.com/bazelbuild/bazel-skylib/blob/56a2abbaf131332835ab2721a258ea3c763a7178/rules/private/copy_file_private.bzl#L117) however this does not use the experimental platform API.

  • We define a provider that gives the script extension for a given platform and a rule to instantiate it.
  • We define a target with the platform_info rule that selects the correct settings based on constraints from @platform.
  • During toolchain config creation we inject that target using the exec config.
  • We can then retrieve the platform information in the toolchain config (namely the script extension here).

Note that the platform information could have given a simple is_windows flag, but I chose this implementation because it matches the previous one more closely.

Note also that it was not possible to keep the script_extension attribute as string, because the cfg field is not supported on string attributes.

This has been deprecated and will be removed in Bazel 10.

This implementation of the platform information retrieval is similar to
what is done in Skylib (see https://github.com/bazelbuild/bazel-skylib/blob/56a2abbaf131332835ab2721a258ea3c763a7178/rules/private/copy_file_private.bzl#L117)
however this does not use the experimental platform API.

- We define a provider that gives the script extension for a given platform
  and a rule to instantiate it.
- We define a target with the `platform_info` rule that selects the correct
  settings based on constraints from `@platform`.
- During toolchain config creation we inject that target **using the `exec` config**.
- We can then retrieve the platform information in the toolchain config
  (namely the script extension here).

Note that the platform information could have given a simple `is_windows` flag,
but I chose this implementation because it matches the previous one more closely.

Note also that it was not possible to keep the `script_extension` attribute as
string, because the `cfg` field is not supported on string attributes.
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

I wonder if we could somehow depend on bash on windows (it comes with git for example) and just delete the bat files?

@stevenlr
Copy link
Contributor Author

Both Bazel and its ecosystem have been moving away from depending on Bash on Windows. So it's not really recommended.

I've seen the discussion on a previous PR about using py_binarys for Emscripten scripts. However doing this properly would require quite a bit of infrastructure and I would actually recommend doing it in Emscripten directly instead of here, because the infrastructure would depend on the Emscripten version (because you would have to also define py_librarys, dependencies between them, data targets, handle runfiles correctly, etc, quite a bit of work!).

A simpler approach could be to use the Python interpreter as the tool for each cc toolchain action, and the first argument would be the script (emar.py, emcc.py, etc). That way we could remove the wrapper scripts but still keep all Bazel stuff in this repo.

I could take a swing at it this week-end or early next week, see where it leads, but it's a separate topic anyway.

@stevenlr
Copy link
Contributor Author

stevenlr commented Mar 1, 2026

Hi, I've been trying to remove the need for the batch and bash files, however I don't think it's doable. It seems like Emscripten expects the EM_CONFIG environment variable to have an absolute path. Bazel doesn't allow us to do that because of reproducibility. I don't see any way of avoiding some kind of wrapper that does non-hermetic stuff. Sure we could make the wrappers Python (it would be platform-independent), or even make it only 1 wrapper instead of 4, but I'm not sure the complexity is worth it.

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