Skip to content

Support gen2gen Rules (CustomRuleSourceConfig, ArtifactLocationTransformer) #8140

@JamyDev

Description

@JamyDev

Description of the feature request:

Add an extension point for the following:

  1. CustomRuleSourceConfig -> allow us to set fields that should be considered sources for a custom rule added by a Kind.Provider (in our case cff_srcs isn't considered but we'd like it to be)
    i. I've considered modifying the Kind.Provider, but I didn't want to make breaking changes, so I propose a new extension point
  2. ArtifactLocationTransformer -> Allow mapping artifact location paths to bypass generated code back to the source.
    i. In our below case this lets us map a <srcfile>_cffgen.go back into <srcfile>.go, so packages stay correctly together without duplicate definition warnings (if we bundle both sources, exports would be defined twice)

Which category does this issue belong to?

GoLand

What underlying problem are you trying to solve with this feature?

At Uber we use CFF (a code generator) to turn "easy to read" go code, into more complex, runtime performant go code.

In bazel we have this set up as a cff rule that is embedded as the sources for the go_library rule:

BUILD.bazel

cff(
    name = "cff",
    srcs = [
        "regular_go_src.go",
    ],
    cff_srcs = ["pre_cff_src.go"],
    importpath = "some/import/path",
    visibility = ["//visibility:public"],
)

go_library(
    name = "go_default_library",
    srcs = [
        "regular_go_src.go",
        ":cff",
    ],
    importpath = "some/import/path",
    visibility = ["//visibility:public"],
)

This ends up meaning the pre_cff_src.go is not part of the library package, as when we embed :cff, it will only embed the bazel_out generated code (<srcfile>_cffgen.go).

Adding a Kind.Provider for the CFF rule (CFF("cff", LanguageClass.GO, RuleType.LIBRARY),) helps a bit, but there's still challenges with navigating from a non-cff library, into an import that is a cff library.

What operating system, Intellij IDE and programming languages are you using? Please provide specific versions.

GoLand Mac, 2025.3.1.1

Have you found anything relevant by searching the web?

N/A in depth research done in alternatives

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

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Untriaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions