Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to use @_implementationOnly import SwiftProtobuf #1157

Closed
wangjiejacques opened this issue Jul 7, 2021 · 13 comments
Closed

Add an option to use @_implementationOnly import SwiftProtobuf #1157

wangjiejacques opened this issue Jul 7, 2021 · 13 comments

Comments

@wangjiejacques
Copy link

Currently the generated xxx.pb.swift always use import SwiftProtobuf, but sometimes we want to use @_implementationOnly import SwiftProtobuf, it would be nice to have an option to do so.

@teogeos
Copy link

teogeos commented Jul 7, 2021

For context: we make a library, an XCFramework used by our client's apps. Without @_implementationOnly we get a warning and lose ABI stability warranty.

@thomasvl
Copy link
Collaborator

thomasvl commented Jul 7, 2021

If a proto file imports another one, it is likely because of the types (message/enums) are used as fields. So it wouldn't really be implementation only as the types are exposed by the types in the generate file.

I'm guessing you want the protos to be an implementation details of your types and you don't expose them? i.e. - they should be implementation imports of your code?

If that's what you are after, what's the error? Sounds like maybe this should be an issue agains Swift for the transitive imports of @_implementationOnly imports?

@teogeos
Copy link

teogeos commented Jul 7, 2021

We're not talking about protos importing other proto files. We're talking about importing the core SwiftProtobuf lib.

We're writing a framework that deals with protobufs. We call protoc to generate swift classes for our protos, then put the generated files in our project. But these generated files have import SwiftProtobuf, without @_implementationOnly, which means our framework loses ABI stability. As of now we have to add @_implementationOnly to the generated files ourselves.

We don't want to expose any type coming from SwiftProtobuf.

@wangjiejacques
Copy link
Author

Following this discussion, @_implementationOnly import SwiftProtobuf probably should be the default behavior.

@thomasvl
Copy link
Collaborator

thomasvl commented Jul 7, 2021

Ah, ok, I'm following now. I was mistakenly thinking you wanted all imports as impl only and that's what confused me.

@Lukasa
Copy link
Contributor

Lukasa commented Jul 7, 2021

@_implementationOnly should not be the default behaviour unless you like your code breaking in future Swift releases. 😉

@teogeos
Copy link

teogeos commented Jul 7, 2021

Makes sense to me not to make it default.

But do you think it could be a good idea to make it a code generation option?

@paynerc
Copy link

paynerc commented Jan 14, 2022

But do you think it could be a good idea to make it a code generation option?

It would be nice if there was an option for this... Ended up having a script do this after generating the .swift files.

@daniellfalcao
Copy link

@teogeos I'm trying to create a XCFramework with SwiftProtobuf dependency too but I got some erros describers here, can you give some tips? From what you said i think you obtained success to generate the framework

@Banck
Copy link

Banck commented Jul 1, 2022

Hey!
Is there any way to generate swift files with @_implementationOnly attribute in protoc?

@Lukasa
Copy link
Contributor

Lukasa commented Jul 4, 2022

At this time there is not.

@tbkka
Copy link
Collaborator

tbkka commented Sep 27, 2022

The standard Unix sed command can replace text in groups of files.

@wangjiejacques
Copy link
Author

Fixed by #1393

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants