Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ build-*
cmakebuild/
cmake-build/

# Swift build artefacts
.build/
.swiftpm/xcode/

# Test artefacts
tmp*
*.zst
Expand Down
67 changes: 52 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
// swift-tools-version:5.0
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "zstd",
platforms: [
.macOS(.v10_10), .iOS(.v9), .tvOS(.v9)
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "libzstd",
targets: [ "libzstd" ])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
// Two library products. Each surfaces only one Swift module to its consumers:
//
// • `Zstd` — modern API (renamed functions, prefix-stripped enum cases).
// • `libzstd` — legacy API (raw `ZSTD_*` names) for source-level backwards
// compatibility with code that predates the rename.
//
// A consumer that depends on the `Zstd` product can NOT `import libzstd`
// (and vice versa), because each product is backed by a separate facade
// target whose modulemap declares only one of the two modules.
.library(name: "Zstd", targets: [ "Zstd" ]),
.library(name: "libzstd", targets: [ "libzstd" ]),
.executable(name: "zstd-example", targets: [ "zstd-example" ]),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
// ── The actual C library ────────────────────────────────────────────
// Compiles the real zstd sources once and exposes the raw headers via
// a "private" `_ZstdCore` module that nobody is expected to import.
// Both facade targets below depend on this one for the C symbols.
.target(
name: "libzstd",
name: "_ZstdCore",
path: "lib",
sources: [ "common", "compress", "decompress", "dictBuilder" ],
publicHeadersPath: ".",
cSettings: [
.headerSearchPath(".")
])
.headerSearchPath("."),
]),

// ── Modern Swift facade ─────────────────────────────────────────────
// Owns the `Zstd_module.h` umbrella (which defines
// `ZSTD_FOR_SWIFT_MODERN_API` before including the real headers) and
// its accompanying `Zstd.apinotes`. The umbrella + apinotes pair is the
// only thing that turns "raw zstd headers" into the modern Swift API.
.target(
name: "Zstd",
dependencies: [ "_ZstdCore" ],
path: "Sources/Zstd",
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("../../lib"), // so the umbrella can find zstd.h
]),

// ── Legacy Swift facade ─────────────────────────────────────────────
// Same headers as `Zstd`, but with an umbrella that doesn't define the
// modern-API macro and no apinotes file, so the raw C names come through.
.target(
name: "libzstd",
dependencies: [ "_ZstdCore" ],
path: "Sources/libzstd",
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("../../lib"),
]),

.executableTarget(
name: "zstd-example",
dependencies: [ "Zstd" ],
path: "Sources/zstd-example"),
],
swiftLanguageVersions: [.v5],
cLanguageStandard: .gnu11,
Expand Down
1 change: 1 addition & 0 deletions Sources/Zstd/_empty.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// SwiftPM requires at least one source file per C target.
Loading