Skip to content

fix: Avoid C++ toolchain requirement if possible - #2919

Merged
rickeylev merged 8 commits into
bazel-contrib:mainfrom
fmeum:launcher-maker-toolchain
Nov 22, 2025
Merged

fix: Avoid C++ toolchain requirement if possible#2919
rickeylev merged 8 commits into
bazel-contrib:mainfrom
fmeum:launcher-maker-toolchain

Conversation

@fmeum

@fmeum fmeum commented May 20, 2025

Copy link
Copy Markdown
Member

By making use of the new launcher_maker_toolchain in Bazel 9, rules_python can avoid the requirement for a C++ toolchain targeting the target platform if that platform isn't Windows.

For example, this makes it possible to cross-compile pure Python targets from one Unix to another. Since Java targets have a dependency on Python targets through the proguard_allowlister, this also allows Java targets to be built without any C++ toolchain.

@fmeum
fmeum force-pushed the launcher-maker-toolchain branch from b01c964 to 4769ba5 Compare May 20, 2025 20:10
@rickeylev

Copy link
Copy Markdown
Collaborator

fwiw/fyi: we have a CI job that uses bazel-rolling, in case that's helpful.

Also, a fun trick is using FeatureFlagInfo to detect if a toolchain is present. Something like:

def impl(ctx):
  return FeatureFlagInfo(value=str(ctx.toolchains["foo"] == None))
has_tc = rule(
  implementation = impl,
  toolchains = [toolchain_type("foo", mandatory=False)]

has_tc(name="has_tc")
config_setting("is_has_tc_true", flag_values = {":has_tc": "True"})

alias("launcher_maker", actual = select({
  "is_has_tc_true": ...,
  })
)

@fmeum
fmeum force-pushed the launcher-maker-toolchain branch from 4769ba5 to 0d2cf67 Compare May 21, 2025 08:31
@fmeum

fmeum commented May 21, 2025

Copy link
Copy Markdown
Member Author

Adding a dep on bazel_features isn't easy with rules_python's WORKSPACE setup since it doesn't use two levels of macros. Can we add a call to bazel_features_deps to the relnotes?

@fmeum
fmeum force-pushed the launcher-maker-toolchain branch 4 times, most recently from 4366227 to 8e11859 Compare November 20, 2025 10:26
@fmeum fmeum changed the title Use the launcher_maker toolchain if available fix: Avoid C++ toolchain requirement if possible Nov 20, 2025
@fmeum
fmeum force-pushed the launcher-maker-toolchain branch from 8e11859 to 5f580c9 Compare November 20, 2025 10:32
@fmeum

fmeum commented Nov 20, 2025

Copy link
Copy Markdown
Member Author

@rickeylev @aignas Friendly ping on #2919 (comment). I rebased this PR and updated the PR description to explain the motivation - this is needed to get rid of a transitive dependency on C++ of all Java rules.

@aignas

aignas commented Nov 20, 2025

Copy link
Copy Markdown
Collaborator

If we wanted to avoid the bazel_features introduction we can use the rp_config repo and just check if bazel is version 9 or above.

That said, maybe most of our users on WORKSPACE should either migrate to bzlmod or add bazel_features by this time because it is not sustainable to keep backwards compatibility for too long here.

I'd be +1 for asking them to add bazel_features or to introduce a secondary deps macro. Right now we have py_repository_deps and we could add py_repository_deps_setup. What do you think?

@fmeum
fmeum force-pushed the launcher-maker-toolchain branch from e61a844 to 93dff6a Compare November 21, 2025 09:38
Comment thread tests/base_rules/py_executable_base_tests.bzl Outdated
Comment thread tests/base_rules/py_executable_base_tests.bzl
@rickeylev

Copy link
Copy Markdown
Collaborator

Yeah, lets just add a second deps macro. Workspace makes this painful no matter how we cut it. Might as well provide a utility function everyone can use

@fmeum

fmeum commented Nov 21, 2025

Copy link
Copy Markdown
Member Author

Is a deps macro better than asking users to instantiate bazel_features directly? In WORKSPACE days, I would have actually preferred the latter since the module is released frequently and a dep macro bringing in an outdated version is a net negative.

@fmeum
fmeum force-pushed the launcher-maker-toolchain branch from a174c2d to cc2fa38 Compare November 21, 2025 19:29
@fmeum
fmeum marked this pull request as ready for review November 21, 2025 19:54
@fmeum

fmeum commented Nov 21, 2025

Copy link
Copy Markdown
Member Author

I went with rp_config for now to get CI green without further considerations. Happy to migrate this back to bazel_features if you prefer that.

@rickeylev
rickeylev added this pull request to the merge queue Nov 22, 2025
Merged via the queue into bazel-contrib:main with commit c2ff89f Nov 22, 2025
4 checks passed
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.

3 participants