You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/protoc-gen-grpc-swift/Docs.docc/spm-plugin.md
+20-19
Original file line number
Diff line number
Diff line change
@@ -22,18 +22,8 @@ There are multiple ways to do this. Some of the easiest are:
22
22
1. If you are on macOS, installing it via `brew install protobuf`
23
23
2. Download the binary from [Google's github repository](https://github.com/protocolbuffers/protobuf).
24
24
25
-
### Adding the proto files to your target
26
-
27
-
Next, you need to add the `.proto` files for which you want to generate your Swift types to your target's
28
-
source directory. You should also commit these files to your git repository since the generated types
29
-
are now generated on demand.
30
-
31
-
> Note: imports on your `.proto` files will have to include the relative path from the target source to the `.proto` file you wish to import.
32
-
> Files **must** be contained within the target source directory.
33
-
34
25
### Adding the plugin to your manifest
35
26
36
-
After adding the `.proto` files you can now add the plugin to the target inside your `Package.swift` manifest.
37
27
First, you need to add a dependency on `grpc-swift`. Afterwards, you can declare the usage of the plugin
38
28
for your target. Here is an example snippet of a `Package.swift` manifest:
39
29
@@ -61,23 +51,33 @@ let package = Package(
61
51
62
52
### Configuring the plugin
63
53
64
-
Lastly, after you have added the `.proto` files and modified your `Package.swift` manifest, you can now
65
-
configure the plugin to invoke the `protoc` compiler. This is done by adding a `grpc-swift-config.json`
66
-
to the root of your target's source folder. An example configuration file looks like this:
54
+
Configuring the plugin is done by adding a `grpc-swift-config.json` file anywhere in your target's sources. Before you start configuring the plugin, you need to add the `.proto` files to your sources. You should also commit these files to your git repository since the generated types are now generated on demand. It's also important to note that the proto files in your configuration should be in the same directory as the config file. Let's see an example to have a better understanding.
55
+
56
+
Here's an example file structure that looks like this:
57
+
58
+
```text
59
+
Sources
60
+
├── main.swift
61
+
├── ProtoBuf
62
+
├── grpc-swift-config.json
63
+
├── foo.proto
64
+
└── Bar
65
+
└── Bar.proto
66
+
```
67
67
68
68
```json
69
69
{
70
70
"invocations": [
71
71
{
72
72
"protoFiles": [
73
-
"Path/To/Foo.proto",
73
+
"Foo.proto",
74
74
],
75
75
"visibility": "internal",
76
76
"server": false
77
77
},
78
78
{
79
79
"protoFiles": [
80
-
"Bar.proto"
80
+
"Bar/Bar.proto"
81
81
],
82
82
"visibility": "public",
83
83
"client": false,
@@ -87,11 +87,12 @@ to the root of your target's source folder. An example configuration file looks
87
87
}
88
88
```
89
89
90
-
> Note: paths to your `.proto` files will have to include the relative path from the target source to the `.proto` file location.
91
-
> Files **must** be contained within the target source directory.
90
+
> Note: paths to your `.proto` files will have to include the relative path from the config file directory to the `.proto` file location.
91
+
> Files **must** be contained within the same directory as the config file.
92
92
93
-
In the above configuration, you declared two invocations to the `protoc` compiler. The first invocation
94
-
is generating Swift types for the `Foo.proto` file with `internal` visibility. Notice the relative path to the `.proto` file.
93
+
In the above configuration, notice the relative path of the `.proto` file with respect to the configuration file. If you add a file in the `Sources` folder, the plugin would be unable to access it as the path is computed relative to the `grpc-swift-config.json` file. So the `.proto` files have to be added within the `ProtoBuf` folder, with relative paths taken into consideration.
94
+
Here, you declared two invocations to the `protoc` compiler. The first invocation
95
+
is generating Swift types for the `Foo.proto` file with `internal` visibility.
95
96
We have also specified the `server` option and set it to false: this means that server code won't be generated for this proto.
96
97
The second invocation is generating Swift types for the `Bar.proto` file with the `public` visibility.
97
98
Notice the `client` option: it's been set to false, so no client code will be generated for this proto. We have also set
0 commit comments