Skip to content

Commit

Permalink
Patch rulegen to support early loading of apple_support
Browse files Browse the repository at this point in the history
  • Loading branch information
aaliddell committed Feb 7, 2024
1 parent a0c56d1 commit ccc6d66
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions MODULE.bazel
Expand Up @@ -70,6 +70,8 @@ local_path_override(
)

# Objective-C
bazel_dep(name = "apple_support", version = "1.11.1")

bazel_dep(name = "rules_proto_grpc_objc", version = "0.0.0.rpg.version.placeholder")
local_path_override(
module_name = "rules_proto_grpc_objc",
Expand Down
1 change: 1 addition & 0 deletions examples/objc/objc_grpc_compile/MODULE.bazel
@@ -1,3 +1,4 @@

bazel_dep(name = "apple_support", version = "1.11.1")
bazel_dep(name = "rules_proto_grpc", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_example_protos", version = "0.0.0.rpg.version.placeholder")
Expand Down
1 change: 1 addition & 0 deletions examples/objc/objc_grpc_library/MODULE.bazel
@@ -1,3 +1,4 @@

bazel_dep(name = "apple_support", version = "1.11.1")
bazel_dep(name = "rules_proto_grpc", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_example_protos", version = "0.0.0.rpg.version.placeholder")
Expand Down
1 change: 1 addition & 0 deletions examples/objc/objc_proto_compile/MODULE.bazel
@@ -1,3 +1,4 @@

bazel_dep(name = "apple_support", version = "1.11.1")
bazel_dep(name = "rules_proto_grpc", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_example_protos", version = "0.0.0.rpg.version.placeholder")
Expand Down
1 change: 1 addition & 0 deletions examples/objc/objc_proto_library/MODULE.bazel
@@ -1,3 +1,4 @@

bazel_dep(name = "apple_support", version = "1.11.1")
bazel_dep(name = "rules_proto_grpc", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_example_protos", version = "0.0.0.rpg.version.placeholder")
Expand Down
4 changes: 2 additions & 2 deletions tools/rulegen/c.go
Expand Up @@ -67,14 +67,14 @@ var cProtoLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc_{{ .Lan
],
)`)

var cModuleExtraLines = `bazel_dep(name = "protobuf", version = "23.1")`
var cModuleSuffixLines = `bazel_dep(name = "protobuf", version = "23.1")`

func makeC() *Language {
return &Language{
Name: "c",
DisplayName: "C",
Notes: mustTemplate("Rules for generating C protobuf ``.c`` & ``.h`` files and libraries using `upb <https://github.com/protocolbuffers/upb>`_. Libraries are created with the Bazel native ``cc_library``"),
ModuleExtraLines: cModuleExtraLines,
ModuleSuffixLines: cModuleSuffixLines,
Rules: []*Rule{
&Rule{
Name: "c_proto_compile",
Expand Down
18 changes: 14 additions & 4 deletions tools/rulegen/main.go
Expand Up @@ -153,6 +153,11 @@ func mustWriteLanguageExampleModuleBazelFile(dir string, lang *Language, rule *R
// +2 as we are in the examples/{rule} subdirectory
rootPath := strings.Repeat("../", len(depth) + 2)

if (len(lang.ModulePrefixLines) > 0) {
out.ln()
out.w(lang.ModulePrefixLines)
}

extraDeps := ""
extraLocalOverrides := ""
for _, dep := range lang.DependsOn {
Expand Down Expand Up @@ -184,9 +189,9 @@ local_path_override(
path = "%smodules/%s",
)%s`, lang.Name, extraDeps, rootPath, rootPath, lang.Name, rootPath, lang.Name, extraLocalOverrides)

if (len(lang.ModuleExtraLines) > 0) {
if (len(lang.ModuleSuffixLines) > 0) {
out.ln()
out.w(lang.ModuleExtraLines)
out.w(lang.ModuleSuffixLines)
}

out.ln()
Expand Down Expand Up @@ -363,15 +368,20 @@ func mustWriteModuleBazel(dir, template string, languages []*Language) {

for _, lang := range languages {
out.w("# %s", lang.DisplayName)
if (len(lang.ModulePrefixLines) > 0) {
out.w(lang.ModulePrefixLines)
out.ln()
}

out.w(`bazel_dep(name = "rules_proto_grpc_%s", version = "0.0.0.rpg.version.placeholder")
local_path_override(
module_name = "rules_proto_grpc_%s",
path = "modules/%s",
)`, lang.Name, lang.Name, lang.Name)
out.ln()

if (len(lang.ModuleExtraLines) > 0) {
out.w(lang.ModuleExtraLines)
if (len(lang.ModuleSuffixLines) > 0) {
out.w(lang.ModuleSuffixLines)
out.ln()
}
}
Expand Down
3 changes: 3 additions & 0 deletions tools/rulegen/objc.go
Expand Up @@ -84,12 +84,15 @@ GRPC_DEPS = [
Label("@grpc//src/objective-c:proto_objc_rpc"),
]`)

var objcModulePrefixLines = `bazel_dep(name = "apple_support", version = "1.11.1")` // Need apple_support loaded as early as possible for toolchain

func makeObjc() *Language {
return &Language{
Name: "objc",
DisplayName: "Objective-C",
Notes: mustTemplate("Rules for generating Objective-C protobuf and gRPC ``.m`` & ``.h`` files and libraries using standard Protocol Buffers and gRPC. Libraries are created with the Bazel native ``objc_library``"),
SkipTestPlatforms: []string{"linux", "windows"},
ModulePrefixLines: objcModulePrefixLines,
Rules: []*Rule{
&Rule{
Name: "objc_proto_compile",
Expand Down
4 changes: 2 additions & 2 deletions tools/rulegen/python.go
Expand Up @@ -83,7 +83,7 @@ GRPCLIB_DEPS = [
Label(requirement("grpclib")),
]`)

var pythonModuleExtraLines = `bazel_dep(name = "rules_python", version = "0.29.0")
var pythonModuleSuffixLines = `bazel_dep(name = "rules_python", version = "0.29.0")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.11")`
Expand All @@ -93,7 +93,7 @@ func makePython() *Language {
Name: "python",
DisplayName: "Python",
Notes: mustTemplate("Rules for generating Python protobuf and gRPC ``.py`` files and libraries using standard Protocol Buffers and gRPC or `grpclib <https://github.com/vmagamedov/grpclib>`_. Libraries are created with ``py_library`` from ``rules_python``. To use the fast C++ Protobuf implementation, you can add ``--define=use_fast_cpp_protos=true`` to your build, but this requires you setup the path to your Python headers.\n\n.. note:: If you have proto libraries that produce overlapping import paths, be sure to set ``legacy_create_init=False`` on the top level ``py_binary`` or ``py_test`` to ensure all paths are importable."),
ModuleExtraLines: pythonModuleExtraLines,
ModuleSuffixLines: pythonModuleSuffixLines,
Aliases: map[string]string{
"py_proto_compile": "python_proto_compile",
"py_grpc_compile": "python_grpc_compile",
Expand Down
3 changes: 2 additions & 1 deletion tools/rulegen/types.go
Expand Up @@ -22,7 +22,8 @@ type Language struct {
DependsOn []string

// Extra lines for MODULE.bazel for examples etc
ModuleExtraLines string
ModulePrefixLines string
ModuleSuffixLines string

// Additional CI-specific env vars in the form "K=V"
PresubmitEnvVars map[string]string
Expand Down

0 comments on commit ccc6d66

Please sign in to comment.