Skip to content

SwiftProtobuf: Consider swift_access_level file option #59

@ktoso

Description

@ktoso

How about we introduce an FileOption in the files and use it like:

We want to offer some types as public so users can easily use them in their types; This is mostly about ActorAddress really;

We currently expose this by manually passing the public access level option on CLI https://github.com/apple/swift-distributed-actors/pull/58/files

We could alternatively:

for p in $(find . -name "*.proto"); do
    out_dir=$( dirname "$p" )
    base_name=$( echo basename "$p" | sed "s/.*\///" )
    out_name="${base_name%.*}.pb.swift"
    dest_dir="../Sources/DistributedActors/${out_dir}/Protobuf"
    dest_file="${dest_dir}/${out_name}"
    mkdir -p ${dest_dir}

    access_level=""
    if [[ $(grep '(swift_access_level) = PUBLIC' ${p} | wc -l) -eq 1 ]]; then
        access_level="--swift_opt=Visibility=Public"
    fi

    command="protoc --swift_out=. ${p} ${access_level}"
    echo $command
   `$command`
    mv "${out_dir}/${out_name}" "${dest_file}"
done

And in source:

import "google/protobuf/descriptor.proto";

enum SwiftAccessLevel {
    INTERNAL = 0;
    PUBLIC = 1;
}
extend google.protobuf.FileOptions {
    SwiftAccessLevel sact_access_level = 542700;
} // move this to some Options.proto and import it
option optimize_for = SPEED;
option swift_prefix = "Proto";
option (swift_access_level) = PUBLIC; // could be built-in to protobuf plugin, we'd import SwiftProtobufOptions.proto I guess

To be honest, this should be built-in in the Swift Protobuf plugin... https://github.com/apple/swift-protobuf

I'm checking if/how we can collaborate on that plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionNeeds further discussion to reach desicioni:protobufIntegration with ProtoBuf

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions