Skip to content

Commit

Permalink
Updated some docs and removed/rearranged some obsolete stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed Aug 11, 2021
1 parent c5d6ec7 commit 1735541
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 3,719 deletions.
8 changes: 0 additions & 8 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,12 @@ cc_library(

# copybara:strip_for_google3_begin

py_binary(
name = "amalgamate",
srcs = ["tools/amalgamate.py"],
)

upb_amalgamation(
name = "gen_amalgamation",
outs = [
"upb.c",
"upb.h",
],
amalgamator = ":amalgamate",
libs = [
":upb",
":fastdecode",
Expand All @@ -267,7 +261,6 @@ upb_amalgamation(
"php-upb.c",
"php-upb.h",
],
amalgamator = ":amalgamate",
libs = [
":upb",
":fastdecode",
Expand All @@ -293,7 +286,6 @@ upb_amalgamation(
"ruby-upb.c",
"ruby-upb.h",
],
amalgamator = ":amalgamate",
libs = [
":upb",
":fastdecode",
Expand Down
42 changes: 36 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
## <a name="cla"></a> Signing the CLA

Please sign the [Google Contributor License Agreement
(CLA)](https://cla.developers.google.com/)
before sending pull requests. For any code changes to be
accepted, the CLA must be signed. It's a quick process, I
promise!
# How to Contribute

We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.

## Get in touch

If your idea will take you more than, say, 30 minutes to
implement, please get in touch first via the issue tracker
to touch base about your plan. That will give an
opportunity for early feedback and help avoid wasting your
time.

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Agreement. You (or your employer) retain the copyright to your contribution;
this simply gives us permission to use and redistribute your contributions as
part of the project. Head over to <https://cla.developers.google.com/> to see
your current agreements on file or to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Code Reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Community Guidelines

This project follows [Google's Open Source Community
Guidelines](https://opensource.google/conduct/).
72 changes: 0 additions & 72 deletions DESIGN.md

This file was deleted.

150 changes: 44 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,62 @@

# μpb - a small protobuf implementation in C

|Platform|Build Status|
|--------|------------|
|macOS|[![Build Status](https://storage.googleapis.com/upb-kokoro-results/status-badge/macos.png)](https://fusion.corp.google.com/projectanalysis/summary/KOKORO/prod%3Aupb%2Fmacos%2Fcontinuous)|
|ubuntu|[![Build Status](https://storage.googleapis.com/upb-kokoro-results/status-badge/ubuntu.png)](https://fusion.corp.google.com/projectanalysis/summary/KOKORO/prod%3Aupb%2Fubuntu%2Fcontinuous)|

μpb (often written 'upb') is a small protobuf implementation written in C.

upb generates a C API for creating, parsing, and serializing messages
as declared in `.proto` files. upb is heavily arena-based: all
messages always live in an arena (note: the arena can live in stack or
static memory if desired). Here is a simple example:

```c
#include "conformance/conformance.upb.h"

void foo(const char* data, size_t size) {
upb_arena *arena;

/* Generated message type. */
conformance_ConformanceRequest *request;
conformance_ConformanceResponse *response;

arena = upb_arena_new();
request = conformance_ConformanceRequest_parse(data, size, arena);
response = conformance_ConformanceResponse_new(arena);

switch (conformance_ConformanceRequest_payload_case(request)) {
case conformance_ConformanceRequest_payload_protobuf_payload: {
upb_strview payload = conformance_ConformanceRequest_protobuf_payload(request);
// ...
break;
}

case conformance_ConformanceRequest_payload_NOT_SET:
fprintf(stderr, "conformance_upb: Request didn't have payload.\n");
break;

default: {
static const char msg[] = "Unsupported input format.";
conformance_ConformanceResponse_set_skipped(
response, upb_strview_make(msg, sizeof(msg)));
break;
}
}

/* Frees all messages on the arena. */
upb_arena_free(arena);
}
```
# μpb: small, fast C protos

API and ABI are both subject to change! Please do not distribute
as a shared library for this reason (for now at least).
μpb (often written 'upb') is a small
[protobuf](https://github.com/protocolbuffers/protobuf) implementation written
in C.

## Using upb in your project
upb is the core runtime for protobuf languages extensions in
[Ruby](https://github.com/protocolbuffers/protobuf/tree/master/ruby),
[PHP](https://github.com/protocolbuffers/protobuf/tree/master/php), and (soon)
Python.

Currently only Bazel is supported (CMake support is partial and incomplete
but full CMake support is an eventual goal).
While upb offers a C API, the C API & ABI **are not stable**. For this reason,
upb is not generally offered as a C library for direct consumption, and there
are no releases.

To use upb in your Bazel project, first add upb to your `WORKSPACE` file,
either as a `git_repository()` or as a `new_local_repository()` with a
Git Submodule. (For an example, see `examples/bazel/ in this repo).
## Features

```python
# Add this to your WORKSPACE file.
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
upb has comparable speed to protobuf C++, but is an order of magnitude smaller
in code size.

git_repository(
name = "upb",
remote = "https://github.com/protocolbuffers/upb.git",
commit = "d16bf99ac4658793748cda3251226059892b3b7b",
)
Like the main protobuf implementation in C++, it supports:

load("@upb//bazel:workspace_deps.bzl", "upb_deps")
- a generated API (in C)
- reflection
- binary & JSON wire formats
- text format serialization
- all standard features of protobufs (oneofs, maps, unknown fields, etc.)
- full conformance with the protobuf conformance tests

upb_deps()
```
upb also supports some features that C++ does not:

Then in your BUILD file you can add `upb_proto_library()` rules that
generate code for a corresponding `proto_library()` rule. For
example:

```python
# Add this to your BUILD file.
load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library")

proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
)

upb_proto_library(
name = "foo_upbproto",
deps = [":foo_proto"],
)

cc_binary(
name = "test_binary",
srcs = ["test_binary.c"],
deps = [":foo_upbproto"],
)
```
- **optional reflection:** generated messages are agnostic to whether
reflection will be linked in or not.
- **no global state:** no pre-main registration or other global state.
- **fast reflection-based parsing:** messages loaded at runtime parse
just as fast as compiled-in messages.

However there are some features it does not support:

Then in your `.c` file you can #include the generated header:
- proto2 extensions (coming soon!)
- text format parsing
- deep descriptor verification: upb's descriptor validation is not is exhaustive
as `protoc`.

```c
#include "foo.upb.h"
## Install

/* Insert code that uses generated types. */
For Ruby, use [RubyGems](https://rubygems.org/gems/google-protobuf):

```
$ gem install google-protobuf
```

## Lua bindings
For PHP, use [PECL](https://pecl.php.net/package/protobuf):

This repo has some Lua bindings for the core library. These are
experimental and very incomplete. These are currently included in
order to validate that the C API is suitable for wrapping. As the
project matures these Lua bindings may become publicly available.
```
$ sudo pecl install protobuf
```

## Contact
## Contributing

Author: Josh Haberman ([[email protected]](mailto:[email protected]),
[[email protected]](mailto:[email protected]))
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
6 changes: 6 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

py_binary(
name = "amalgamate",
srcs = ["amalgamate.py"],
visibility = ["//:__pkg__"],
)
File renamed without changes.
5 changes: 3 additions & 2 deletions bazel/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ def _upb_amalgamation(ctx):
outputs = ctx.outputs.outs,
arguments = [ctx.bin_dir.path + "/", ctx.attr.prefix] + [f.path for f in srcs] + ["-I" + root for root in _get_real_roots(inputs)],
progress_message = "Making amalgamation",
executable = ctx.executable.amalgamator,
executable = ctx.executable._amalgamator,
)
return []

upb_amalgamation = rule(
attrs = {
"amalgamator": attr.label(
"_amalgamator": attr.label(
executable = True,
cfg = "host",
default = "//bazel:amalgamate",
),
"prefix": attr.string(
default = "",
Expand Down
Loading

0 comments on commit 1735541

Please sign in to comment.