alexeyxo / protobuf-swift

Google ProtocolBuffers for Apple Swift
http://protobuf.io/#swift
Apache License 2.0
937 stars 138 forks source link

Package name end with `.Protobuf` in proto3 #130

Open langyanduan opened 8 years ago

langyanduan commented 8 years ago
protoc
$ brew update
$ brew install protobuf --devel --verbose
...
$ protoc --version
libprotoc 3.0.0
protobuf-swift
$ git clone https://github.com/alexeyxo/protobuf-swift
$ git checkout -b ProtoBuf3.0-Swift2.0 origin/ProtoBuf3.0-Swift2.0
$ ./scripts/build.sh
Cocoapods
pod 'ProtocolBuffers-Swift', :git => 'https://github.com/alexeyxo/protobuf-swift', :branch => 'ProtoBuf3.0-Swift2.0'

Error

if named package end with .Protobuf, the swift file will has wrong package name.

.proto file

syntax = "proto3";
package Swift.Protobuf;

.swift file

// Generated by the Protocol Buffers 3.0 compiler.  DO NOT EDIT!
// Source file "api.proto"
// Syntax "Proto3"

import Foundation
import ProtocolBuffers

public struct Swift { public extension Protobuf}

OK

if package named end with other word like Swift.Protobuf1, it's look good.

.proto file

syntax = "proto3";
package Swift.Protobuf1;

.swift file

// Generated by the Protocol Buffers 3.0 compiler.  DO NOT EDIT!
// Source file "api.proto"
// Syntax "Proto3"

import Foundation
import ProtocolBuffers

public struct Swift { public extension Protobuf1 { }}
alexeyxo commented 8 years ago

The word "Protobuf" is a reserved name for standard packages from google.

langyanduan commented 8 years ago

"Google.Protobuf" is a reserved name? But i see other language can supports "xxx.Protobuf" as package name.

kosciej commented 8 years ago

I confirm, other languages support package name like com.something.somethingelse.protobuf. "protobuf" in package name doesn't seem to be reserved word.

I've encountered the same issue when tried to compile proto file from my project (actively used with several mainstream languages).