Skip to content

Declare a "scalac" exec_group so per-action cpu sizing can be set#1842

Open
gergelyfabian wants to merge 1 commit into
bazel-contrib:masterfrom
gergelyfabian:exec-groups-scalac
Open

Declare a "scalac" exec_group so per-action cpu sizing can be set#1842
gergelyfabian wants to merge 1 commit into
bazel-contrib:masterfrom
gergelyfabian:exec-groups-scalac

Conversation

@gergelyfabian

Copy link
Copy Markdown
Contributor

Adds an empty exec_group("scalac") to every scala rule that compiles Scala sources (scala_library, scala_library_for_plugin_bootstrapping, scala_macro_library, scala_binary, scala_test, scala_junit_test, scala_repl) and wires the Scalac action to it via
exec_group = "scalac" in compile_scala. Also declares the same exec_group on the two aspects that call compile_scala (scrooge_scala_aspect, scala_proto_aspect) — aspects do not inherit exec_groups from the rule they attach to, so they need their own declaration.

The group is intentionally empty (no toolchains / no exec_compatible_with) — its sole purpose is to be a target for the <group>.<key> syntax on exec_properties. This lets a user set exec_properties = {"scalac.<key>": "<value>"} on a target to configure the compile action independently of the target's other actions (test execution, jar packaging, etc.). Without a declared exec_group, Bazel rejects the prefixed key at analysis time.

The action's toolchain resolution and exec platform selection are unchanged: no toolchains or constraints are attached to the group, so the rule's default toolchains still apply to the Scalac action.

scala_proto_library and scrooge_scala_library intentionally do not declare the exec_group on the top-level rule: Bazel does not propagate target-level exec_properties to actions created by attached aspects, so declaring it there would silently drop the user's config. The analysis-time error surfaces the limitation; users needing per-action config for these rules should set exec_properties at the platform level.

Regression coverage:

  • //test:ScalacExecGroup* targets set a scalac.* exec_property on each of the seven rules that support the feature. Removing the rule's exec_group declaration fails analysis on these targets under bazel build test/....
  • test/shell/test_scalac_exec_group.sh uses bazel aquery to verify the property reaches the Scalac action's ExecutionInfo on every regression target, catching removal of exec_group = "scalac" from ctx.actions.run in compile_scala (which would silently reroute the property to the default exec group without failing analysis).
  • //test_expect_failure/scalac_exec_group_on_aspect_rule/... exercises the intentional gap on scala_proto_library and scrooge_scala_library; the same shell test asserts both fail analysis with the expected "non-existent exec groups: scalac" message, so the docs' claim stays honest if Bazel changes behavior or someone adds the exec_group to those rules.

Documents the feature and the aspect-propagation limitation under docs/scalac_exec_group.md.

Adds an empty `exec_group("scalac")` to every scala rule that compiles
Scala sources (scala_library, scala_library_for_plugin_bootstrapping,
scala_macro_library, scala_binary, scala_test, scala_junit_test,
scala_repl) and wires the Scalac action to it via
`exec_group = "scalac"` in `compile_scala`. Also declares the same
exec_group on the two aspects that call `compile_scala`
(scrooge_scala_aspect, scala_proto_aspect) — aspects do not inherit
exec_groups from the rule they attach to, so they need their own
declaration.

The group is intentionally empty (no toolchains / no
exec_compatible_with) — its sole purpose is to be a target for the
`<group>.<key>` syntax on `exec_properties`. This lets a user set
`exec_properties = {"scalac.<key>": "<value>"}` on a target to
configure the compile action independently of the target's other
actions (test execution, jar packaging, etc.). Without a declared
exec_group, Bazel rejects the prefixed key at analysis time.

The action's toolchain resolution and exec platform selection are
unchanged: no toolchains or constraints are attached to the group,
so the rule's default toolchains still apply to the Scalac action.

`scala_proto_library` and `scrooge_scala_library` intentionally do not
declare the exec_group on the top-level rule: Bazel does not propagate
target-level `exec_properties` to actions created by attached aspects,
so declaring it there would silently drop the user's config. The
analysis-time error surfaces the limitation; users needing per-action
config for these rules should set exec_properties at the platform
level.

Regression coverage:

- //test:ScalacExecGroup* targets set a scalac.* exec_property on each
  of the seven rules that support the feature. Removing the rule's
  exec_group declaration fails analysis on these targets under `bazel
  build test/...`.
- test/shell/test_scalac_exec_group.sh uses `bazel aquery` to verify
  the property reaches the Scalac action's ExecutionInfo on every
  regression target, catching removal of `exec_group = "scalac"` from
  `ctx.actions.run` in compile_scala (which would silently reroute the
  property to the default exec group without failing analysis).
- //test_expect_failure/scalac_exec_group_on_aspect_rule/... exercises
  the intentional gap on scala_proto_library and scrooge_scala_library;
  the same shell test asserts both fail analysis with the expected
  "non-existent exec groups: scalac" message, so the docs' claim stays
  honest if Bazel changes behavior or someone adds the exec_group to
  those rules.

Documents the feature and the aspect-propagation limitation under
docs/scalac_exec_group.md.
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.

1 participant