• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Generates C# source files from .proto files.
3# You first need to make sure protoc has been built (see instructions on
4# building protoc in root of this repository)
5
6set -e
7
8# cd to repository root
9pushd $(dirname $0)/..
10
11# Protocol buffer compiler to use. If the PROTOC variable is set,
12# use that. Otherwise, probe for expected locations under both
13# Windows and Unix.
14PROTOC_LOCATIONS=(
15  "bazel-bin/protoc"
16  "solution/Debug/protoc.exe"
17  "cmake/build/Debug/protoc.exe"
18  "cmake/build/Release/protoc.exe"
19)
20if [ -z "$PROTOC" ]; then
21  for protoc in "${PROTOC_LOCATIONS[@]}"; do
22    if [ -x "$protoc" ]; then
23      PROTOC="$protoc"
24    fi
25  done
26  if [ -z "$PROTOC" ]; then
27    echo "Unable to find protocol buffer compiler."
28    exit 1
29  fi
30fi
31
32# descriptor.proto and well-known types
33$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
34    --csharp_opt=base_namespace=Google.Protobuf \
35    --csharp_opt=file_extension=.pb.cs \
36    src/google/protobuf/descriptor.proto \
37    src/google/protobuf/any.proto \
38    src/google/protobuf/api.proto \
39    src/google/protobuf/duration.proto \
40    src/google/protobuf/empty.proto \
41    src/google/protobuf/field_mask.proto \
42    src/google/protobuf/source_context.proto \
43    src/google/protobuf/struct.proto \
44    src/google/protobuf/timestamp.proto \
45    src/google/protobuf/type.proto \
46    src/google/protobuf/wrappers.proto \
47    src/google/protobuf/compiler/plugin.proto
48
49# Test protos
50# Note that this deliberately does *not* include old_extensions1.proto
51# and old_extensions2.proto, which are generated with an older version
52# of protoc.
53$PROTOC -Isrc -I. \
54    --experimental_allow_proto3_optional \
55    --experimental_editions \
56    --csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \
57    --csharp_opt=file_extension=.pb.cs \
58    --descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \
59    --include_source_info \
60    --include_imports \
61    conformance/test_protos/test_messages_edition2023.proto \
62    csharp/protos/map_unittest_proto3.proto \
63    csharp/protos/unittest_issues.proto \
64    csharp/protos/unittest_custom_options_proto3.proto \
65    csharp/protos/unittest_proto3.proto \
66    csharp/protos/unittest_import_proto3.proto \
67    csharp/protos/unittest_import_public_proto3.proto \
68    csharp/protos/unittest.proto \
69    csharp/protos/unittest_import.proto \
70    csharp/protos/unittest_import_public.proto \
71    csharp/protos/unittest_issue6936_a.proto \
72    csharp/protos/unittest_issue6936_b.proto \
73    csharp/protos/unittest_issue6936_c.proto \
74    csharp/protos/unittest_selfreferential_options.proto \
75    editions/golden/test_messages_proto3_editions.proto \
76    editions/golden/test_messages_proto2_editions.proto \
77    src/google/protobuf/unittest_well_known_types.proto \
78    src/google/protobuf/test_messages_proto3.proto \
79    src/google/protobuf/test_messages_proto2.proto \
80    src/google/protobuf/unittest_features.proto \
81    src/google/protobuf/unittest_legacy_features.proto \
82    src/google/protobuf/unittest_proto3_optional.proto \
83    src/google/protobuf/unittest_retention.proto
84
85# AddressBook sample protos
86$PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \
87    --csharp_opt=file_extension=.pb.cs \
88    examples/addressbook.proto
89
90# Conformance tests
91$PROTOC -I. --csharp_out=csharp/src/Google.Protobuf.Conformance \
92    --csharp_opt=file_extension=.pb.cs \
93    conformance/conformance.proto
94