diff --git a/MODULE.bazel b/MODULE.bazel index 46549bb1..35db3d55 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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", diff --git a/examples/objc/objc_grpc_compile/MODULE.bazel b/examples/objc/objc_grpc_compile/MODULE.bazel index 65914304..d01995ec 100644 --- a/examples/objc/objc_grpc_compile/MODULE.bazel +++ b/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") diff --git a/examples/objc/objc_grpc_library/MODULE.bazel b/examples/objc/objc_grpc_library/MODULE.bazel index 65914304..d01995ec 100644 --- a/examples/objc/objc_grpc_library/MODULE.bazel +++ b/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") diff --git a/examples/objc/objc_proto_compile/MODULE.bazel b/examples/objc/objc_proto_compile/MODULE.bazel index 65914304..d01995ec 100644 --- a/examples/objc/objc_proto_compile/MODULE.bazel +++ b/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") diff --git a/examples/objc/objc_proto_library/MODULE.bazel b/examples/objc/objc_proto_library/MODULE.bazel index 65914304..d01995ec 100644 --- a/examples/objc/objc_proto_library/MODULE.bazel +++ b/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") diff --git a/tools/rulegen/c.go b/tools/rulegen/c.go index 3aedb23d..12844d27 100644 --- a/tools/rulegen/c.go +++ b/tools/rulegen/c.go @@ -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 `_. Libraries are created with the Bazel native ``cc_library``"), - ModuleExtraLines: cModuleExtraLines, + ModuleSuffixLines: cModuleSuffixLines, Rules: []*Rule{ &Rule{ Name: "c_proto_compile", diff --git a/tools/rulegen/main.go b/tools/rulegen/main.go index 3490ab23..4ce1ae20 100644 --- a/tools/rulegen/main.go +++ b/tools/rulegen/main.go @@ -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 { @@ -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() @@ -363,6 +368,11 @@ 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", @@ -370,8 +380,8 @@ local_path_override( )`, 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() } } diff --git a/tools/rulegen/objc.go b/tools/rulegen/objc.go index f0c8d7a5..41c08f84 100644 --- a/tools/rulegen/objc.go +++ b/tools/rulegen/objc.go @@ -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", diff --git a/tools/rulegen/python.go b/tools/rulegen/python.go index a239ffca..116249d3 100644 --- a/tools/rulegen/python.go +++ b/tools/rulegen/python.go @@ -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")` @@ -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 `_. 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", diff --git a/tools/rulegen/types.go b/tools/rulegen/types.go index 9100d887..e6a0efbf 100644 --- a/tools/rulegen/types.go +++ b/tools/rulegen/types.go @@ -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