Skip to content

Commit f38e9a9

Browse files
authored
Windows support and other various changes (#10)
### 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
1 parent 567d515 commit f38e9a9

40 files changed

+727
-443
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Sources/Minizip/* linguist-vendored
1+
Sources/CMinizip/* linguist-vendored

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @fpseverino

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,49 @@ on:
99
jobs:
1010
unit-tests:
1111
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
12+
with:
13+
with_linting: true
14+
with_musl: true
15+
ios_scheme_name: Zip
1216
secrets:
1317
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18+
19+
windows-unit:
20+
if: ${{ !(github.event.pull_request.draft || false) }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
swift-version:
25+
- 5.9
26+
- 5.10
27+
- 6.0
28+
include:
29+
- { swift-version: 5.9, swift-branch: swift-5.9.2-release, swift-tag: 5.9.2-RELEASE }
30+
- { swift-version: 5.10, swift-branch: swift-5.10.1-release, swift-tag: 5.10.1-RELEASE }
31+
- { swift-version: 6.0, swift-branch: swift-6.0.1-release, swift-tag: 6.0.1-RELEASE }
32+
runs-on: windows-latest
33+
timeout-minutes: 60
34+
steps:
35+
- name: Install Windows Swift toolchain
36+
uses: compnerd/gha-setup-swift@main
37+
with:
38+
branch: ${{ matrix.swift-branch }}
39+
tag: ${{ matrix.swift-tag }}
40+
- name: Download zlib
41+
run: |
42+
curl -L -o zlib.zip https://www.zlib.net/zlib131.zip
43+
mkdir zlib-131
44+
tar -xf zlib.zip -C zlib-131 --strip-components=1
45+
- name: Build and install zlib
46+
run: |
47+
cd zlib-131
48+
mkdir build
49+
cd build
50+
cmake ..
51+
cmake --build . --config Release
52+
cmake --install . --prefix ../install
53+
- name: Check out code
54+
uses: actions/checkout@v4
55+
- name: Run unit tests
56+
run: |
57+
swift test -Xcc -I'C:/Program Files (x86)/zlib/include' -Xlinker -L'C:/Program Files (x86)/zlib/lib'

.swift-format

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"fileScopedDeclarationPrivacy": {
3+
"accessLevel": "private"
4+
},
5+
"indentation": {
6+
"spaces": 4
7+
},
8+
"indentConditionalCompilationBlocks": true,
9+
"indentSwitchCaseLabels": false,
10+
"lineBreakAroundMultilineExpressionChainComponents": false,
11+
"lineBreakBeforeControlFlowKeywords": false,
12+
"lineBreakBeforeEachArgument": false,
13+
"lineBreakBeforeEachGenericRequirement": false,
14+
"lineLength": 140,
15+
"maximumBlankLines": 1,
16+
"multiElementCollectionTrailingCommas": true,
17+
"noAssignmentInExpressions": {
18+
"allowedFunctions": [
19+
"XCTAssertNoThrow"
20+
]
21+
},
22+
"prioritizeKeepingFunctionOutputTogether": false,
23+
"respectsExistingLineBreaks": true,
24+
"rules": {
25+
"AllPublicDeclarationsHaveDocumentation": false,
26+
"AlwaysUseLiteralForEmptyCollectionInit": false,
27+
"AlwaysUseLowerCamelCase": false,
28+
"AmbiguousTrailingClosureOverload": true,
29+
"BeginDocumentationCommentWithOneLineSummary": false,
30+
"DoNotUseSemicolons": true,
31+
"DontRepeatTypeInStaticProperties": true,
32+
"FileScopedDeclarationPrivacy": true,
33+
"FullyIndirectEnum": true,
34+
"GroupNumericLiterals": true,
35+
"IdentifiersMustBeASCII": true,
36+
"NeverForceUnwrap": false,
37+
"NeverUseForceTry": false,
38+
"NeverUseImplicitlyUnwrappedOptionals": false,
39+
"NoAccessLevelOnExtensionDeclaration": true,
40+
"NoAssignmentInExpressions": true,
41+
"NoBlockComments": true,
42+
"NoCasesWithOnlyFallthrough": true,
43+
"NoEmptyTrailingClosureParentheses": true,
44+
"NoLabelsInCasePatterns": true,
45+
"NoLeadingUnderscores": false,
46+
"NoParensAroundConditions": true,
47+
"NoPlaygroundLiterals": true,
48+
"NoVoidReturnOnFunctionSignature": true,
49+
"OmitExplicitReturns": false,
50+
"OneCasePerLine": true,
51+
"OneVariableDeclarationPerLine": true,
52+
"OnlyOneTrailingClosureArgument": true,
53+
"OrderedImports": true,
54+
"ReplaceForEachWithForLoop": true,
55+
"ReturnVoidInsteadOfEmptyTuple": true,
56+
"TypeNamesShouldBeCapitalized": true,
57+
"UseEarlyExits": false,
58+
"UseExplicitNilCheckInConditions": true,
59+
"UseLetInEveryBoundCaseVariable": true,
60+
"UseShorthandTypeNames": true,
61+
"UseSingleLinePropertyGetter": true,
62+
"UseSynthesizedInitializer": true,
63+
"UseTripleSlashForDocumentationComments": true,
64+
"UseWhereClausesInForLoops": false,
65+
"ValidateDocumentationComments": false
66+
},
67+
"spacesAroundRangeFormationOperators": false,
68+
"tabWidth": 8,
69+
"version": 1
70+
}

Package.swift

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,68 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.9
22
import PackageDescription
33

4+
#if canImport(Darwin) || compiler(<6.0)
5+
import Foundation
6+
#else
7+
import FoundationEssentials
8+
#endif
9+
410
let package = Package(
511
name: "Zip",
612
products: [
713
.library(name: "Zip", targets: ["Zip"])
814
],
915
targets: [
1016
.target(
11-
name: "Minizip",
12-
exclude: ["module"],
13-
swiftSettings: [
14-
.enableUpcomingFeature("ConciseMagicFile"),
17+
name: "CMinizip",
18+
cSettings: [
19+
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
1520
],
16-
linkerSettings: [
17-
.linkedLibrary("z")
18-
]
21+
swiftSettings: swiftSettings
1922
),
2023
.target(
2124
name: "Zip",
2225
dependencies: [
23-
.target(name: "Minizip"),
26+
.target(name: "CMinizip")
27+
],
28+
cSettings: [
29+
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
2430
],
25-
swiftSettings: [
26-
.enableUpcomingFeature("ConciseMagicFile"),
27-
]
31+
swiftSettings: swiftSettings
2832
),
2933
.testTarget(
3034
name: "ZipTests",
3135
dependencies: [
32-
.target(name: "Zip"),
36+
.target(name: "Zip")
3337
],
3438
resources: [
35-
.copy("Resources"),
39+
.copy("TestResources")
3640
],
37-
swiftSettings: [
38-
.enableUpcomingFeature("ConciseMagicFile"),
39-
]
41+
swiftSettings: swiftSettings
4042
),
4143
]
4244
)
45+
46+
var swiftSettings: [SwiftSetting] {
47+
[
48+
.enableUpcomingFeature("ExistentialAny"),
49+
.enableUpcomingFeature("ConciseMagicFile"),
50+
.enableUpcomingFeature("ForwardTrailingClosures"),
51+
.enableUpcomingFeature("DisableOutwardActorInference"),
52+
.enableUpcomingFeature("StrictConcurrency"),
53+
.enableExperimentalFeature("StrictConcurrency=complete"),
54+
]
55+
}
56+
57+
if let target = package.targets.filter({ $0.name == "CMinizip" }).first {
58+
#if os(Windows)
59+
if ProcessInfo.processInfo.environment["ZIP_USE_DYNAMIC_ZLIB"] == nil {
60+
target.cSettings?.append(contentsOf: [.define("ZLIB_STATIC")])
61+
target.linkerSettings = [.linkedLibrary("zlibstatic")]
62+
} else {
63+
target.linkerSettings = [.linkedLibrary("zlib")]
64+
}
65+
#else
66+
target.linkerSettings = [.linkedLibrary("z")]
67+
#endif
68+
}

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,41 @@
1212
<img src="https://img.shields.io/codecov/c/github/vapor-community/Zip?style=plastic&logo=codecov&label=codecov">
1313
</a>
1414
<a href="https://swift.org">
15-
<img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+">
15+
<img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+">
1616
</a>
1717
</div>
1818
<br>
1919

20-
A framework for zipping and unzipping files in Swift.
20+
📂 A framework for zipping and unzipping files in Swift.
2121

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

25+
## Overview
26+
27+
### Getting Started
28+
2529
Use the SPM string to easily include the dependendency in your `Package.swift` file.
2630

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

31-
## Usage
35+
and add it to your target's dependencies:
36+
37+
```swift
38+
.product(name: "Zip", package: "zip")
39+
```
40+
41+
### Supported Platforms
42+
43+
Zip supports all platforms supported by Swift 5.9 and later.
44+
45+
To use Zip on Windows, you need to pass an available build of `zlib` to the build via extended flags. For example:
46+
47+
```shell
48+
swift build -Xcc -I'C:/pathTo/zlib/include' -Xlinker -L'C:/pathTo/zlib/lib'
49+
```
3250

3351
### Quick Functions
3452

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

File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// CMinizip.h
3+
// Zip
4+
//
5+
// Created by Florian Friedrich on 3/27/19.
6+
// Copyright © 2019 Roy Marmelstein. All rights reserved.
7+
//
8+
9+
#ifndef CMinizip_h
10+
#define CMinizip_h
11+
12+
#include "ioapi.h"
13+
#include "crypt.h"
14+
#include "unzip.h"
15+
#include "zip.h"
16+
17+
#endif /* CMinizip_h */
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)