Skip to content

Commit a9508d4

Browse files
authored
Merge pull request #42 from YuhanLiin/editions
Add Editions support
2 parents 535ec8b + 92e1f9b commit a9508d4

21 files changed

Lines changed: 1091 additions & 179 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- uses: arduino/setup-protoc@v3
2020
with:
2121
repo-token: ${{ secrets.GITHUB_TOKEN }}
22+
version: '27.x'
2223
- run: cargo clippy --workspace --tests --no-default-features --exclude arm-app -- -Dwarnings
2324
- run: cargo clippy --workspace --tests --all-features --exclude arm-app -- -Dwarnings
2425
- run: cargo test --workspace --exclude arm-app
@@ -39,6 +40,7 @@ jobs:
3940
- uses: arduino/setup-protoc@v3
4041
with:
4142
repo-token: ${{ secrets.GITHUB_TOKEN }}
43+
version: '27.x'
4244
- run: cargo build --workspace --exclude no-panicking --exclude arm-app
4345
- run: cargo build -p no-panicking --profile release-lto
4446
# Check if descriptor.rs has been bootstrapped properly
@@ -61,6 +63,7 @@ jobs:
6163
- uses: arduino/setup-protoc@v3
6264
with:
6365
repo-token: ${{ secrets.GITHUB_TOKEN }}
66+
version: '27.x'
6467
- run: cd examples/arm-app && cargo build --profile release-lto --target thumbv7em-none-eabihf
6568

6669
miri:
@@ -74,6 +77,7 @@ jobs:
7477
- uses: arduino/setup-protoc@v3
7578
with:
7679
repo-token: ${{ secrets.GITHUB_TOKEN }}
80+
version: '27.x'
7781
- run: MIRIFLAGS=-"Zmiri-tree-borrows" cargo +nightly miri test -p micropb -p basic-proto
7882

7983
documentation:

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Added
6+
7+
- Protobuf Editions support
8+
9+
### Changed
10+
11+
- Enums now have `Debug` explicit manual impls that print the enum variant name, rather than the old derived impl that prints the variant number
12+
313
## 0.6.0
414

515
### Added

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
"examples/basic",
1515
"tests/proptest-proto",
1616
"tests/doc-proto",
17+
"tests/editions",
1718
]
1819

1920
# For the no-panicking example

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@ Unlike other Rust Protobuf libraries, `micropb` is aimed for constrained environ
1313
- Reduced memory usage for generated code, especially for optional fields.
1414
- Allows both statically-allocated containers ([`heapless`](https://docs.rs/heapless/latest/heapless), [`arrayvec`](https://docs.rs/arrayvec/latest/arrayvec)) or dynamically-allocated containers from [`alloc`](https://doc.rust-lang.org/alloc).
1515
- Code generator is highly configurable.
16+
- Type-safe open enums, rather than `i32`.
1617
- Fields can have custom handlers with user-defined encoding and decoding behaviour.
1718
- Supports different data sources for encoding and decoding, abstracted behind the `PbRead` and `PbWrite` traits.
1819
- Supports caching of message field lengths during encoding, improving performance on deeply nested message structures.
1920

2021
#### Limitations
21-
- Does not support Protobuf Editions, RPC, or extensions.
22+
- Does not support RPC or extensions.
23+
- Does not support closed enums.
2224
- No reflection capabilities.
2325
- `string`, `bytes`, repeated, and `map` fields require some basic user configuration to get working.
2426

27+
### Editions Support
28+
29+
`micropb` supports the `field_presence` and `repeated_field_encoding` features of Protobuf Editions. The `enum_type`, `message_encoding`, and `utf8_validation` features are ignored, because `micropb` does not support customizing those features. The other standard Editions features are not relevant to code generation.
30+
2531
## Overview
2632

2733
The `micropb` project consists of two crates:

examples/file-descriptor-set/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ fn main() {
2121
".google.protobuf.OneofDescriptorProto",
2222
".google.protobuf.MessageOptions",
2323
".google.protobuf.EnumValueDescriptorProto",
24+
".google.protobuf.FeatureSet",
2425
],
2526
Config::new().no_accessors(false),
27+
)
28+
// Need to be able to clone FeatureSet for Editions support
29+
.configure(
30+
".google.protobuf.FeatureSet",
31+
Config::new().no_clone_impl(false),
2632
);
2733
gen.compile_protos(&["google/protobuf/descriptor.proto"], "descriptor.rs")
2834
.unwrap();

micropb-gen/src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,11 @@ fn substitute_param<'a>(
638638
t: Option<impl ToString>,
639639
) -> Cow<'a, str> {
640640
if let Some(t) = t
641-
&& typestr.find(pat).is_some() {
642-
let t = t.to_string();
643-
return typestr.replace(pat, &t).into();
644-
}
641+
&& typestr.find(pat).is_some()
642+
{
643+
let t = t.to_string();
644+
return typestr.replace(pat, &t).into();
645+
}
645646
typestr
646647
}
647648

0 commit comments

Comments
 (0)