Skip to content

Commit 4531d06

Browse files
committed
bump
1 parent 4f5815a commit 4531d06

16 files changed

+85
-49
lines changed

go/protopace/Makefile

+20-6
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,25 @@ run/live:
8282
# OPERATIONS
8383
# ==================================================================================== #
8484

85-
## releast: cross-compile to karapace build dir
85+
## release: cross-compile to build dir on mac
8686
.PHONY: release
8787
release:
88-
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags='-s' -o=${BUILD_DIR}/${BINARY_NAME}-darwin-amd64.so -buildmode=c-shared ${MAIN_PACKAGE_PATH}
89-
#upx -5 ${BUILD_DIR}/${BINARY_NAME}-darwin-amd64.so
90-
91-
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -ldflags='-s' -o=${BUILD_DIR}/${BINARY_NAME}-darwin-arm64.so -buildmode=c-shared ${MAIN_PACKAGE_PATH}
92-
#upx -5 ${BUILD_DIR}/${BINARY_NAME}-darwin-arm64.so
88+
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags='-s -w' -o=${BUILD_DIR}/${BINARY_NAME}-darwin-amd64.so -buildmode=c-shared ${MAIN_PACKAGE_PATH}
89+
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -ldflags='-s -w' -o=${BUILD_DIR}/${BINARY_NAME}-darwin-arm64.so -buildmode=c-shared ${MAIN_PACKAGE_PATH}
90+
91+
docker run --rm -v "${PWD}":/usr/src/myapp -w /usr/src/myapp --platform=linux/amd64 golang:1.22 env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags='-s -w' -buildmode=c-shared -o ${BINARY_NAME}-linux-amd64.so
92+
cp ${BINARY_NAME}-linux-amd64.so ${BUILD_DIR}/${BINARY_NAME}-linux-amd64.so
93+
cp ${BINARY_NAME}-linux-amd64.h ${BUILD_DIR}/${BINARY_NAME}-linux-amd64.h
94+
rm ${BINARY_NAME}-linux-amd64.so
95+
rm ${BINARY_NAME}-linux-amd64.h
96+
97+
docker run --rm -v "${PWD}":/usr/src/myapp -w /usr/src/myapp --platform=linux/arm64 golang:1.22 env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -ldflags='-s -w' -buildmode=c-shared -o ${BINARY_NAME}-linux-arm64.so
98+
cp ${BINARY_NAME}-linux-arm64.so ${BUILD_DIR}/${BINARY_NAME}-linux-arm64.so
99+
cp ${BINARY_NAME}-linux-arm64.h ${BUILD_DIR}/${BINARY_NAME}-linux-arm64.h
100+
rm ${BINARY_NAME}-linux-arm64.so
101+
rm ${BINARY_NAME}-linux-arm64.h
102+
103+
.PHONY: foo
104+
foo:
105+
dir=$(realpath ${BUILD_DIR}/${BINARY_NAME}-darwin-amd64.so)
106+
echo ${dir}

go/protopace/compatibility.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func Check(schema schema.Schema, previousSchema schema.Schema) error {
3030
"FILE_SAME_PACKAGE",
3131
"FIELD_SAME_NAME",
3232
"FIELD_SAME_JSON_NAME",
33+
"FILE_NO_DELETE",
3334
},
3435
nil,
3536
nil,

go/protopace/compatibility_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ func TestCompatibility(t *testing.T) {
3030
assert.NoError(err)
3131

3232
err = Check(*testSchema, *previousSchema)
33-
assert.ErrorContains(err, "Previously present field \"5\" with name \"local_nested_value\" on message \"EventValue\" was deleted.")
33+
assert.ErrorContains(err, "Field \"5\" with name \"foo\" on message \"EventValue\" changed type from \"string\" to \"int32\".")
3434
}

go/protopace/fixtures/test.proto

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ message EventValue {
2626
google.protobuf.Timestamp created_at = 2;
2727
Status status = 3;
2828
Local.NestedValue local_nested_value = 4;
29+
int32 foo = 5;
2930
}

go/protopace/fixtures/test_previous.proto

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ message EventValue {
2525
NestedValue nested_value = 1;
2626
google.protobuf.Timestamp created_at = 2;
2727
Status status = 3;
28-
Local.NestedValue local_nested_value = 5;
28+
Local.NestedValue local_nested_value = 4;
29+
string foo = 5;
2930
}

go/protopace/formatter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import (
1919
)
2020

