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

Commit

Permalink
commit code:
Browse files Browse the repository at this point in the history
Update libzip to 1.7.3; add support iOS
  • Loading branch information
MartinLau7 committed Dec 22, 2020
1 parent 21f7e0d commit b9ffb96
Show file tree
Hide file tree
Showing 71 changed files with 3,084 additions and 3,142 deletions.
111 changes: 60 additions & 51 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@ import PackageDescription

// MARK: - Common

private func ruleSets<Element>(_ items: [[Element]]) -> [Element] {
return items.flatMap { $0 }
}

private func always<Element>(use items: [Element]) -> [Element] {
return items
}

private func when<Element>(_ condition: Bool, use items: [Element]) -> [Element] {
if condition {
return items
} else {
return []
}
}

private enum OSPlatform: Equatable {
case darwin // macOS, iOS, tvOS, watchOS
case linux // ubuntu(16/18/20) / Amazon Linux 2
case windows // windows 10²
case windows // windows 10

#if os(macOS)
static let current = OSPlatform.darwin
Expand All @@ -35,12 +19,25 @@ private enum OSPlatform: Equatable {
#endif
}

private func ruleSets<Element>(_ items: [[Element]]) -> [Element] {
return items.flatMap { $0 }
}

private func releDeclaration<Element>(_ items: [Element], when platforms: [OSPlatform]) -> [Element] {
if !platforms.contains(OSPlatform.current) {
return []
}
return items
}


// MARK: - Package Config

let package = Package(
name: "LibzipSwift",
platforms: [
.macOS(.v10_13),
.iOS(.v13)
],
products: [
.library(name: "LibzipSwift", targets: ["LibzipSwift"]),
Expand All @@ -58,51 +55,63 @@ let package = Package(
dependencies: [],
path: "Sources/libzip",
exclude: ruleSets([
// always excluded items
always(use: [
// Exclude XZ compression
"src/zip_algorithm_xz.c",

// Exclude non-CommonCrypto encryption
[
// HAVE_MBEDTLS HAVE_GNUTLS
"src/zip_crypto_mbedtls.c",
"src/zip_crypto_gnutls.c",
],
releDeclaration([
// HAVE_WINDOWS_CRYPTO
"src/zip_crypto_win.c",

// Exclude Windows random
"src/zip_random_win32.c",
// WIN32
"src/zip_random_uwp.c",

// Exclude Windows utilities
"src/zip_source_win32handle.c",
"src/zip_source_win32utf8.c",
"src/zip_source_win32a.c",
"src/zip_source_win32w.c",
]),
when(OSPlatform.current == .darwin, use: [
"src/zip_crypto_openssl.c",
]),
when(OSPlatform.current == .linux, use: [
"src/zip_source_file_win32.c",
"src/zip_source_file_win32_named.c",
"src/zip_source_file_win32_utf16.c",
"src/zip_source_file_win32_utf8.c",
"src/zip_source_file_win32_ansi.c",
"src/zip_random_win32.c"
], when: [.linux, .darwin]),

releDeclaration([
// HAVE_COMMONCRYPTO
"src/zip_crypto_commoncrypto.c",
]),
], when: [.linux]),

releDeclaration([
// HAVE_OPENSSL
"src/zip_crypto_openssl.c",

// HAVE_LIBLZMA
// LZMA compression requires LZMA SDK
"src/zip_algorithm_xz.c",
], when: [.darwin]),
]),
sources: [
"src",
""
],
publicHeadersPath: "include",
cSettings: [
.define("HAVE_CONFIG_H"),
.headerSearchPath("private_include"),
],
linkerSettings: ruleSets([
always(use: [
.linkedLibrary("z"),
.linkedLibrary("bz2"),
]),
when(OSPlatform.current == .linux, use: [
.linkedLibrary("ssl"),
.linkedLibrary("crypto")
]),
])
cSettings: ruleSets([
[
.define("HAVE_CONFIG_H"),
],
releDeclaration([
.headerSearchPath("private_include/darwin"),
], when: [.darwin]),
releDeclaration([
.headerSearchPath("private_include/linux"),
], when: [.linux]),
]),
linkerSettings: [
.linkedLibrary("z"),
.linkedLibrary("bz2"),

.linkedLibrary("lzma", .when(platforms: [.linux])),
.linkedLibrary("ssl", .when(platforms: [.linux])),
.linkedLibrary("crypto", .when(platforms: [.linux])),
]
),
.target(
name: "LibzipSwift",
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ print("\(Handle errors here)")
### TODO

- [x] ~~完整的压缩函式~~
- [ ] 对iOS 支持的完善
- [x] 对iOS 支持的完善
- [ ] 对 unix 上的zip 归档保留更多属性
- [ ] 完善单元测试
- [ ] more
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ When you want to undo the changes, you can add discardChanged: false to the clos

- [x] ~~Complete compression function~~

- [ ] Improved iOS support
- [x] Improved iOS support

- [ ] Preserve more attributes for zip archives on unix

Expand Down
172 changes: 0 additions & 172 deletions Sources/libzip/include-patches/zip.h.patch

This file was deleted.

Loading

0 comments on commit b9ffb96

Please sign in to comment.