Skip to content
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

Add example that reproduces proto issue #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ gazelle(
],
command = "update-repos",
)

filegroup(
name = "go_mod",
srcs = [
"go.mod",
"go.sum",
],
visibility = ["//:__subpackages__"],
)
38 changes: 36 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@ workspace(name = "com_github_cloneable_rules_ent")

# load("@com_github_cloneable_rules_ent//:deps.bzl", "ent_go_dependencies")

# ent_go_dependencies()
# gazelle:repository_macro deps.bzl%ent_go_dependencies

#gazelle:repository_macro deps.bzl%ent_go_dependencies
load("//:workspace.bzl", "install_workspace_dependencies")

install_workspace_dependencies()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

# Gazelle -- (for the example)

# gazelle:repo bazel_gazelle
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")


# Protobuf -- (for the example)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()

# Go -- (for the example)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.5")

# Ent -- (for the example)
load("@com_github_cloneable_rules_ent//:deps.bzl", "ent_go_dependencies")

ent_go_dependencies()
3 changes: 3 additions & 0 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/cloneable/rules_ent

go 1.19
23 changes: 23 additions & 0 deletions example/protos/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "user_settings_proto",
srcs = ["user_settings.proto"],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "user_settings_go_proto",
importpath = "github.com/cloneable/rules_ent/example/protos",
proto = ":user_settings_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "proto",
embed = [":user_settings_go_proto"],
importpath = "github.com/cloneable/rules_ent/example/protos",
visibility = ["//visibility:public"],
)
14 changes: 14 additions & 0 deletions example/protos/user_settings.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";

package user_settings;

message UserSettings {
bool color_blind = 1;
AppLanguage lang = 2;
}

enum AppLanguage {
ENGLISH = 0;
FRENCH = 1;
PORTUGUESE = 2;
}
27 changes: 27 additions & 0 deletions example/schema/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("//:defs.bzl", "go_ent_library")

go_library(
name = "schema",
srcs = ["user.go"],
importpath = "github.com/cloneable/rules_ent/example/schema",
visibility = ["//visibility:public"],
deps = [
"//example/protos:proto",
"@com_github_google_uuid//:uuid",
"@io_entgo_ent//:ent",
"@io_entgo_ent//schema/field",
"@io_entgo_ent//schema/mixin",
],
)

go_ent_library(
name = "db",
entities = [
"user",
],
gomod = "//:go_mod",
importpath = "github.com/cloneable/rules_ent/example/db",
schema = ":schema",
visibility = ["//:__subpackages__"],
)
31 changes: 31 additions & 0 deletions example/schema/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package schema

import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
"github.com/cloneable/rules_ent/example/protos"
"github.com/google/uuid"
)

type User struct {
ent.Schema
}

func (User) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Default(uuid.New),
field.String("email").Unique(),
field.Bytes("preferences").GoType(&protos.UserSettings{}),
}
}

func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}

func (User) Edges() []ent.Edge {
return []ent.Edge{}
}
77 changes: 77 additions & 0 deletions workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
""" Morf workspace dependencies """

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

def install_workspace_dependencies():
""" Defines repositories for core rules sets
"""

# Open source license validations
http_archive(
name = "rules_license",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.3/rules_license-0.0.3.tar.gz",
"https://github.com/bazelbuild/rules_license/releases/download/0.0.3/rules_license-0.0.3.tar.gz",
],
sha256 = "00ccc0df21312c127ac4b12880ab0f9a26c1cff99442dc6c5a331750360de3c3",
)

# Protobuf-related rules
http_archive(
name = "com_google_protobuf",
sha256 = "9c0fd39c7a08dff543c643f0f4baf081988129a411b977a07c46221793605638",
strip_prefix = "protobuf-3.20.3",
urls = [
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.20.3.tar.gz",
"https://github.com/protocolbuffers/protobuf/archive/v3.20.3.tar.gz",
],
)

http_archive(
name = "rules_proto",
sha256 = "e017528fd1c91c5a33f15493e3a398181a9e821a804eb7ff5acdd1d2d6c2b18d",
strip_prefix = "rules_proto-4.0.0-3.20.0",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0-3.20.0.tar.gz",
],
)

# go-related rules
http_archive(
name = "io_bazel_rules_go",
sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
],
)

http_archive(
name = "bazel_skylib",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
)

# gazelle
http_archive(
name = "bazel_gazelle",
sha256 = "ecba0f04f96b4960a5b250c8e8eeec42281035970aa8852dda73098274d14a1d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
],
)

# buildifier
http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
strip_prefix = "buildtools-4.2.2",
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz",
],
)