Skip to content

Commit

Permalink
Windows support and other various changes (#10)
Browse files Browse the repository at this point in the history
### Issue #9 

Originally authored by @compnerd in marmelroy#246

- Add support for Windows
- Add Windows CI tests
- Drop support for Swift 5.8
- Adopt `swift-format`
- Add CI for iOS and MUSL
- Various bug fixes
  • Loading branch information
fpseverino authored Nov 7, 2024
1 parent 567d515 commit f38e9a9
Show file tree
Hide file tree
Showing 40 changed files with 727 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Sources/Minizip/* linguist-vendored
Sources/CMinizip/* linguist-vendored
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fpseverino
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,49 @@ on:
jobs:
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
with:
with_linting: true
with_musl: true
ios_scheme_name: Zip
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

windows-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
swift-version:
- 5.9
- 5.10
- 6.0
include:
- { swift-version: 5.9, swift-branch: swift-5.9.2-release, swift-tag: 5.9.2-RELEASE }
- { swift-version: 5.10, swift-branch: swift-5.10.1-release, swift-tag: 5.10.1-RELEASE }
- { swift-version: 6.0, swift-branch: swift-6.0.1-release, swift-tag: 6.0.1-RELEASE }
runs-on: windows-latest
timeout-minutes: 60
steps:
- name: Install Windows Swift toolchain
uses: compnerd/gha-setup-swift@main
with:
branch: ${{ matrix.swift-branch }}
tag: ${{ matrix.swift-tag }}
- name: Download zlib
run: |
curl -L -o zlib.zip https://www.zlib.net/zlib131.zip
mkdir zlib-131
tar -xf zlib.zip -C zlib-131 --strip-components=1
- name: Build and install zlib
run: |
cd zlib-131
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake --install . --prefix ../install
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests
run: |
swift test -Xcc -I'C:/Program Files (x86)/zlib/include' -Xlinker -L'C:/Program Files (x86)/zlib/lib'
70 changes: 70 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": true,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineLength": 140,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": true,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"tabWidth": 8,
"version": 1
}
60 changes: 43 additions & 17 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
// swift-tools-version:5.8
// swift-tools-version:5.9
import PackageDescription

#if canImport(Darwin) || compiler(<6.0)
import Foundation
#else
import FoundationEssentials
#endif

let package = Package(
name: "Zip",
products: [
.library(name: "Zip", targets: ["Zip"])
],
targets: [
.target(
name: "Minizip",
exclude: ["module"],
swiftSettings: [
.enableUpcomingFeature("ConciseMagicFile"),
name: "CMinizip",
cSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
],
linkerSettings: [
.linkedLibrary("z")
]
swiftSettings: swiftSettings
),
.target(
name: "Zip",
dependencies: [
.target(name: "Minizip"),
.target(name: "CMinizip")
],
cSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
],
swiftSettings: [
.enableUpcomingFeature("ConciseMagicFile"),
]
swiftSettings: swiftSettings
),
.testTarget(
name: "ZipTests",
dependencies: [
.target(name: "Zip"),
.target(name: "Zip")
],
resources: [
.copy("Resources"),
.copy("TestResources")
],
swiftSettings: [
.enableUpcomingFeature("ConciseMagicFile"),
]
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
]
}

if let target = package.targets.filter({ $0.name == "CMinizip" }).first {
#if os(Windows)
if ProcessInfo.processInfo.environment["ZIP_USE_DYNAMIC_ZLIB"] == nil {
target.cSettings?.append(contentsOf: [.define("ZLIB_STATIC")])
target.linkerSettings = [.linkedLibrary("zlibstatic")]
} else {
target.linkerSettings = [.linkedLibrary("zlib")]
}
#else
target.linkerSettings = [.linkedLibrary("z")]
#endif
}
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,41 @@
<img src="https://img.shields.io/codecov/c/github/vapor-community/Zip?style=plastic&logo=codecov&label=codecov">
</a>
<a href="https://swift.org">
<img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+">
<img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+">
</a>
</div>
<br>

A framework for zipping and unzipping files in Swift.
📂 A framework for zipping and unzipping files in Swift.

Simple and quick to use.
Built on top of [Minizip 1.2](https://github.com/zlib-ng/minizip-ng/tree/1.2).

## Overview

### Getting Started

Use the SPM string to easily include the dependendency in your `Package.swift` file.

```swift
.package(url: "https://github.com/vapor-community/Zip.git", from: "2.2.0")
```

## Usage
and add it to your target's dependencies:

```swift
.product(name: "Zip", package: "zip")
```

### Supported Platforms

Zip supports all platforms supported by Swift 5.9 and later.

To use Zip on Windows, you need to pass an available build of `zlib` to the build via extended flags. For example:

```shell
swift build -Xcc -I'C:/pathTo/zlib/include' -Xlinker -L'C:/pathTo/zlib/lib'
```

### Quick Functions

Expand Down Expand Up @@ -56,7 +74,7 @@ import Zip
do {
let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")!
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
try Zip.unzipFile(filePath, destination: documentsDirectory, overwrite: true, password: "password") { progress in
try Zip.unzipFile(filePath, destination: documentsDirectory, password: "password") { progress in
print(progress)
}

Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions Sources/CMinizip/include/CMinizip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CMinizip.h
// Zip
//
// Created by Florian Friedrich on 3/27/19.
// Copyright © 2019 Roy Marmelstein. All rights reserved.
//

#ifndef CMinizip_h
#define CMinizip_h

#include "ioapi.h"
#include "crypt.h"
#include "unzip.h"
#include "zip.h"

#endif /* CMinizip_h */
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions Sources/CMinizip/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CMinizip [system][extern_c] {
header "CMinizip.h"
export *
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 0 additions & 17 deletions Sources/Minizip/include/Minizip.h

This file was deleted.

5 changes: 0 additions & 5 deletions Sources/Minizip/module/module.modulemap

This file was deleted.

Loading

0 comments on commit f38e9a9

Please sign in to comment.