feat(rpc): port RPC repo to bazel monorepo

This commit is contained in:
41666 2020-10-11 05:53:35 -04:00
parent e33e6f8574
commit 2d919c6053
17 changed files with 111 additions and 82 deletions

1
.bazelrc Normal file
View file

@ -0,0 +1 @@
build --workspace_status_command=hack/workspace_status.sh

View file

@ -1,5 +1,6 @@
workspace(
name = "roleypoly",
managed_directories = {"@npm": ["node_modules"]},
)
### BAZEL
@ -39,18 +40,22 @@ git_repository(
http_archive(
name = "rules_proto",
sha256 = "4d421d51f9ecfe9bf96ab23b55c6f2b809cbaf0eea24952683e397decfbd0dd0",
strip_prefix = "rules_proto-f6b8d89b90a7956f6782a4a3609b2f0eee3ce965",
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/f6b8d89b90a7956f6782a4a3609b2f0eee3ce965.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
],
)
git_repository(
name = "rules_typescript_proto",
commit = "692cbfb909c8972250bc6b378a3c1f14f36b9c54",
remote = "https://github.com/Dig-Doug/rules_typescript_proto",
shallow_since = "1599865339 -0400",
### NODE
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
### PROTO
@ -60,18 +65,14 @@ rules_proto_dependencies()
rules_proto_toolchains()
### NODE
### ts proto
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
node_repositories(
package_json = ["//:package.json"],
)
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
git_repository(
name = "rules_typescript_proto",
# branch = "test/ts_library",
commit = "34f22e81a0b1dc66de18b729bcc77e1485ded337",
remote = "https://github.com/roleypoly/rules_typescript_proto.git",
shallow_since = "1602400942 -0400",
)
load("@rules_typescript_proto//:index.bzl", "rules_typescript_proto_dependencies")

36
hack/tsproto.bzl Normal file
View file

@ -0,0 +1,36 @@
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
def _generalize_pb_imports(name, srcs = [], grpc = False):
suffix_match = "pb"
if grpc:
suffix_match = ""
native.genrule(
name = name,
srcs = srcs,
outs = ["index.ts"],
cmd = """
echo $(SRCS) | tr ' ' '\n' | grep '""" + suffix_match + """\\.js$$' | xargs -l1 -I '{}' basename {} .js | xargs -l1 -I'{}' echo 'export * from "./{}"' > $(location index.ts)
""",
output_to_bindir = True,
)
def ts_proto(proto, name = "ts", grpc = False):
typescript_proto_library(
name = name + "_proto",
proto = proto,
visibility = ["//visibility:public"],
)
_generalize_pb_imports(
grpc = grpc,
name = name + "_proto_generalized",
srcs = [":" + name + "_proto"],
)
ts_library(
name = name,
srcs = [":" + name + "_proto_generalized"],
deps = [":" + name + "_proto"],
visibility = ["//visibility:public"],
)

View file

@ -33,8 +33,6 @@
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@bazel/karma": "^2.2.1",
"@bazel/labs": "^2.2.1",
"@bazel/typescript": "^2.2.1",
"@storybook/addon-actions": "^6.0.26",
"@storybook/addon-essentials": "^6.0.26",
@ -47,7 +45,9 @@
"@types/styled-components": "5.1.4",
"babel-loader": "^8.1.0",
"prettier": "^2.1.2",
"protoc-gen-ts": "^0.3.4",
"react-is": "^16.13.1",
"ts-protoc-gen": "^0.13.0",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"tslint": "6.1.3",
"tslint-config-prettier": "^1.18.0",
@ -55,4 +55,4 @@
"tslint-plugin-prettier": "^2.3.0",
"typescript": "^4.0.3"
}
}
}

View file

@ -1,7 +1,7 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
proto_library(
name = "auth_proto",
@ -23,7 +23,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":auth_proto",
)

View file

@ -1,7 +1,7 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
proto_library(
name = "backend_proto",
@ -32,7 +32,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":backend_proto",
)

View file

@ -1,7 +1,7 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
proto_library(
name = "client_proto",
@ -10,7 +10,6 @@ proto_library(
deps = [
"//src/rpc/auth:auth_proto",
"//src/rpc/shared:shared_proto",
"@com_google_protobuf//:empty_proto",
],
)
@ -33,7 +32,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":client_proto",
)

View file

