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

Windows Support #246

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Windows Support #246

wants to merge 8 commits into from

Conversation

compnerd
Copy link

There was a Swift forums thread that indicated that people wanted to use this package on Windows but it did not build due to the missing header. In order to verify if it built on Windows, I built it locally. This led to a series of changes which ultimately enabled the Windows support in the package. I am opening the PR in case it is interesting for the project to enable Windows support.

`free` should not be used to release the memory allocation.  The
allocation was performed with `UnsafeMutablePointer.allocate(capacity:)`
which does not provide a guarantee on the allocation being performed
with `malloc`.  In fact, on Windows, this is actively not the case and
is is performed with `_aligned_alloc`.  Therefore the release must be
balanced with the MSVC specific `_aligned_free`.  Instead, prefer to use
the portable `UnsafeMutablePointer.deallocate` to correctly balance the
memory allocation.
Rather than explicitly trying to handle the memory management lifetime,
extend the lifetime to the scope and use a `defer` statement to ensure
that the memory is always deallocated when exiting the scope.
The `unzGetCurrentFileInfo64` signature does not use a C type for the
length but rather a local type definition.  The type definition
underlying it is a `long` which is differently sized on LP64 and LLP64
systems.  Adjust this by casting the parameter to the proper type
(`uLong`) as vended by the C library.
When using vim as the editor, some configurations may emit the swap file
next to the source.  Ignore swap files from accidentally being
committed.
`#import` is an Objective-C construct and is not portable.  `#include`
is the standard mechanism for including a source file.  Use of the
Objective-C mechanism works in many cases but not globally.  On Windows,
this is used as a MSVC extension for COM type library inclusion.

Switch to the standard spelling to allow building on Windows.
The linking is already handled at the SPM layer.  There is no reason to
force a secondary link directive.  This primarily impacts Darwin
platforms where the link directive would form a `LC_LINKER_OPTION` load
command to ensure that zlib is linked against.  However, we have the
platform specific linkage and this is already performed at the SPM
layer.  Remove the directive and allow SPM to handle it.
The library name for zlib is different on Windows than on Unix platforms
(`zlib` and `zlibstatic`).  In order to support properly linking against
the library the user must specify the linkage type.  Since SwiftPM does
not have the ability to properly control build settings, use an
environment variable to select between the two.  If
`ZIP_USE_DYNAMIC_ZLIB` is set, we will attempt to perform dynamic
linkage against zlib, otherwise, we will use static linking.

Take the opportunity to silence some warnings due to deprecated symbol
usage on Windows.

A build of zlib must be available for use and must be explicitly passed
to the build on Windows via extended flags (i.e. `-Xcc` and `-Xlinker`).
Windows does not have full POSIX permissions and instead has a far
richer permission model through proper ACLing.  Adjust the expectations
accordingly.
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

Successfully merging this pull request may close these issues.

None yet

1 participant