Repository navigation
Expand file tree
/
Copy pathPackage.swift
More file actions
86 lines (85 loc) · 4.15 KB
/
Copy pathPackage.swift
File metadata and controls
86 lines (85 loc) · 4.15 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
// swift-tools-version: 6.2
// Root-level Package.swift — alef-generated for published distributions.
//
// This manifest uses `.binaryTarget` for pre-built XCFramework/artifact bundles.
// External consumers depend on this via `.package(url: "...", from: "...")`.
//
// For in-tree development, see `packages/swift/Package.swift` and
// `packages/swift/README.md` for the source-based workflow.
import PackageDescription
let package = Package(
name: "Crawlberg",
platforms: [
.macOS(.v15),
.iOS(.v16),
],
products: [
.library(name: "Crawlberg", targets: ["Crawlberg"])
],
targets: [
// RustBridgeC: C headers target. Swift files in RustBridge import this to
// access C types (RustStr, etc.) produced by swift-bridge.
// publicHeadersPath: "." exposes the headers.
.target(
name: "RustBridgeC",
path: "packages/swift/Sources/RustBridgeC",
publicHeadersPath: "."
),
// RustBridgeBinary: pre-built static library for macOS (arm64, x86_64),
// iOS (device, simulator), and Linux (arm64, x86_64). The artifactbundle
// ships `.a` files only — SwiftPM binary targets cannot supply Swift
// modules, so the swift-bridge generated Swift sources live in the
// sibling RustBridge target below and link against this binary.
.binaryTarget(
name: "RustBridgeBinary",
url: "https://github.com/xberg-io/crawlberg/releases/download/v1.13.2/Crawlberg-rs.artifactbundle.zip",
checksum: "8c948b50463f59345d9402b8779aeaed24d4d8447cc4c1b04aa9ecefc1fbdb25"
),
// RustBridge: Swift wrapper module owning the swift-bridge generated
// sources. Depends on RustBridgeC for C type declarations and on
// RustBridgeBinary so the linker picks up the static library symbols.
.target(
name: "RustBridge",
dependencies: ["RustBridgeC", "RustBridgeBinary"],
path: "packages/swift/Sources/RustBridge",
// swift-bridge's generated async glue (`withCheckedThrowingContinuation` fed by a
// non-`@Sendable` callback) does not pass Swift 6 region-isolation checking: every
// `async fn` bridge function fails with "sending 'rustFnRetVal' risks causing data
// races". The generated code is not ours to edit, so this target stays in Swift 5
// language mode; the facade module keeps the manifest's default. ~keep
swiftSettings: [.swiftLanguageMode(.v5)],
// The pre-built static library inside RustBridgeBinary references Apple
// system frameworks (e.g. reqwest's proxy detection pulls in the Rust
// `system_configuration` crate → `SC*` symbols) and native system
// libraries (e.g. the archive/`xz2` path pulls in `lzma-sys` →
// `_lzma_stream_decoder`). The artifactbundle ships only the `.a`, so these
// must be linked by the consumer. `liblzma` ships in the macOS SDK and on
// Linux.
linkerSettings: [
.linkedLibrary("lzma"),
// Same reasoning as lzma: the bzip2 crates (archive/zip/unhwp) emit
// `-lbz2`, surfacing undefined `_BZ2_bzDecompress*`. `libbz2` ships in
// the macOS SDK and on Linux.
.linkedLibrary("bz2"),
// The pre-built static library pulls in C++ dependencies (onnxruntime,
// tesseract, ClipperLib) that reference the C++ runtime/ABI
// (`__cxa_throw`, `__gxx_personality_v0`, `__cxa_guard_acquire`, ...). A
// `.a` archive does not carry the transitive `-lc++`/`-lstdc++`
// system-lib dependency, so the consumer must link the C++ standard
// library explicitly or the final link fails with undefined symbols
// from those crates.
.linkedLibrary("c++", .when(platforms: [.macOS, .iOS])),
.linkedLibrary("stdc++", .when(platforms: [.linux])),
.linkedFramework("Security", .when(platforms: [.macOS, .iOS])),
.linkedFramework("CoreFoundation", .when(platforms: [.macOS, .iOS])),
.linkedFramework("OpenDirectory", .when(platforms: [.macOS])),
.linkedFramework("SystemConfiguration", .when(platforms: [.macOS])),
]
),
.target(
name: "Crawlberg",
dependencies: ["RustBridge", "RustBridgeC"],
path: "packages/swift/Sources/Crawlberg"
),
]
)