@ -4,12 +4,12 @@ package roleypoly.auth.client;
option go_package = "github.com/roleypoly/roleypoly/src/auth/client";
import "src/rpc/shared/internal.proto";
import "google/protobuf/empty.proto";
import "src/rpc/shared/shared.proto";
import "src/rpc/auth/shared.proto";
service AuthClient {
rpc GetClientToken(google.protobuf.Empty) returns (roleypoly.auth.Token) {}
rpc GetUserSession(google.protobuf.Empty) returns (roleypoly.RoleypolySession) {}
rpc GetClientToken(roleypoly.Empty) returns (roleypoly.auth.Token) {}
rpc GetUserSession(roleypoly.Empty) returns (roleypoly.RoleypolySession) {}
rpc ResolveSessionKey(roleypoly.auth.Token) returns (roleypoly.auth.Token) {}
rpc AuthorizeChallenge(roleypoly.auth.AuthChallenge) returns (roleypoly.auth.Token) {}
}

View file

@ -1,13 +1,13 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
proto_library(
name = "ctf_proto",
srcs = ["ctf.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:empty_proto"],
deps = ["//src/rpc/shared:shared_proto"],
)
go_proto_library(
@ -16,6 +16,7 @@ go_proto_library(
importpath = "github.com/roleypoly/roleypoly/src/rpc/ctf",
proto = ":ctf_proto",
visibility = ["//visibility:public"],
deps = ["//src/rpc/shared"],
)
go_library(
@ -25,7 +26,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":ctf_proto",
)

View file

@ -3,13 +3,13 @@ syntax = "proto3";
package roleypoly.ctf;
option go_package = "github.com/roleypoly/roleypoly/src/rpc/ctf";
import "google/protobuf/empty.proto";
import "src/rpc/shared/shared.proto";
service CTF {
rpc GetRingFlags (Ring) returns (Flags) {}
rpc CreateFlag (Flag) returns (Flag) {}
rpc PromoteFlag (Flag) returns (Flag) {}
rpc RemoveFlag (Flag) returns (google.protobuf.Empty) {}
rpc RemoveFlag (Flag) returns (roleypoly.Empty) {}
}
message Flags {

View file

@ -1,16 +1,17 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
package(default_visibility = [
"//hack/fixtures:__subpackages__",
])
proto_library(
name = "discord_proto",
srcs = ["discord.proto"],
visibility = ["//visibility:public"],
deps = [
"//src/rpc/shared:shared_proto",
"@com_google_protobuf//:empty_proto",
],
deps = ["//src/rpc/shared:shared_proto"],
)
go_proto_library(
@ -29,7 +30,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":discord_proto",
)

View file

@ -3,11 +3,10 @@ syntax = "proto3";
package roleypoly.discord;
option go_package = "github.com/roleypoly/roleypoly/src/rpc/discord";
import "google/protobuf/empty.proto";
import "src/rpc/shared/shared.proto";
service Discord {
rpc ListGuilds(google.protobuf.Empty) returns (GuildList) {}
rpc ListGuilds(roleypoly.Empty) returns (GuildList) {}
rpc GetGuild(roleypoly.IDQuery) returns (Guild) {}
rpc GetGuildRoles(roleypoly.IDQuery) returns (GuildRoles) {}
rpc GetGuildsByMember(roleypoly.IDQuery) returns (GuildList) {}
@ -17,7 +16,7 @@ service Discord {
rpc UpdateMember(Member) returns (Member) {} // deprecated 4 MAR 2020
rpc UpdateMemberRoles(RoleTransaction) returns (RoleTransactionResult) {}
rpc OwnUser(google.protobuf.Empty) returns (roleypoly.DiscordUser) {}
rpc OwnUser(roleypoly.Empty) returns (roleypoly.DiscordUser) {}
}
message GuildMembers {

View file

@ -1,7 +1,7 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
proto_library(
name = "platform_proto",
@ -10,7 +10,6 @@ proto_library(
deps = [
"//src/rpc/discord:discord_proto",
"//src/rpc/shared:shared_proto",
"@com_google_protobuf//:empty_proto",
],
)
@ -33,7 +32,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":platform_proto",
)

View file

@ -5,15 +5,14 @@ option go_package = "github.com/roleypoly/roleypoly/src/rpc/platform";
import "src/rpc/shared/shared.proto";
import "src/rpc/discord/discord.proto";
import "google/protobuf/empty.proto";
service Platform {
rpc EnumerateMyGuilds(google.protobuf.Empty) returns (GuildEnumeration) {}
rpc EnumerateMyGuilds(roleypoly.Empty) returns (GuildEnumeration) {}
rpc GetGuildSlug(roleypoly.IDQuery) returns (roleypoly.Guild) {}
rpc GetGuild(roleypoly.IDQuery) returns (PresentableGuild) {}
rpc UpdateMyRoles(UpdateRoles) returns (google.protobuf.Empty) {}
rpc UpdateGuildData(GuildData) returns (google.protobuf.Empty) {}
rpc UpdateMyRoles(UpdateRoles) returns (roleypoly.Empty) {}
rpc UpdateGuildData(GuildData) returns (roleypoly.Empty) {}
}
message GuildEnumeration { repeated PresentableGuild guilds = 1; }

View file

@ -1,7 +1,12 @@
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")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")
load("//:hack/tsproto.bzl", "ts_proto")
package(default_visibility = [
"//hack/fixtures:__subpackages__",
"//src/design-system/atoms/role:__subpackages__",
])
proto_library(
name = "shared_proto",
@ -26,7 +31,6 @@ go_library(
visibility = ["//visibility:public"],
)
typescript_proto_library(
name = "ts",
ts_proto(
proto = ":shared_proto",
)

View file

@ -2,6 +2,8 @@ syntax = "proto3";
package roleypoly;
option go_package = "github.com/roleypoly/roleypoly/src/rpc/shared";
message Empty {}
message IDQuery {
string MemberID = 1;
string GuildID = 2;

View file

@ -1120,18 +1120,6 @@
resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.0.tgz#860ce718b0b73f4009e153541faff2cb6b85d047"
integrity sha512-4Th98KlMHr5+JkxfcoDT//6vY8vM+iSPrLNpHhRyLx2CFYi8e2RfqPLdpbnpo0Q5lQC5hNB79yes07zb02fvCw==
"@bazel/karma@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@bazel/karma/-/karma-2.2.1.tgz#f59bf39fe044940c87c5ab00cc0e0dcdfe522cd9"
integrity sha512-4rOeweI9IaQ60/T1igk6IcqmX6v+OyIQFLzieeYrb/EYs+iNirw8sZtsVjMKoZ59dA1zSjxDIVWH0yRJI/SAwQ==
dependencies:
tmp "0.1.0"
"@bazel/labs@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@bazel/labs/-/labs-2.2.1.tgz#0bae2b6a053e55884a98a44ca45eccc06aa149cd"
integrity sha512-0BveUK2MqFbYFkj7sfrwDQAA8OMa/YlNNO+PReOJ8VoQZIenWl8mQO3THTtsoRWbFN7zl8S3z0CLutrb35BPmA==
"@bazel/typescript@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-2.2.1.tgz#46d6dcedd91a7fd0421e9286790aff94ec45bece"
@ -5782,7 +5770,7 @@ good-listener@^1.2.2:
dependencies:
delegate "^3.1.2"
google-protobuf@3.13.0, google-protobuf@^3.13.0:
google-protobuf@3.13.0, google-protobuf@^3.13.0, google-protobuf@^3.6.1:
version "3.13.0"
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.13.0.tgz#909c5983d75dd6101ed57c79e0528d000cdc3251"
integrity sha512-ZIf3qfLFayVrPvAjeKKxO5FRF1/NwRxt6Dko+fWEMuHwHbZx8/fcaAao9b0wCM6kr8qeg2te8XTpyuvKuD9aKw==
@ -8352,6 +8340,11 @@ protobufjs@6.8.8:
"@types/node" "^10.1.0"
long "^4.0.0"
protoc-gen-ts@^0.3.4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/protoc-gen-ts/-/protoc-gen-ts-0.3.4.tgz#231de77a9ce1b748e666d5db85a1ca933d02ca71"
integrity sha512-j2oawQXhg+xAK/FbMVHYDyyvjCpX3VdgWXIDQm/3UzzNPXGzpwCMU9r4jexr0fWccuahFPnaqQGOhY0FuOwV2g==
proxy-addr@~2.0.5:
version "2.0.6"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf"
@ -9940,13 +9933,6 @@ tinycolor2@^1.4.1:
resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.2.tgz#3f6a4d1071ad07676d7fa472e1fac40a719d8803"
integrity sha512-vJhccZPs965sV/L2sU4oRQVAos0pQXwsvTLkWYdqJ+a8Q5kPFzJTuOFwy7UniPli44NKQGAglksjvOcpo95aZA==
tmp@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.1.0.tgz#ee434a4e22543082e294ba6201dcc6eafefa2877"
integrity sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==
dependencies:
rimraf "^2.6.3"
tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
@ -10053,6 +10039,13 @@ ts-pnp@^1.1.6:
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
ts-protoc-gen@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/ts-protoc-gen/-/ts-protoc-gen-0.13.0.tgz#2763ae4e4a1a7d7001d53d2f3043357c691701ea"
integrity sha512-j18X4rkDBbG/ZHUJy88WFeZP6mStGow5uREaohowlHXTu3/N7WcpyPhb7Vh6wN38ERmc/AkT9gqT98+vtlRhJA==
dependencies:
google-protobuf "^3.6.1"
tsconfig-paths-webpack-plugin@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-3.3.0.tgz#a7461723c20623ca9148621a5ce36532682ad2ff"