Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Doesn't work in playground due to zlib code #50

Closed
e28eta opened this issue Jul 25, 2016 · 5 comments
Closed

Doesn't work in playground due to zlib code #50

e28eta opened this issue Jul 25, 2016 · 5 comments

Comments

@e28eta
Copy link

e28eta commented Jul 25, 2016

When I include WebSocket.swift in a playground's sources directory, the playground fails to execute.

I'm able to work around the failure by commenting out the @_silgen_name declarations for libz methods and the uses of those methods in the Inflator/Deflator classes.

I'm not sure what the real solution to the problem is. Maybe using Apple's libcompression API, but I haven't (yet) taken the time to compare it to libz.

@tidwall
Copy link
Owner

tidwall commented Jul 25, 2016

I'm not familiar with playgrounds, but I did take a look and I couldn't find a solution just yet. It appears that there is no #if !PLAYGROUND #endif sort of preprocessor for the playground or swift. Also I can't find a way to include zlib into a playground project.

I looked at other libraries that Apple recommends such as LZ4, LZMA, and LZFSE. All of them seem to require a linking stage which I don't think is possible in playground.

As it stands the only reasonable solution that I know of is to comment out the code.

I'll keep looking and hopefully I'll find something.

@e28eta
Copy link
Author

e28eta commented Jul 26, 2016

The documentation you linked to is what I was looking at. It looks trivially easy to use in the playground, just import Compression module. I didn't actually check, but I'm sure that's all you have to do to use them for any other project.

@tidwall
Copy link
Owner

tidwall commented Jul 27, 2016

Thanks for pointing that out.

I was able to swap out the old code with the new and it seems to compile (though I haven't test if the inflating actually works). I had to include the Compression framework to the project.

I'm still not able to get it to work in the playground. I added the WebSocket.swift and the libcompression.tbd file to the project.

image

Here's a gist of the WebSocket.swift

I must be close. Do you have any ideas?

@e28eta
Copy link
Author

e28eta commented Aug 1, 2016

I'm having trouble with Xcode 7.3/Swift 2.2. It's choking on the libcompression code when it's in the Sources directory. It looks like it's not linking against the library correctly. I set up a minimal test case playground: a single file in Sources containing just enough code to call compression_stream_init. It's happy with references to the compression_stream struct, and the enum values for status. As soon as I add the method call, compilation of the Sources seems to fail:

dyld: warning: could not load inserted library '.../TestPlayground_Sources.framework/TestPlayground_Sources' because image not found
Playground execution failed: .../playground4.swift:18:8: error: no such module 'TestPlayground_Sources'
import TestPlayground_Sources

Taking the exact same playground & code (changing 1 line for Swift 3), it seems to be working in Xcode 8b2. Moving that minimal code out of the file in Sources directory and putting it into the playground's Contents.swift (the "playground" file), it works fine under 7.3. So maybe there's a 7.3 incompatibility or bug?

I did not need to include libcompression.tbd (and don't know what that does, but it seemed to make things worse in 7.3).

I may keep looking at this today or tomorrow, and see if I can get libcompression working with the Swift 3.0 version of WebSocket.swift that I've been playing with.

@tidwall
Copy link
Owner

tidwall commented Aug 1, 2016

That's good news. If all seem well with Xcode 8 then I'll migrate to libcompression for Swift 3.
And I'll probably leave zlib in Swift 2.

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

No branches or pull requests

2 participants