diff --git a/BUILD b/BUILD index 3d57e96bf..a68160e81 100644 --- a/BUILD +++ b/BUILD @@ -15,7 +15,7 @@ swift_library( srcs = ["//src:DflatFiles"], module_name = "Dflat", deps = [ - "@flatbuffers//:FlatBuffers", + "@flatbuffers//swift", "@swift-atomics//:SwiftAtomics", ], ) diff --git a/Package.swift b/Package.swift index 4336b0a72..f81e0a7af 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ import PackageDescription var dependencies: [Package.Dependency] = [ .package( name: "FlatBuffers", url: "https://github.com/mustiikhalil/flatbuffers.git", - .revision("7d043834fd9e1dc0dcc2a5bea2852210433b597a")), + .revision("b52c73460318ab1fef4a68913c9870eb2c2dd5a7")), .package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.1"), .package( name: "SQLite3", url: "https://github.com/liuliu/swift-sqlite3-support.git", from: "3.38.5"), @@ -17,7 +17,7 @@ import PackageDescription var dependencies: [Package.Dependency] = [ .package( name: "FlatBuffers", url: "https://github.com/mustiikhalil/flatbuffers.git", - .revision("7d043834fd9e1dc0dcc2a5bea2852210433b597a")), + .revision("b52c73460318ab1fef4a68913c9870eb2c2dd5a7")), .package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.1"), ] let sqliteDflatDependencies: [Target.Dependency] = ["Dflat", "_SQLiteDflatOSShim"] diff --git a/WORKSPACE b/WORKSPACE index 14fdd73ff..71c3bdcee 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,9 +20,9 @@ git_repository( new_git_repository( name = "flatbuffers", build_file = "flatbuffers.BUILD", - commit = "354d97f6da18cbbdeddfcdd2d5aebf1bcc57a092", + commit = "11a19887053534c43f73e74786b46a615ecbf28e", remote = "https://github.com/google/flatbuffers.git", - shallow_since = "1632261689 -0700", + shallow_since = "1654463045 +0200", ) new_git_repository( diff --git a/external/flatbuffers.BUILD b/external/flatbuffers.BUILD index 69bcf310c..7ba56412c 100644 --- a/external/flatbuffers.BUILD +++ b/external/flatbuffers.BUILD @@ -1,7 +1,6 @@ -licenses(["notice"]) - load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") + +licenses(["notice"]) package( default_visibility = ["//visibility:public"], @@ -9,8 +8,23 @@ package( exports_files([ "LICENSE", + "tsconfig.json", ]) +config_setting( + name = "platform_freebsd", + constraint_values = [ + "@platforms//os:freebsd", + ], +) + +config_setting( + name = "platform_openbsd", + constraint_values = [ + "@platforms//os:openbsd", + ], +) + # Public flatc library to compile flatbuffer files at runtime. cc_library( name = "flatbuffers", @@ -24,10 +38,20 @@ cc_library( filegroup( name = "public_headers", srcs = [ + "include/flatbuffers/allocator.h", + "include/flatbuffers/array.h", "include/flatbuffers/base.h", + "include/flatbuffers/bfbs_generator.h", + "include/flatbuffers/buffer.h", + "include/flatbuffers/buffer_ref.h", "include/flatbuffers/code_generators.h", + "include/flatbuffers/default_allocator.h", + "include/flatbuffers/detached_buffer.h", + "include/flatbuffers/flatbuffer_builder.h", "include/flatbuffers/flatbuffers.h", + "include/flatbuffers/flex_flat_util.h", "include/flatbuffers/flexbuffers.h", + "include/flatbuffers/grpc.h", "include/flatbuffers/hash.h", "include/flatbuffers/idl.h", "include/flatbuffers/minireflect.h", @@ -35,7 +59,13 @@ filegroup( "include/flatbuffers/reflection_generated.h", "include/flatbuffers/registry.h", "include/flatbuffers/stl_emulation.h", + "include/flatbuffers/string.h", + "include/flatbuffers/struct.h", + "include/flatbuffers/table.h", "include/flatbuffers/util.h", + "include/flatbuffers/vector.h", + "include/flatbuffers/vector_downward.h", + "include/flatbuffers/verifier.h", ], ) @@ -51,7 +81,6 @@ cc_library( # Public flatc compiler. cc_library( name = "flatc", - linkopts = ["-lm"], deps = [ "//src:flatc", ], @@ -74,13 +103,9 @@ cc_library( "include/flatbuffers/flexbuffers.h", "include/flatbuffers/stl_emulation.h", "include/flatbuffers/util.h", + "include/flatbuffers/vector.h", + "include/flatbuffers/verifier.h", ], linkstatic = 1, strip_include_prefix = "/include", ) - -swift_library( - name = "FlatBuffers", - srcs = glob(["swift/Sources/FlatBuffers/*.swift"]), - module_name = "FlatBuffers", -) diff --git a/src/parser/BUILD b/src/parser/BUILD index 0630e52d6..9b7317ec5 100644 --- a/src/parser/BUILD +++ b/src/parser/BUILD @@ -7,7 +7,10 @@ package( cc_binary( name = "dflats", srcs = ["dflats.cpp"], - deps = ["@flatbuffers//:flatc"], + deps = [ + "@flatbuffers", + "@flatbuffers//:flatc", + ], ) swift_binary( diff --git a/src/parser/dflats.cpp b/src/parser/dflats.cpp index ca4af2d07..476bff6c4 100644 --- a/src/parser/dflats.cpp +++ b/src/parser/dflats.cpp @@ -52,16 +52,16 @@ static const char *idl_types[] = { const std::string GenJSONType(const flatbuffers::Type &type) { if (type.base_type == flatbuffers::BASE_TYPE_STRUCT) { - return std::string("{\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.struct_def->name, false)) + "\"}"; + return std::string("{\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.struct_def->name, flatbuffers::Case::kLowerCamel)) + "\"}"; } else if (flatbuffers::IsSeries(type)) { if (type.element == flatbuffers::BASE_TYPE_STRUCT) { - return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.struct_def->name, false)) + "\"}}"; + return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.struct_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}"; } else if (type.element == flatbuffers::BASE_TYPE_UNION) { - return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}}"; + return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}"; } else if (type.element == flatbuffers::BASE_TYPE_UTYPE) { - return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}}"; + return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}"; } else if (type.enum_def) { - return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}}"; + return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}"; } else if (type.element == flatbuffers::BASE_TYPE_VECTOR || type.element == flatbuffers::BASE_TYPE_ARRAY) { exit(-1); } else { @@ -69,14 +69,14 @@ const std::string GenJSONType(const flatbuffers::Type &type) { } } else if (flatbuffers::IsUnion(type)) { if (type.base_type == flatbuffers::BASE_TYPE_UTYPE) { - return std::string("{\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}"; + return std::string("{\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}"; } else if (type.base_type == flatbuffers::BASE_TYPE_UNION) { - return std::string("{\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}"; + return std::string("{\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}"; } else { exit(-1); } } else if (flatbuffers::IsEnum(type)) { - return std::string("{\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}"; + return std::string("{\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}"; } else { return std::string("{\"type\": \"") + idl_types[type.base_type] + "\"}"; } @@ -111,7 +111,7 @@ const std::string GenAttributes(const flatbuffers::SymbolTabledefined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(enum_val.union_type.struct_def->name, false)) + "\", \"value\": " + enum_def.ToString(enum_val) + "}, "; + json += "{\"name\": \"" + flatbuffers::ConvertCase(enum_val.name, flatbuffers::Case::kLowerCamel) + "\", \"type\": \"struct\", \"struct\": \"" + enum_val.union_type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(enum_val.union_type.struct_def->name, flatbuffers::Case::kLowerCamel)) + "\", \"value\": " + enum_def.ToString(enum_val) + "}, "; } else { - json += "{\"name\": \"" + flatbuffers::MakeCamel(enum_val.name, false) + "\", \"type\": \"\", \"value\": " + enum_def.ToString(enum_val) + "}, "; + json += "{\"name\": \"" + flatbuffers::ConvertCase(enum_val.name, flatbuffers::Case::kLowerCamel) + "\", \"type\": \"\", \"value\": " + enum_def.ToString(enum_val) + "}, "; } } if (vals.size() > 0) { @@ -138,7 +138,7 @@ const std::string GenUnion(const flatbuffers::EnumDef &enum_def) { const std::string GenStruct(const flatbuffers::StructDef &struct_def) { std::string json = std::string("{\"fixed\": ") + (struct_def.fixed ? "true" : "false") + ", "; - json += "\"name\": \"" + flatbuffers::MakeCamel(struct_def.name, false) + "\", "; + json += "\"name\": \"" + flatbuffers::ConvertCase(struct_def.name, flatbuffers::Case::kLowerCamel) + "\", "; json += "\"generated\": "; json += (struct_def.generated ? "true, " : "false, "); json += "\"namespace\": [" + GenNamespace(*struct_def.defined_namespace) + "], "; @@ -147,9 +147,9 @@ const std::string GenStruct(const flatbuffers::StructDef &struct_def) { for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { const auto &field_def = **it; if (field_def.value.constant != "0") { - json += "{\"name\": \"" + flatbuffers::MakeCamel(field_def.name, false) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", \"default\": \"" + field_def.value.constant + "\", " + GenAttributes(field_def.attributes) + "}, "; + json += "{\"name\": \"" + flatbuffers::ConvertCase(field_def.name, flatbuffers::Case::kLowerCamel) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", \"default\": \"" + field_def.value.constant + "\", " + GenAttributes(field_def.attributes) + "}, "; } else { - json += "{\"name\": \"" + flatbuffers::MakeCamel(field_def.name, false) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", " + GenAttributes(field_def.attributes) + "}, "; + json += "{\"name\": \"" + flatbuffers::ConvertCase(field_def.name, flatbuffers::Case::kLowerCamel) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", " + GenAttributes(field_def.attributes) + "}, "; } } if (struct_def.fields.vec.size() > 0) { @@ -185,9 +185,9 @@ static void GenerateJSONAdapter(const flatbuffers::Parser &parser, const std::st } if (parser.root_struct_def_) { if (parser.structs_.vec.size() > 0) { - json = json.substr(0, json.size() - 2) + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::MakeCamel(parser.root_struct_def_->name, false) + "\"}}"; + json = json.substr(0, json.size() - 2) + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::ConvertCase(parser.root_struct_def_->name, flatbuffers::Case::kLowerCamel) + "\"}}"; } else { - json = json + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::MakeCamel(parser.root_struct_def_->name, false) + "\"}}"; + json = json + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::ConvertCase(parser.root_struct_def_->name, flatbuffers::Case::kLowerCamel) + "\"}}"; } } else { json = json + "]}";