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 and other various changes #10

Merged
merged 123 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 121 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
74104c8
Add support for Windows
fpseverino Sep 6, 2024
84d232c
Add Windows CI tests
fpseverino Sep 6, 2024
96ee005
Fix tests
fpseverino Sep 6, 2024
91da55c
Fix tests again
fpseverino Sep 6, 2024
b5bcdf9
Add Foundation to Package.swift (for Windows)
fpseverino Sep 6, 2024
5abe368
Remove TSAN on Windows CI
fpseverino Sep 6, 2024
d7ce892
Try adding zlib to Windows
fpseverino Sep 6, 2024
de20838
Try installing zlib on Windows
fpseverino Sep 6, 2024
bd937aa
Try manually downloading zlib
fpseverino Sep 6, 2024
b8b5284
Switch from `tar` to 7Zip
fpseverino Sep 7, 2024
64ae784
Fix `zlib` link
fpseverino Sep 7, 2024
c004302
Fix `zlib` file name
fpseverino Sep 7, 2024
3f1d112
Fix Windows CI
fpseverino Sep 7, 2024
c74b3e3
Fix `swift test` command on Windows
fpseverino Sep 7, 2024
54a3062
Fix library directory on Windows
fpseverino Sep 7, 2024
1a63d1e
Remove unecessary escaping in CI
fpseverino Sep 7, 2024
0b0fde2
Add quotes to CI command
fpseverino Sep 7, 2024
27d0631
Fix path traversal on Windows
fpseverino Sep 7, 2024
725fc95
Add CODEOWNERS
fpseverino Sep 7, 2024
0ebf430
Custom permissions on Windows
fpseverino Sep 8, 2024
e2e6fe5
Try changing permissions
fpseverino Sep 8, 2024
61b9d18
Sophisticated debug
fpseverino Sep 8, 2024
59ea45f
More advanced debugging
fpseverino Sep 9, 2024
ccc15db
Remove debugging too advanced for our times
fpseverino Sep 9, 2024
6cd1e4c
More debugging prints
fpseverino Sep 9, 2024
bd66eed
Even more print statements
fpseverino Sep 9, 2024
43d1a60
Try replacing colons in Windows
fpseverino Sep 9, 2024
a05d515
Try better method of removing colons
fpseverino Sep 9, 2024
c5ba7d1
Fix compiler complains
fpseverino Sep 9, 2024
88e9d7b
Fix typo
fpseverino Sep 9, 2024
3d8a54e
Try changing char
fpseverino Sep 9, 2024
48a3582
Another char
fpseverino Sep 9, 2024
56b206f
New sophisticated debugging
fpseverino Sep 9, 2024
433fc61
Try zipping the file on Windows
fpseverino Sep 9, 2024
b9b43af
Try unzipping the Finder file in Windows tests
fpseverino Sep 9, 2024
4b68f84
Try setting permissions on Windows
fpseverino Sep 9, 2024
b3a50b8
Try fix permission on Windows
fpseverino Sep 9, 2024
3bba399
Try Copilot suggestion for permissions
fpseverino Sep 9, 2024
00ecf98
Add WinSDK
fpseverino Sep 9, 2024
0d12dc0
Fix Windows permissions
fpseverino Sep 9, 2024
5662231
Again, fix Windows APIs
fpseverino Sep 9, 2024
9113f27
Try fixing bug
fpseverino Sep 9, 2024
dee3cec
Try removing permission on Windows
fpseverino Sep 10, 2024
7aa2848
Try again removing colons
fpseverino Sep 10, 2024
af87289
Try to use same tests
fpseverino Sep 10, 2024
3a0e530
Add more tests
fpseverino Sep 10, 2024
54471c2
Futuristic debugging
fpseverino Sep 10, 2024
6641007
Try fixing Windows tests
fpseverino Sep 10, 2024
516905f
Refactor file handler test
fpseverino Sep 10, 2024
6446ecf
Try more sophisticated debug
fpseverino Sep 10, 2024
0a8500a
Add prefix to URLs on Windows
fpseverino Sep 10, 2024
63b0635
Final touches
fpseverino Sep 10, 2024
dab6f9e
Real last touches
fpseverino Sep 10, 2024
25cfef1
Last last touches
fpseverino Sep 10, 2024
5ecd264
import FoundationEssentials
fpseverino Sep 10, 2024
6d27f1b
Try using `swift-system`
fpseverino Sep 12, 2024
a1d92aa
Remove `swift-system`
fpseverino Sep 12, 2024
74b2c1f
Add Swift 6 Windows CI
fpseverino Sep 21, 2024
af7eb7b
Fix tests
fpseverino Sep 21, 2024
b8b94f1
Debug Windows on 6.0
fpseverino Sep 21, 2024
17547c3
More debugging
fpseverino Sep 21, 2024
c8b266d
More debugging
fpseverino Sep 21, 2024
cefe774
Remove debug prints
fpseverino Sep 21, 2024
776bfa8
Try again with `swift-system`
fpseverino Sep 22, 2024
f371520
Fix permissions
fpseverino Sep 22, 2024
e9965bb
Change permissions on Windows
fpseverino Sep 22, 2024
465c1ab
Give up on `swift-system`
fpseverino Sep 22, 2024
b5a4849
Debug zipping
fpseverino Sep 22, 2024
d012000
Remove print statements
fpseverino Sep 22, 2024
0795d58
Update Windows CI Swift version to 6.0.1
fpseverino Sep 28, 2024
a098012
Fix tests
fpseverino Sep 28, 2024
18eac81
Fix `import FoundationEssentials`
fpseverino Sep 29, 2024
8c30bda
Fix `import FoundationEssentials`
fpseverino Sep 29, 2024
64de55f
Try @compnerd fix
fpseverino Sep 29, 2024
5650dae
Try more debugging
fpseverino Sep 29, 2024
1729655
Small fix
fpseverino Sep 29, 2024
d91b56f
Try fixing zipping
fpseverino Sep 29, 2024
3689887
Fix some tests
fpseverino Sep 29, 2024
516384c
Fix macro
fpseverino Sep 29, 2024
4f0debd
Fix Foundation problems
fpseverino Sep 29, 2024
1e23b68
Improve file handler
fpseverino Sep 29, 2024
ac17fc7
Fix Windows file name validation in Zip.swift
fpseverino Oct 2, 2024
97d24c1
Fix Windows file name validation in ZipTests.swift
fpseverino Oct 2, 2024
6a36697
Fix Windows file name validation in Zip.swift
fpseverino Oct 2, 2024
9a38aba
Fix Windows file name validation in Zip.swift and ZipTests.swift
fpseverino Oct 2, 2024
668236f
Fix tests on Windows
fpseverino Oct 2, 2024
76f1c5a
Try adding back `directoryAttributes`
fpseverino Oct 2, 2024
66ef006
Try renaming files in Windows
fpseverino Oct 4, 2024
679ce96
Fix Windows bugs
fpseverino Oct 4, 2024
4506aea
Improve Windows file name updating
fpseverino Oct 4, 2024
6c4a6b8
Add test for handling Windows reserved characters in filenames
fpseverino Oct 4, 2024
386625d
Fix Windows renaming
fpseverino Oct 4, 2024
1e753bf
Improve testing
fpseverino Oct 4, 2024
e23360d
debugging
fpseverino Oct 4, 2024
dc1ed91
Try debugging
fpseverino Oct 4, 2024
c717b29
More debugging
fpseverino Oct 4, 2024
71d0079
Try fixing Windows file renaming
fpseverino Oct 4, 2024
857ab71
Fix typo
fpseverino Oct 4, 2024
e65a61d
Try another fix
fpseverino Oct 4, 2024
9101997
Try the most sophisticated debugging
fpseverino Oct 4, 2024
01fe9c6
Found the bug
fpseverino Oct 4, 2024
1553464
Remove support for Swift 5.8
fpseverino Oct 5, 2024
72b9947
Adopt `swift-format`
fpseverino Oct 5, 2024
d348c9d
Small fixes
fpseverino Oct 5, 2024
cf43031
Move to vapor/ci linting
fpseverino Oct 5, 2024
f2e3fc4
Try better renaming on Windows
fpseverino Oct 6, 2024
c2c2ba2
Revert last commit
fpseverino Oct 6, 2024
429c905
Clean up
fpseverino Oct 6, 2024
060f7e2
Fix bug
fpseverino Oct 6, 2024
43c645a
More clean up
fpseverino Oct 6, 2024
0e8547f
Try testing on MUSL and iOS
fpseverino Oct 12, 2024
3912b6b
Try adding `platforms` to Package.swift
fpseverino Oct 12, 2024
5ef50d0
Just test on MUSL for now
fpseverino Oct 12, 2024
eacc47e
Try again testing on iOS
fpseverino Oct 12, 2024
69db78c
Fix iOS testing
fpseverino Oct 12, 2024
d93a688
Add documentation for Windows
fpseverino Oct 15, 2024
8af2981
Deprecate extension code, refactor code and tests
fpseverino Nov 4, 2024
1ab9309
Make linter happy and update README
fpseverino Nov 4, 2024
537aa47
Synchronize `customFileExtensions` with `NSLock`
fpseverino Nov 5, 2024
cbdbb39
Fix for previous versions of Swift
fpseverino Nov 5, 2024
145d03d
Update compiler version check for custom file extensions
fpseverino Nov 5, 2024
d271668
Apply Saleem changes
fpseverino Nov 7, 2024
3078cbf
Make the linter happy
fpseverino Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Validating CODEOWNERS rules …
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