-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example where a proto imports another proto. This addtionally exports the Protobuf runtime as a framework into rules_ios. proto_map.txt - this file is used to map protobuf imports to framework names in rules_ios
- Loading branch information
1 parent
e492188
commit 5f310d9
Showing
8 changed files
with
169 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
load("@rules_proto_grpc//objc:defs.bzl", "objc_proto_compile") | ||
load("@rules_proto_grpc//internal:filter_files.bzl", "filter_files") | ||
load("//rules:framework.bzl", "apple_framework") | ||
load("proto_library.bzl", "apple_proto_libary") | ||
load("//rules:framework.bzl", "apple_framework", "apple_framework_packaging") | ||
|
||
exports_files(["*.proto"]) | ||
|
||
proto_library( | ||
name = "sample_proto", | ||
srcs = ["sample.proto"], | ||
# Export protobuf into a framework module | ||
objc_library( | ||
name = "Protobuf_hdrs", | ||
hdrs = ["Protobuf/module.modulemap"], | ||
) | ||
|
||
objc_proto_compile( | ||
name = "sample_objc_proto", | ||
protos = [":sample_proto"], | ||
apple_framework_packaging( | ||
name = "Protobuf", | ||
framework_name = "Protobuf", | ||
transitive_deps = [], | ||
deps = [ | ||
"Protobuf_hdrs", | ||
"@com_github_protocolbuffers_protobuf//:objectivec", | ||
], | ||
) | ||
|
||
# Filter files to sources and headers | ||
filter_files( | ||
name = "sample_objc_proto.m", | ||
extensions = ["m"], | ||
target = "sample_objc_proto", | ||
# Note: the proto_map.txt needs to correspend with the names here | ||
# Specifically calling these Sample or SampleProto | ||
apple_proto_libary( | ||
name = "Sample", | ||
proto_srcs = ["sample.proto"], | ||
deps = [":Dep"], | ||
) | ||
|
||
filter_files( | ||
name = "sample_objc_proto.h", | ||
extensions = ["h"], | ||
target = "sample_objc_proto", | ||
apple_proto_libary( | ||
name = "Dep", | ||
proto_srcs = ["dep.proto"], | ||
) | ||
|
||
apple_framework( | ||
name = "SampleProtoFramework", | ||
srcs = [ | ||
":sample_objc_proto.h", | ||
":sample_objc_proto.m", | ||
], | ||
includes = ["sample_objc_proto"], | ||
platforms = {"ios": "10.0"}, | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_google_protobuf//:protobuf_objc"], | ||
name = "Some", | ||
srcs = ["Some.swift"], | ||
objc_defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1"], | ||
swift_defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1"], | ||
deps = ["Sample"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
framework module Protobuf { | ||
header "GPBAny.pbobjc.h" | ||
header "GPBApi.pbobjc.h" | ||
header "GPBDuration.pbobjc.h" | ||
header "GPBEmpty.pbobjc.h" | ||
header "GPBFieldMask.pbobjc.h" | ||
header "GPBSourceContext.pbobjc.h" | ||
header "GPBStruct.pbobjc.h" | ||
header "GPBTimestamp.pbobjc.h" | ||
header "GPBType.pbobjc.h" | ||
header "GPBWrappers.pbobjc.h" | ||
header "GPBArray.h" | ||
header "GPBBootstrap.h" | ||
header "GPBCodedInputStream.h" | ||
header "GPBCodedOutputStream.h" | ||
header "GPBDescriptor.h" | ||
header "GPBDictionary.h" | ||
header "GPBExtensionInternals.h" | ||
header "GPBExtensionRegistry.h" | ||
header "GPBMessage.h" | ||
header "GPBProtocolBuffers.h" | ||
header "GPBProtocolBuffers_RuntimeSupport.h" | ||
header "GPBRootObject.h" | ||
header "GPBRuntimeTypes.h" | ||
header "GPBUnknownField.h" | ||
header "GPBUnknownFieldSet.h" | ||
header "GPBUtilities.h" | ||
header "GPBWellKnownTypes.h" | ||
header "GPBWireFormat.h" | ||
header "Any.pbobjc.h" | ||
header "Api.pbobjc.h" | ||
header "Duration.pbobjc.h" | ||
header "Empty.pbobjc.h" | ||
header "FieldMask.pbobjc.h" | ||
header "SourceContext.pbobjc.h" | ||
header "Struct.pbobjc.h" | ||
header "Timestamp.pbobjc.h" | ||
header "Type.pbobjc.h" | ||
header "Wrappers.pbobjc.h" | ||
header "GPBArray_PackagePrivate.h" | ||
header "GPBCodedInputStream_PackagePrivate.h" | ||
header "GPBCodedOutputStream_PackagePrivate.h" | ||
header "GPBDescriptor_PackagePrivate.h" | ||
header "GPBDictionary_PackagePrivate.h" | ||
header "GPBMessage_PackagePrivate.h" | ||
header "GPBRootObject_PackagePrivate.h" | ||
header "GPBUnknownFieldSet_PackagePrivate.h" | ||
header "GPBUnknownField_PackagePrivate.h" | ||
header "GPBUtilities_PackagePrivate.h" | ||
export * | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Sample | ||
|
||
func main() { | ||
print(Sample()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
package example; | ||
|
||
message Dep { | ||
string name = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
load("//rules:framework.bzl", "apple_framework") | ||
load("@rules_proto_grpc//objc:defs.bzl", "objc_proto_compile") | ||
load("@rules_proto_grpc//internal:filter_files.bzl", "filter_files") | ||
|
||
## This macro generates a apple_framework _per_ proto_srcs | ||
|
||
def apple_proto_libary(name, proto_srcs, use_proto_map = True, deps = []): | ||
native.proto_library( | ||
name = name + "_proto", | ||
srcs = proto_srcs, | ||
# Internal implementation detail: assume all deps are protos | ||
deps = [d + "_proto" for d in deps], | ||
) | ||
|
||
# proto_map.txt needs to correspend with the names used in rules_ios, this | ||
# allows the devs to import them as as such | ||
if use_proto_map: | ||
extra_protoc_args = [ | ||
"--objc_opt", | ||
# In-practice this might be generated by a repository_rule or a | ||
# build rule - in that case just put the file here: | ||
# e.g. external/my_protos/proto_map.txt | ||
"named_framework_to_proto_path_mappings_path=tests/ios/frameworks/protos/proto_map.txt", | ||
] | ||
extra_protoc_files = [ | ||
"proto_map.txt", | ||
] | ||
else: | ||
extra_protoc_args = [] | ||
extra_protoc_files = [] | ||
|
||
objc_proto_compile( | ||
name = name + "_objc_proto", | ||
protos = [name + "_proto"], | ||
extra_protoc_args = extra_protoc_args, | ||
extra_protoc_files = extra_protoc_files, | ||
verbose = 2, | ||
) | ||
|
||
# Filter files to sources and headers | ||
filter_files( | ||
name = name + ".pbobjc.m", | ||
target = name + "_objc_proto", | ||
extensions = ["m"], | ||
) | ||
|
||
# This has to correspond with rules_ios | ||
filter_files( | ||
name = name + ".pbobjc.h", | ||
target = name + "_objc_proto", | ||
extensions = ["h"], | ||
) | ||
|
||
apple_framework( | ||
name = name, | ||
srcs = [name + ".pbobjc.m", name + ".pbobjc.h"], | ||
objc_defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1"], | ||
swift_defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1"], | ||
deps = [":Protobuf"] + deps, | ||
platforms = {"ios": "10.0"}, | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Sample:tests/ios/frameworks/protos/sample.proto | ||
Dep:tests/ios/frameworks/protos/dep.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters