This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Package.swift
127 lines (113 loc) · 3.92 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
// MARK: - Common
private enum OSPlatform: Equatable {
case darwin // macOS, iOS, tvOS, watchOS
case linux // ubuntu(16/18/20) / Amazon Linux 2
case windows // windows 10
#if os(macOS)
static let current = OSPlatform.darwin
#elseif os(Linux)
static let current = OSPlatform.linux
#else
#error("Unsupported platform.")
#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"]),
],
dependencies: ruleSets([
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0")
// when(OSPlatform.current == .linux, use: [
// .package(url: "https://github.com/IBM-Swift/OpenSSL.git", from: "2.2.2"),
// ]),
]),
targets: [
.target(
name: "libzip",
dependencies: [],
path: "Sources/libzip",
exclude: ruleSets([
[
// HAVE_MBEDTLS HAVE_GNUTLS
"src/zip_crypto_mbedtls.c",
"src/zip_crypto_gnutls.c",
],
releDeclaration([
// HAVE_WINDOWS_CRYPTO
"src/zip_crypto_win.c",
// WIN32
"src/zip_random_uwp.c",
"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: 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",
dependencies: ["libzip"],
path: "Sources/LibzipSwift"
),
.testTarget(
name: "LibzipSwiftTests",
dependencies: ["LibzipSwift"],
exclude: ["TestData"]
),
]
)