Skip to content

Generate Google modules #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ The package can be installed by adding `:protobuf` to your list of dependencies
```elixir
def deps do
[
{:protobuf, "~> 0.10.0"},
# Only for files generated from Google's protos.
# Can be ignored if you don't use Google's protos.
# Or you can generate the code by yourself.
{:google_protos, "~> 0.1"}
{:protobuf, "~> 0.13.0"}
]
end
```

### Google Protos

Since `:protobuf` version `0.13.0` we include all of the well known Google Protobuf modules. This conflicts with the deprecated `:google_protos` package. Please remove the `:google_protos` package from your dependencies and run `mix deps.unlock --unused`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's actually true 🤔 If I pull 0.13.0 now, it won't contain these new files. Perhaps you meant the next patch/minor version?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, fixed it on #381. Thank you for pointing out!


## Features

* Define messages with DSL
Expand Down
2 changes: 1 addition & 1 deletion lib/elixirpb.pb.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Elixirpb.FileOptions do
@moduledoc false

use Protobuf, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto2

field :module_prefix, 1, optional: true, type: :string
end
8 changes: 8 additions & 0 deletions lib/google/protobuf/any.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Google.Protobuf.Any do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :type_url, 1, type: :string, json_name: "typeUrl"
field :value, 2, type: :bytes
end
2 changes: 1 addition & 1 deletion lib/google/protobuf/compiler/plugin.pb.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Google.Protobuf.Compiler.CodeGeneratorResponse.Feature do
@moduledoc false

use Protobuf, enum: true, syntax: :proto2, protoc_gen_elixir_version: "0.13.0"
use Protobuf, enum: true, protoc_gen_elixir_version: "0.13.0", syntax: :proto2

field :FEATURE_NONE, 0
field :FEATURE_PROTO3_OPTIONAL, 1
Expand Down
8 changes: 8 additions & 0 deletions lib/google/protobuf/duration.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Google.Protobuf.Duration do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :seconds, 1, type: :int64
field :nanos, 2, type: :int32
end
5 changes: 5 additions & 0 deletions lib/google/protobuf/empty.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Google.Protobuf.Empty do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3
end
7 changes: 7 additions & 0 deletions lib/google/protobuf/field_mask.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Google.Protobuf.FieldMask do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :paths, 1, repeated: true, type: :string
end
52 changes: 52 additions & 0 deletions lib/google/protobuf/struct.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
defmodule Google.Protobuf.NullValue do
@moduledoc false

use Protobuf, enum: true, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :NULL_VALUE, 0
end

defmodule Google.Protobuf.Struct.FieldsEntry do
@moduledoc false

use Protobuf, map: true, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :key, 1, type: :string
field :value, 2, type: Google.Protobuf.Value
end

defmodule Google.Protobuf.Struct do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :fields, 1, repeated: true, type: Google.Protobuf.Struct.FieldsEntry, map: true
end

defmodule Google.Protobuf.Value do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

oneof :kind, 0

field :null_value, 1,
type: Google.Protobuf.NullValue,
json_name: "nullValue",
enum: true,
oneof: 0

field :number_value, 2, type: :double, json_name: "numberValue", oneof: 0
field :string_value, 3, type: :string, json_name: "stringValue", oneof: 0
field :bool_value, 4, type: :bool, json_name: "boolValue", oneof: 0
field :struct_value, 5, type: Google.Protobuf.Struct, json_name: "structValue", oneof: 0
field :list_value, 6, type: Google.Protobuf.ListValue, json_name: "listValue", oneof: 0
end

defmodule Google.Protobuf.ListValue do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :values, 1, repeated: true, type: Google.Protobuf.Value
end
8 changes: 8 additions & 0 deletions lib/google/protobuf/timestamp.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Google.Protobuf.Timestamp do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :seconds, 1, type: :int64
field :nanos, 2, type: :int32
end
71 changes: 71 additions & 0 deletions lib/google/protobuf/wrappers.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
defmodule Google.Protobuf.DoubleValue do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :double
end

defmodule Google.Protobuf.FloatValue do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :float
end

defmodule Google.Protobuf.Int64Value do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :int64
end

defmodule Google.Protobuf.UInt64Value do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :uint64
end

defmodule Google.Protobuf.Int32Value do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :int32
end

defmodule Google.Protobuf.UInt32Value do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :uint32
end

defmodule Google.Protobuf.BoolValue do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :bool
end

defmodule Google.Protobuf.StringValue do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :string
end

defmodule Google.Protobuf.BytesValue do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.13.0", syntax: :proto3

field :value, 1, type: :bytes
end
15 changes: 12 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule Protobuf.Mixfile do

defp aliases do
[
gen_bootstrap_protos: [&build_escript/1, &gen_bootstrap_protos/1],
gen_bootstrap_protos: [&build_escript/1, &gen_bootstrap_protos/1, &gen_google_protos/1],
gen_test_protos: [&build_escript/1, &create_generated_dir/1, &gen_test_protos/1],
test: [
&build_escript/1,
Expand Down Expand Up @@ -179,8 +179,8 @@ defmodule Protobuf.Mixfile do
protoc!("-I \"#{proto_bench}\"", "./bench/lib", benchmark_proto_files())
end

defp gen_google_test_protos(_args) do
proto_root = path_in_protobuf_source(["src"])
defp gen_google_protos(_args) do
proto_src = path_in_protobuf_source(["src"])

files = ~w(
google/protobuf/any.proto
Expand All @@ -190,6 +190,15 @@ defmodule Protobuf.Mixfile do
google/protobuf/struct.proto
google/protobuf/timestamp.proto
google/protobuf/wrappers.proto
)

protoc!("-I \"#{proto_src}\"", "./lib", files)
end

defp gen_google_test_protos(_args) do
proto_root = path_in_protobuf_source(["src"])

files = ~w(
google/protobuf/test_messages_proto2.proto
google/protobuf/test_messages_proto3.proto
)
Expand Down
Loading