commit | 7106d86685e3395efc6df5d2ee5914fe622ed6b9 | [log] [tgz] |
---|---|---|
author | Philipp Schrader <philipp.schrader@gmail.com> | Wed Apr 17 22:06:06 2024 -0700 |
committer | GitHub <noreply@github.com> | Thu Apr 18 05:06:06 2024 +0000 |
tree | 97dd663545295565a2f2ba8146b25d3afcfb739f | |
parent | da6472013fde0992c4d70b5e289a440da3383350 [diff] |
Remove npm/rules_js dependency for C++ only use cases (#7990) When flatbuffers is being used from a project that has no use for JavaScript, users encounter an error similar to the following: ERROR: Skipping '@com_github_google_flatbuffers//:flatbuffers': error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined. WARNING: Target pattern parsing failed. ERROR: error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined. INFO: Elapsed time: 0.023s INFO: 0 processes. FAILED: Build did NOT complete successfully (0 packages loaded) currently loading: @com_github_google_flatbuffers// That's not ideal. Users that only care about C++ for example shouldn't be forced to deal with rules_js and friends. This patch attempts to fix that by moving the rules_js-specific things into the `ts` and `tests/ts` directories. This should allow non-JavaScript projects to ignore rules_js and friends completely. Here I basically followed the `rules_foo` example from rules_js: https://github.com/aspect-build/rules_js/tree/main/e2e/rules_foo The idea is that flatbuffers has its own npm dependencies regardless of what other projects may have. This means we should not force the user to import flatbuffers's npm dependencies. The new `ts/repositories.bzl` file is used by dependents to import flatbuffers's dependencies. They can still import their own dependencies. This cleanup allowed me to move all JavaScript-specific stuff from the top-level directory into subdirectories. There should be no changes in this patch in terms of functionality. It's just a refactor of the rules_js call sites. Users will have to add a call to the function in `ts/repositories.bzl` in their own `WORKSPACE` file. They can use `tests/ts/bazel_repository_test/WORKSPACE` as an example. Co-authored-by: Derek Bailey <derekbailey@google.com>
FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.
Build the compiler for flatbuffers (flatc
)
Use cmake
to create the build files for your platform and then perform the compliation (Linux example).
cmake -G "Unix Makefiles" make -j
Define your flatbuffer schema (.fbs
)
Write the schema to define the data you want to serialize. See monster.fbs for an example.
Generate code for your language(s)
Use the flatc
compiler to take your schema and generate language-specific code:
./flatc --cpp --rust monster.fbs
Which generates monster_generated.h
and monster_generated.rs
files.
Serialize data
Use the generated code, as well as the FlatBufferBuilder
to construct your serialized buffer. (C++
example)
Transmit/store/save Buffer
Use your serialized buffer however you want. Send it to someone, save it for later, etc...
Read the data
Use the generated accessors to read the data from the serialized buffer.
It doesn't need to be the same language/schema version, FlatBuffers ensures the data is readable across languages and schema versions. See the Rust
example reading the data written by C++
.
Go to our landing page to browse our documentation.
Code generation and runtime libraries for many popular languages.
FlatBuffers does not follow traditional SemVer versioning (see rationale) but rather uses a format of the date of the release.
flatbuffers
tag for any questions regarding FlatBuffers.To contribute to this project, see CONTRIBUTING.
Please see our Security Policy for reporting vulnerabilities.
Flatbuffers is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.