2121
func Format(schema s.Schema) (s.Schema, error) {
22-
res, err := schema.Compile()
22+
all, err := schema.Compile()
2323
if err != nil {
2424
return schema, err
2525
}
26+
res := all[0]
2627

2728
astNodeMapping := map[ast.Node]protoreflect.FullName{}
2829

go/protopace/schema/schema.go

+28-16
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@ func FromString(name string, proto string, dependencies []Schema) (*Schema, erro
3434
return &Schema{Schema: proto, Name: name, ParserResult: result, Dependencies: dependencies}, nil
3535
}
3636

37-
func (s Schema) Compile() (linker.Result, error) {
37+
func (s Schema) Compile() ([]linker.Result, error) {
3838
resolver := NewSchemaResolver(append(s.Dependencies, s))
3939
compiler := NewCompiler(resolver)
4040
ctx := context.Background()
41-
files, err := compiler.Compile(ctx, s.Name)
41+
schemas := []string{s.Name}
42+
for _, dep := range s.Dependencies {
43+
schemas = append(schemas, dep.Name)
44+
}
45+
files, err := compiler.Compile(ctx, schemas...)
4246
if err != nil {
4347
return nil, err
4448
}
45-
res := files[0].(linker.Result)
49+
res := make([]linker.Result, len(files))
50+
for i, f := range files {
51+
res[i] = f.(linker.Result)
52+
}
4653
return res, nil
4754
}
4855

@@ -51,19 +58,24 @@ func (s Schema) CompileBufImage() (bufimage.Image, error) {
5158
if err != nil {
5259
return nil, err
5360
}
54-
imageFile, err := bufimage.NewImageFile(
55-
res.FileDescriptorProto(),
56-
nil,
57-
uuid.Nil,
58-
"",
59-
"",
60-
false,
61-
false,
62-
nil,
63-
)
64-
if err != nil {
65-
return nil, err
61+
files := make([]bufimage.ImageFile, len(res))
62+
for i, r := range res {
63+
file, err := bufimage.NewImageFile(
64+
r.FileDescriptorProto(),
65+
nil,
66+
uuid.Nil,
67+
"",
68+
"",
69+
false,
70+
false,
71+
nil,
72+
)
73+
if err != nil {
74+
return nil, err
75+
}
76+
files[i] = file
6677
}
67-
image, err := bufimage.NewImage([]bufimage.ImageFile{imageFile})
78+
79+
image, err := bufimage.NewImage(files)
6880
return image, err
6981
}

karapace/compatibility/protobuf/checks.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,31 @@
1111
def check_protobuf_schema_compatibility(
1212
reader: ProtobufSchema, writer: ProtobufSchema, use_protopace: bool = False
1313
) -> SchemaCompatibilityResult:
14-
result = CompareResult()
15-
1614
if use_protopace:
1715
old_deps = []
18-
for _, val in reader.dependencies.items():
19-
old_deps.append(Proto(val.name, val.get_schema().schema_str))
20-
old_proto = Proto(reader.record_name, reader.to_schema(), old_deps)
16+
# TODO: get dependencies recursive
17+
if reader.dependencies:
18+
for _, val in reader.dependencies.items():
19+
old_deps.append(Proto(val.name, val.get_schema().schema_str))
20+
old_proto = Proto("test.proto", reader.to_schema(), old_deps)
2121

2222
new_deps = []
23-
for _, val in writer.dependencies.items():
24-
new_deps.append(Proto(val.name, val.get_schema().schema_str))
25-
new_proto = Proto(writer.record_name, writer.to_schema(), old_deps)
23+
if writer.dependencies:
24+
for _, val in writer.dependencies.items():
25+
new_deps.append(Proto(val.name, val.get_schema().schema_str))
26+
new_proto = Proto("test.proto", writer.to_schema(), new_deps)
2627

2728
try:
2829
check_compatibility(new_proto, old_proto)
29-
except IncompatibleError:
30-
result.add_modification(Modification.PROTOPACE)
30+
except IncompatibleError as err:
31+
return SchemaCompatibilityResult(
32+
compatibility=SchemaCompatibilityType.incompatible,
33+
messages=set([str(err)]),
34+
)
3135

32-
return result
36+
return SchemaCompatibilityResult(SchemaCompatibilityType.compatible)
3337

38+
result = CompareResult()
3439
writer.compare(reader, result)
3540
if result.is_compatible():
3641
return SchemaCompatibilityResult(SchemaCompatibilityType.compatible)

karapace/protobuf/compare_result.py

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Modification(Enum):
3434
ONE_OF_FIELD_DROP = auto()
3535
ONE_OF_FIELD_MOVE = auto()
3636
FEW_FIELDS_CONVERTED_TO_ONE_OF = auto()
37-
PROTOPACE = auto()
3837

3938
# protobuf compatibility issues is described in at
4039
# https://yokota.blog/2021/08/26/understanding-protobuf-compatibility/
@@ -48,7 +47,6 @@ def is_compatible(self) -> bool:
4847
self.FIELD_TAG_ALTER,
4948
self.ONE_OF_FIELD_DROP,
5049
self.FEW_FIELDS_CONVERTED_TO_ONE_OF,
51-
self.PROTOPACE,
5250
] # type: ignore[comparison-overlap]
5351

5452

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

karapace/protobuf/protopace/protopace.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
if arch == "x86_64":
1919
arch = "amd64"
20+
elif arch == "aarch64":
21+
arch = "arm64"
2022

2123
lib_file = os.path.join(file_dir, f"bin/protopace-{system}-{arch}.so")
2224

@@ -75,9 +77,9 @@ def check_compatibility(proto: Proto, prev_proto: Proto) -> None:
7577
c_dependencies = (ctypes.c_char_p * length)(*[d.schema.encode() for d in proto.dependencies])
7678
c_dependency_names = (ctypes.c_char_p * length)(*[d.name.encode() for d in proto.dependencies])
7779

78-
prev_length = len(proto.dependencies)
79-
prev_c_dependencies = (ctypes.c_char_p * length)(*[d.schema.encode() for d in prev_proto.dependencies])
80-
prev_c_dependency_names = (ctypes.c_char_p * length)(*[d.name.encode() for d in prev_proto.dependencies])
80+
prev_length = len(prev_proto.dependencies)
81+
prev_c_dependencies = (ctypes.c_char_p * prev_length)(*[d.schema.encode() for d in prev_proto.dependencies])
82+
prev_c_dependency_names = (ctypes.c_char_p * prev_length)(*[d.name.encode() for d in prev_proto.dependencies])
8183

8284
err = lib.CheckCompatibility(
8385
proto.name.encode(),

karapace/schema_registry_apis.py

+1
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ async def compatibility_check(
452452
use_protopace=self.config["use_protopace"],
453453
)
454454
if is_incompatible(result):
455+
self.log.info(f'incompatible: {result.messages}')
455456
self.r({"is_compatible": False}, content_type)
456457
self.r({"is_compatible": True}, content_type)
457458

tests/integration/test_dependencies_compatibility_protobuf.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ async def test_protobuf_schema_compatibility_dependencies1g(registry_async_clien
323323
evolved_schema = """
324324
syntax = "proto3";
325325
package a1;
326-
import "google/type/postal_address.proto";
326+
import "google/protobuf/duration.proto";
327327
message TestMessage {
328328
message V {
329-
google.type.PostalAddress h = 1;
329+
google.protobuf.Duration h = 1;
330330
int32 x = 2;
331331
}
332332
string t = 1;
@@ -369,10 +369,10 @@ async def test_protobuf_schema_compatibility_dependencies1g_otherway(registry_as
369369
original_schema = """
370370
syntax = "proto3";
371371
package a1;
372-
import "google/type/postal_address.proto";
372+
import "google/protobuf/duration.proto";
373373
message TestMessage {
374374
message V {
375-
google.type.PostalAddress h = 1;
375+
google.protobuf.Duration h = 1;
376376
int32 x = 2;
377377
}
378378
string t = 1;
@@ -617,13 +617,13 @@ async def test_protobuf_customer_update_when_having_references(registry_async_cl
617617
syntax = "proto3";
618618
package a1;
619619
import "place.proto";
620-
import "google/type/postal_address.proto";
620+
import "google/protobuf/duration.proto";
621621
// @producer: another comment
622622
message Customer {
623623
string name = 1;
624624
int32 code = 2;
625625
Place place = 3;
626-
google.type.PostalAddress address = 4;
626+
google.protobuf.Duration address = 4;
627627
}
628628
"""
629629
body = {
@@ -645,13 +645,13 @@ async def test_protobuf_customer_update_when_having_references(registry_async_cl
645645
syntax = "proto3";
646646
package a1;
647647
import "place.proto";
648-
import "google/type/postal_address.proto";
648+
import "google/protobuf/duration.proto";
649649
// @consumer: the comment was incorrect, updating it now
650650
message Customer {
651651
string name = 1;
652652
int32 code = 2;
653653
Place place = 3;
654-
google.type.PostalAddress address = 4;
654+
google.protobuf.Duration address = 4;
655655
}
656656
"""
657657

0 commit comments

Comments
 (0)