-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackage.swift
More file actions
195 lines (179 loc) · 7.69 KB
/
Copy pathPackage.swift
File metadata and controls
195 lines (179 loc) · 7.69 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// swift-tools-version: 6.3
import PackageDescription
let package = Package(
name: "BitcoinKernel",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.visionOS(.v2),
],
products: [
.library(name: "Bitcoin", targets: ["Bitcoin"]),
.library(name: "BitcoinKernel", targets: ["BitcoinKernel"]),
],
traits: [
.trait(name: "wallet")
],
dependencies: [
// Pinned to the pruned-umbrella-1.90.0 release commit. That tag name is not
// SemVer, so it cannot be used with `exact:`; a revision pin is reproducible
// and removes the (non-existent) branch reference.
.package(url: "https://github.com/21-DOT-DEV/swift-boost", revision: "6d8c72c0f41a20ec47b25096e4c422ef34f67579"),
.package(url: "https://github.com/21-DOT-DEV/swift-event", exact: "0.2.1"),
] + Package.Dependency.developmentDependencies,
targets: [
.target(
name: "Bitcoin",
dependencies: ["bitcoind"],
swiftSettings: SwiftSetting.bitcoinSettings
),
.target(
name: "BitcoinKernel",
dependencies: ["libbitcoinkernel"]
),
// MARK: - Bitcoin Core
.target(
name: "libbitcoinkernel",
dependencies: Target.Dependency.kernelDeps,
exclude: ["src/crypto/ctaes/ctaes.c"],
cxxSettings: CXXSetting.kernelSettings
),
.target(
name: "bitcoind",
dependencies: Target.Dependency.bitcoinDeps,
exclude: ["src/bridge/README.md"],
cxxSettings: CXXSetting.bitcoinSettings,
linkerSettings: [
.linkedLibrary("sqlite3")
]
),
// MARK: - Vendored C/C++ Libraries
.target(name: "crc32c"),
.target(
name: "leveldb",
cxxSettings: [
// See CXXSetting.shared: override the toolchain's Debug default of
// libc++ DEBUG hardening (O(n) container-invariant checks) with FAST.
.define("_LIBCPP_HARDENING_MODE", to: "_LIBCPP_HARDENING_MODE_FAST"),
.define("LEVELDB_PLATFORM_POSIX", to: "1"),
.define("LEVELDB_IS_BIG_ENDIAN", to: "0"),
// `port_config.h` defaults assume Apple (HAVE_FULLFSYNC=1, HAVE_FDATASYNC=0).
// The header guards each define with `#if !defined(...)`, so passing the
// correct flags for Linux from the build is enough — no source patch needed.
.define("HAVE_FDATASYNC", to: "1", .when(platforms: [.linux])),
.define("HAVE_FULLFSYNC", to: "0", .when(platforms: [.linux])),
.headerSearchPath("."),
]
),
.target(name: "minisketch"),
.target(
name: "secp256k1",
cSettings: [
.define("ECMULT_GEN_PREC_BITS", to: "4"),
.define("ECMULT_WINDOW_SIZE", to: "15"),
.define("ENABLE_MODULE_ELLSWIFT"),
.define("ENABLE_MODULE_EXTRAKEYS"),
.define("ENABLE_MODULE_RECOVERY"),
.define("ENABLE_MODULE_SCHNORRSIG"),
.define("ENABLE_MODULE_MUSIG"),
]
),
// MARK: - Tests
.testTarget(
name: "BitcoinTests",
dependencies: ["Bitcoin"],
resources: [.copy("Fixtures")],
swiftSettings: SwiftSetting.bitcoinSettings
),
.testTarget(
name: "BitcoinKernelTests",
dependencies: ["BitcoinKernel"]
),
],
// Matches the vendored secp256k1 C sources, which are written to C89.
// SwiftPM applies one C standard to every C target in the package.
cLanguageStandard: .c89,
cxxLanguageStandard: .cxx20
)
// MARK: - Extensions
extension Package.Dependency {
/// Development-only dependencies, excluded at tagged releases.
///
/// When resolved at a tagged release (`Context.gitInformation?.currentTag != nil`),
/// development tools (tuist, subtree, docc) are excluded so consumers aren't
/// forced to download them. Runtime dependencies (`swift-boost`, `swift-event`)
/// stay inline above and always resolve.
static var developmentDependencies: [Package.Dependency] {
guard Context.gitInformation?.currentTag == nil else { return [] }
return [
.package(url: "https://github.com/21-DOT-DEV/swift-plugin-tuist.git", exact: "4.195.11"),
.package(url: "https://github.com/21-DOT-DEV/swift-plugin-subtree.git", exact: "0.0.15"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.5.0"),
]
}
}
extension Target.Dependency {
/// Dependencies for the libbitcoinkernel target.
static let kernelDeps: [Self] = [
.product(name: "boost", package: "swift-boost"),
.target(name: "crc32c"),
.target(name: "leveldb"),
.target(name: "secp256k1"),
]
/// Dependencies for the bitcoind target.
static let bitcoinDeps: [Self] =
kernelDeps + [
.product(name: "libevent", package: "swift-event"),
.target(name: "minisketch"),
.target(name: "libbitcoinkernel"),
]
}
extension SwiftSetting {
/// Swift settings for the Bitcoin target.
///
/// - Note: Xcode does not resolve `.when(traits:)` conditions for Swift settings,
/// so Swift source files use `#if Xcode || ENABLE_WALLET` guards as a workaround.
/// Xcode automatically defines `Xcode` in all Swift compilations.
static let bitcoinSettings: [Self] = [
.interoperabilityMode(.Cxx),
.define("ENABLE_WALLET", .when(traits: ["wallet"])),
]
}
extension CXXSetting {
/// Shared C++ settings for all Bitcoin Core C++ targets.
static let shared: [Self] = [
// Override the toolchain's Debug default of
// `_LIBCPP_HARDENING_MODE_DEBUG`, which compiles in libc++'s O(n)
// container-invariant checks (`std::__tree_sub_invariant` on every
// map/set insert/erase). During IBD Core's maps reach ~130k+ entries,
// making those checks quadratic — one core pins at ~100%, validation
// stalls holding `cs_main`, and every RPC poll times out (-1001). FAST
// keeps the cheap O(1) checks (bounds, etc.) and drops the O(n) ones.
// A target-level `-D` is emitted after the toolchain default, so it wins.
.define("_LIBCPP_HARDENING_MODE", to: "_LIBCPP_HARDENING_MODE_FAST"),
.headerSearchPath("src"),
.headerSearchPath("src/univalue/include"),
// Disable `multi_index_container`'s serialization member templates
// — we never call them in the swift-bitcoinkernel subset, and skipping
// their declaration keeps us decoupled from the standalone Boost
// `serialization` module so it stays out of the dependency graph.
.define("BOOST_MULTI_INDEX_DISABLE_SERIALIZATION"),
]
/// C++ settings for the bitcoind target.
static let bitcoinSettings: [Self] =
shared + [
.headerSearchPath("../libbitcoinkernel/src"),
.headerSearchPath("../libbitcoinkernel/src/univalue/include"),
.define("MAIN_FUNCTION", to: "int bitcoind_main(int argc, char* argv[])"),
.define("G_TRANSLATION_FUN", to: "G_TRANSLATION_FUN_LOCAL"),
.define("ENABLE_WALLET", to: "1", .when(traits: ["wallet"])),
.define("HAVE_SYSTEM", to: "1", .when(platforms: [.linux])),
]
/// C++ settings for the libbitcoinkernel target.
static let kernelSettings: [Self] =
shared + [
.define("BITCOINKERNEL_BUILD", to: "1"),
.define("HAVE_SYSTEM", to: "1", .when(platforms: [.linux])),
]
}