|
| 1 | +// swift-tools-version:5.10 |
| 2 | +/* |
| 3 | + This source file is part of the Swift.org open source project |
| 4 | + |
| 5 | + Copyright (c) 2021-2024 Apple Inc. and the Swift project authors |
| 6 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | + |
| 8 | + See https://swift.org/LICENSE.txt for license information |
| 9 | + See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 10 | +*/ |
| 11 | + |
| 12 | +import PackageDescription |
| 13 | + |
| 14 | +func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { |
| 15 | + guard let value = Context.environment[key] else { |
| 16 | + return defaultValue |
| 17 | + } |
| 18 | + if value == "1" { |
| 19 | + return true |
| 20 | + } else if value == "0" { |
| 21 | + return false |
| 22 | + } else { |
| 23 | + return defaultValue |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +let isSwiftCI = Context.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil |
| 28 | + |
| 29 | +let cmarkPackageName = isSwiftCI ? "cmark" : "swift-cmark" |
| 30 | + |
| 31 | +let markdownTarget = Target.target( |
| 32 | + name: "Markdown", |
| 33 | + dependencies: [ |
| 34 | + "CAtomic", |
| 35 | + .product(name: "cmark-gfm", package: cmarkPackageName), |
| 36 | + .product(name: "cmark-gfm-extensions", package: cmarkPackageName), |
| 37 | + ], |
| 38 | + exclude: [ |
| 39 | + "CMakeLists.txt" |
| 40 | + ] |
| 41 | +) |
| 42 | +let markdownTestTarget = Target.testTarget( |
| 43 | + name: "MarkdownTests", |
| 44 | + dependencies: ["Markdown"], |
| 45 | + resources: [.process("Visitors/Everything.md")] |
| 46 | +) |
| 47 | + |
| 48 | +let package = Package( |
| 49 | + name: "swift-markdown", |
| 50 | + products: [ |
| 51 | + .library( |
| 52 | + name: "Markdown", |
| 53 | + targets: ["Markdown"]), |
| 54 | + ], |
| 55 | + targets: [ |
| 56 | + .target(name: "CAtomic"), |
| 57 | + markdownTarget, |
| 58 | + markdownTestTarget, |
| 59 | + ] |
| 60 | +) |
| 61 | + |
| 62 | +// If the `SWIFTCI_USE_LOCAL_DEPS` environment variable is set, |
| 63 | +// we're building in the Swift.org CI system alongside other projects in the Swift toolchain and |
| 64 | +// we can depend on local versions of our dependencies instead of fetching them remotely. |
| 65 | +if !isSwiftCI { |
| 66 | + // Building standalone, so fetch all dependencies remotely. |
| 67 | + package.dependencies += [ |
| 68 | + .package(url: "https://github.com/apple/swift-cmark.git", branch: "gfm"), |
| 69 | + ] |
| 70 | + |
| 71 | + // SwiftPM command plugins are only supported by Swift version 5.6 and later. |
| 72 | + #if swift(>=5.6) |
| 73 | + package.dependencies += [ |
| 74 | + .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"), |
| 75 | + ] |
| 76 | + #endif |
| 77 | +} else { |
| 78 | + // Building in the Swift.org CI system, so rely on local versions of dependencies. |
| 79 | + package.dependencies += [ |
| 80 | + .package(path: "../cmark"), |
| 81 | + ] |
| 82 | +} |
| 83 | + |
| 84 | +// Enable swift-testing by default on CI environment |
| 85 | +let enableSwiftTesting = envEnable("SWIFT_MARKDOWN_SWIFT_TESTING_INTEGRATION", default: true) |
| 86 | + |
| 87 | +if enableSwiftTesting { |
| 88 | + package.dependencies += [ |
| 89 | + .package(url: "https://github.com/apple/swift-testing.git", exact: "0.6.0"), |
| 90 | + ] |
| 91 | + markdownTestTarget.dependencies.append( |
| 92 | + .product(name: "Testing", package: "swift-testing") |
| 93 | + ) |
| 94 | + var swiftSettings = markdownTestTarget.swiftSettings ?? [] |
| 95 | + swiftSettings.append(.define("SWIFT_MARKDOWN_SWIFT_TESTING_INTEGRATION")) |
| 96 | + markdownTestTarget.swiftSettings = swiftSettings |
| 97 | +} |
0 commit comments