Skip to content

Commit b5a6444

Browse files
committed
Add example that reproduces proto issue
1 parent 3041436 commit b5a6444

File tree

8 files changed

+222
-2
lines changed

8 files changed

+222
-2
lines changed

BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ gazelle(
1414
],
1515
command = "update-repos",
1616
)
17+
18+
filegroup(
19+
name = "go_mod",
20+
srcs = [
21+
"go.mod",
22+
"go.sum",
23+
],
24+
visibility = ["//:__subpackages__"],
25+
)

WORKSPACE.bazel

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,50 @@ workspace(name = "com_github_cloneable_rules_ent")
44

55
# ent_go_repositories()
66

7+
<<<<<<< HEAD
78
# load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
89

910
# go_rules_dependencies()
1011

1112
# go_register_toolchains(version = "host")
1213

1314
# load("@com_github_cloneable_rules_ent//:deps.bzl", "ent_go_dependencies")
15+
=======
16+
# gazelle:repository_macro deps.bzl%ent_go_dependencies
17+
>>>>>>> 281959a (Add example that reproduces proto issue)
1418

15-
# ent_go_dependencies()
19+
load("//:workspace.bzl", "install_workspace_dependencies")
1620

17-
#gazelle:repository_macro deps.bzl%ent_go_dependencies
21+
install_workspace_dependencies()
22+
23+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
24+
25+
# Gazelle -- (for the example)
26+
27+
# gazelle:repo bazel_gazelle
28+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
29+
30+
31+
# Protobuf -- (for the example)
32+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
33+
34+
protobuf_deps()
35+
36+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
37+
38+
rules_proto_dependencies()
39+
40+
rules_proto_toolchains()
41+
42+
# Go -- (for the example)
43+
44+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
45+
46+
go_rules_dependencies()
47+
48+
go_register_toolchains(version = "1.19.5")
49+
50+
# Ent -- (for the example)
51+
load("@com_github_cloneable_rules_ent//:deps.bzl", "ent_go_dependencies")
52+
53+
ent_go_dependencies()

example/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/cloneable/rules_ent
2+
3+
go 1.19

example/protos/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
3+
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
4+
5+
proto_library(
6+
name = "user_settings_proto",
7+
srcs = ["user_settings.proto"],
8+
visibility = ["//visibility:public"],
9+
)
10+
11+
go_proto_library(
12+
name = "user_settings_go_proto",
13+
importpath = "github.com/cloneable/rules_ent/example/protos",
14+
proto = ":user_settings_proto",
15+
visibility = ["//visibility:public"],
16+
)
17+
18+
go_library(
19+
name = "proto",
20+
embed = [":user_settings_go_proto"],
21+
importpath = "github.com/cloneable/rules_ent/example/protos",
22+
visibility = ["//visibility:public"],
23+
)

example/protos/user_settings.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
syntax = "proto3";
2+
3+
package user_settings;
4+
5+
message UserSettings {
6+
bool color_blind = 1;
7+
AppLanguage lang = 2;
8+
}
9+
10+
enum AppLanguage {
11+
ENGLISH = 0;
12+
FRENCH = 1;
13+
PORTUGUESE = 2;
14+
}

example/schema/BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
load("//:defs.bzl", "go_ent_library")
3+
4+
go_library(
5+
name = "schema",
6+
srcs = ["user.go"],
7+
importpath = "github.com/cloneable/rules_ent/example/schema",
8+
visibility = ["//visibility:public"],
9+
deps = [
10+
"//example/protos:proto",
11+
"@com_github_google_uuid//:uuid",
12+
"@io_entgo_ent//:ent",
13+
"@io_entgo_ent//schema/field",
14+
"@io_entgo_ent//schema/mixin",
15+
],
16+
)
17+
18+
go_ent_library(
19+
name = "db",
20+
entities = [
21+
"user",
22+
],
23+
gomod = "//:go_mod",
24+
importpath = "github.com/cloneable/rules_ent/example/db",
25+
schema = ":schema",
26+
visibility = ["//:__subpackages__"],
27+
)

example/schema/user.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package schema
2+
3+
import (
4+
"entgo.io/ent"
5+
"entgo.io/ent/schema/field"
6+
"entgo.io/ent/schema/mixin"
7+
"github.com/cloneable/rules_ent/example/protos"
8+
"github.com/google/uuid"
9+
)
10+
11+
type User struct {
12+
ent.Schema
13+
}
14+
15+
func (User) Fields() []ent.Field {
16+
return []ent.Field{
17+
field.UUID("id", uuid.UUID{}).Default(uuid.New),
18+
field.String("email").Unique(),
19+
field.Bytes("preferences").GoType(&protos.UserSettings{}),
20+
}
21+
}
22+
23+
func (User) Mixin() []ent.Mixin {
24+
return []ent.Mixin{
25+
mixin.Time{},
26+
}
27+
}
28+
29+
func (User) Edges() []ent.Edge {
30+
return []ent.Edge{}
31+
}

workspace.bzl

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
""" Morf workspace dependencies """
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
4+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
5+
6+
def install_workspace_dependencies():
7+
""" Defines repositories for core rules sets
8+
"""
9+
10+
# Open source license validations
11+
http_archive(
12+
name = "rules_license",
13+
urls = [
14+
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.3/rules_license-0.0.3.tar.gz",
15+
"https://github.com/bazelbuild/rules_license/releases/download/0.0.3/rules_license-0.0.3.tar.gz",
16+
],
17+
sha256 = "00ccc0df21312c127ac4b12880ab0f9a26c1cff99442dc6c5a331750360de3c3",
18+
)
19+
20+
# Protobuf-related rules
21+
http_archive(
22+
name = "com_google_protobuf",
23+
sha256 = "9c0fd39c7a08dff543c643f0f4baf081988129a411b977a07c46221793605638",
24+
strip_prefix = "protobuf-3.20.3",
25+
urls = [
26+
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.20.3.tar.gz",
27+
"https://github.com/protocolbuffers/protobuf/archive/v3.20.3.tar.gz",
28+
],
29+
)
30+
31+
http_archive(
32+
name = "rules_proto",
33+
sha256 = "e017528fd1c91c5a33f15493e3a398181a9e821a804eb7ff5acdd1d2d6c2b18d",
34+
strip_prefix = "rules_proto-4.0.0-3.20.0",
35+
urls = [
36+
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0-3.20.0.tar.gz",
37+
],
38+
)
39+
40+
# go-related rules
41+
http_archive(
42+
name = "io_bazel_rules_go",
43+
sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
44+
urls = [
45+
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
46+
"https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
47+
],
48+
)
49+
50+
http_archive(
51+
name = "bazel_skylib",
52+
urls = [
53+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
54+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
55+
],
56+
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
57+
)
58+
59+
# gazelle
60+
http_archive(
61+
name = "bazel_gazelle",
62+
sha256 = "ecba0f04f96b4960a5b250c8e8eeec42281035970aa8852dda73098274d14a1d",
63+
urls = [
64+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
65+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
66+
],
67+
)
68+
69+
# buildifier
70+
http_archive(
71+
name = "com_github_bazelbuild_buildtools",
72+
sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
73+
strip_prefix = "buildtools-4.2.2",
74+
urls = [
75+
"https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz",
76+
],
77+
)

0 commit comments

Comments
 (0)