Skip to content
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
1 change: 1 addition & 0 deletions bazel/envoy_mobile_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def kotlin_dependencies():
maven_install(
artifacts = [
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.flatbuffers:flatbuffers-java:2.0.3",
# Kotlin
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11",
"androidx.recyclerview:recyclerview:1.1.0",
Expand Down
8 changes: 8 additions & 0 deletions bazel/envoy_mobile_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ def envoy_mobile_repositories():
urls = ["https://github.com/google/bazel-common/archive/413b433b91f26dbe39cdbc20f742ad6555dd1e27.zip"],
)

http_archive(
name = "swift_flatbuffers",
sha256 = "ffd68aebdfb300c9e82582ea38bf4aa9ce65c77344c94d5047f3be754cc756ea",
build_file = "@envoy_mobile//bazel:flatbuffers.BUILD",
strip_prefix = "flatbuffers-2.0.0",
urls = ["https://github.com/google/flatbuffers/archive/refs/tags/v2.0.0.zip"],
)

upstream_envoy_overrides()
swift_repos()
kotlin_repos()
Expand Down
13 changes: 13 additions & 0 deletions bazel/flatbuffers.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")

licenses(["notice"]) # Apache 2

package(
default_visibility = ["//visibility:public"],
)

swift_library(
name = "FlatBuffers",
srcs = glob(["swift/Sources/FlatBuffers/*.swift"]),
module_name = "FlatBuffers",
)
32 changes: 32 additions & 0 deletions bazel/flatbuffers.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_library_public")
load("@envoy_mobile//bazel:kotlin_lib.bzl", "envoy_mobile_kt_library")

def envoy_mobile_flatbuffers_library(name, srcs, namespace, types):
flatbuffer_cc_library(
name = "{}_fb_cc_lib".format(name),
srcs = srcs,
)

directory_path = namespace.replace(".", "/")
kotlin_files = [directory_path + "/" + t + ".kt" for t in types]
flatbuffer_library_public(
name = "{}_fb_kt_srcs".format(name),
srcs = srcs,
# TODO(snowp): For some reason I can't get this to work with just one output file for java. For now we can avoid dealing with this since basically all use cases of this would result in multiple files for Java.
outs = kotlin_files,
language_flag = "--kotlin",
)

envoy_mobile_kt_library(
name = "{}_fb_kt_lib".format(name),
srcs = [":{}_fb_kt_srcs".format(name)],
deps = ["@maven//:com_google_flatbuffers_flatbuffers_java"],
)

swift_outputs = ["{}_generated.swift".format(f.replace(".fbs", "")) for f in srcs]
flatbuffer_library_public(
name = "{}_fb_swift_srcs".format(name),
srcs = srcs,
outs = swift_outputs,
language_flag = "--swift",
)
1 change: 1 addition & 0 deletions library/swift/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ swift_library(
module_name = "Envoy",
private_deps = [
"//library/objective-c:envoy_engine_objc_lib",
"@swift_flatbuffers//:FlatBuffers",
"@envoy_mobile_extra_swift_sources//:extra_private_dep",
],
visibility = ["//visibility:public"],
Expand Down
16 changes: 16 additions & 0 deletions test/fbs/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
load("//bazel:flatbuffers.bzl", "envoy_mobile_flatbuffers_library")

licenses(["notice"]) # Apache 2

envoy_package()

envoy_mobile_flatbuffers_library(
name = "test",
srcs = ["test.fbs"],
namespace = "Test.Nested",
types = [
"SomeType",
"SomeOtherType",
],
)
10 changes: 10 additions & 0 deletions test/fbs/test.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Test.Nested;

table SomeType {
}

table SomeOtherType {

}

root_type SomeType;
10 changes: 10 additions & 0 deletions test/kotlin/io/envoyproxy/envoymobile/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ envoy_mobile_kt_test(
],
)

envoy_mobile_kt_test(
name = "flatbuffers_test",
srcs = [
"FlatBuffersTest.kt",
],
deps = [
"//test/fbs:test_fb_kt_lib",
],
)

envoy_mobile_kt_test(
name = "grpc_request_headers_builder_test",
srcs = [
Expand Down
16 changes: 16 additions & 0 deletions test/kotlin/io/envoyproxy/envoymobile/FlatBuffersTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.envoyproxy.envoymobile

import Test.Nested.SomeType
import com.google.flatbuffers.FlatBufferBuilder
import org.junit.Test

class FlatBuffersTest {

@Test
fun `flatbuffers construction`() {
// This test doesn't really test any functionality, just demonstrates that we are able to utilize flatbuffers pending
// real usage within the code base.
val s = SomeType()
val f = FlatBufferBuilder()
}
}
12 changes: 12 additions & 0 deletions test/swift/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ envoy_mobile_swift_test(
],
)

envoy_mobile_swift_test(
name = "flatbuffer_test",
srcs = [
"FlatBufferTest.swift",
] + [
"//test/fbs:test_fb_swift_srcs",
],
deps = [
"@swift_flatbuffers//:FlatBuffers",
],
)

envoy_cc_library(
name = "test_extensions_cc",
srcs = [
Expand Down
12 changes: 12 additions & 0 deletions test/swift/integration/FlatBufferTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Envoy
import FlatBuffers
import XCTest

final class FlatBufferTest: XCTestCase {
func testCreateFlatBuffer() {
// This test simply verifies that we can import both the generated types as
// well as upstream FlatBuffers.
_ = Test_Nested_SomeTypeT()
_ = FlatBufferBuilder()
}
}