chinedufn / swift-bridge

swift-bridge facilitates Rust and Swift interop.
https://chinedufn.github.io/swift-bridge
Apache License 2.0
842 stars 62 forks source link

Make extern Swift functions public to prevent stripping in Release builds #262

Open jmp-0x7C0 opened 8 months ago

jmp-0x7C0 commented 8 months ago

I had a quick stab at fixing #166, if I have understood the instructions correctly this would resolve the issue at the cost of changing the visibility of functions in the module.

@chinedufn let me know if I'm on the right track here.

So far I have only added tests for the swift-bridge-ir crate, I'm guessing it might make sense to also add a small repro example to run xcodebuild in release mode on CI.

chinedufn commented 8 months ago

I'm guessing it might make sense to also add a small repro example to run xcodebuild in release mode on CI.

This is a very good idea.

Here's one solution off the top of my head


Just a quick idea. You might have a better solution in mind.

jmp-0x7C0 commented 8 months ago

@chinedufn Ok I've create both a reproduction case that fails to build against the master branch, and a case that builds successfully against this branch.

I'm not sure we want this amount of code duplication for the repro case and the success case. There's probably also a smarter way to specify which versions of the dependencies to build e.g. using the cargo --config flag but I couldn't get it to work so I just created two separate projects. Also if this PR would be merged as is the tests would start failing as I'm currently pointing the failing case at the master branch.

If you have any suggestions for how to structure this code better, avoid the duplication etc. I'd be happy to make those changes.

I did have a go at reproducing the issue by just calling swiftc directly in the same way as the async-functions example but with release optimisation flags and code stripping enabled but I couldn't reproduce the issue. I also tried using swift build -c release, which also built successfully. But I was immediately able to reproduce the issue by creating a Swift Package and calling xcodebuild archive as reported by @bes.

chinedufn commented 8 months ago

Thanks for putting this together.

I'm not sure we want this amount of code duplication for the repro case and the success case.

We don't need to maintain two cases.

The purpose of making the failure case was for us to be sure that we weren't accidentally landing a test that would have always passed.

For example, you found that the swift build -c release example was always passing, so that would have been a bad test.

we just need to land one of the test crates, not both. Then we can have confidence that your code for going from func -> public func is working as intended.

I did have a go at reproducing the issue by just calling swiftc directly in the same way as the async-functions example but with release optimisation flags and code stripping enabled but I couldn't reproduce the issue. I also tried using swift build -c release, which also built successfully. But I was immediately able to reproduce the issue by creating a Swift Package and calling xcodebuild archive.

Great. Thanks for figuring this out.

In the test crate's README Let's document what we tried and why we think it didn't work.

This helps with:

In short, a maintainer should be able to clearly understand why we are using a more complex solution (Swift Package + xcodebuild) instead of a simpler one (swiftc).

chinedufn commented 7 months ago

Are you able to complete this pull request? Looks like the main remaining work is to delete one of the test packages.

Is there anything that I can help with?

extrawurst commented 6 months ago

would be awesome to get this merged

jmp-0x7C0 commented 6 months ago

@chinedufn

Are you able to complete this pull request?

Thank you for the review. I've been quite busy with other projects recently, but I should have a bit more time to get this finished next week.

chinedufn commented 5 months ago

Hello, hello. Anticipate having any time for this?