我有一个Package. swift
清单如下:
// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "long-package-name-ios",
defaultLocalization: "en",
platforms: [
.iOS(.v14),
.macOS(.v10_15)
],
products: [
.library(
name: "PackageName",
targets: ["PackageName"]),
.library(
name: "PackageNameImproved",
targets: ["PackageNameImproved"]),
.library(
name: "PackageNameUI",
targets: ["PackageNameUI"]),
],
dependencies: [
.package(
name: "PackageLib",
url: "ssh://apple.com/packagelib.git",
.upToNextMinor(from: "1.2.3")
)
],
targets: [
.target(
name: "PackageName",
dependencies: [
.product(name: "PackageLib", package: "PackageLib"),
],
path: "PackageName"),
.target(
name: "PackageName",
dependencies: [
"PackageName",
.product(name: "PackageLib", package: "PackageLib"),
],
path: "PackageNameImproved"),
.target(
name: "PackageNameUI",
dependencies: [
"PackageNameImproved",
],
path: "PackageNameUI")
]
)
包裹清单摘要:
PackageName
与macOS兼容,其他都是iOS的构建命令
为iOS构建long-package-name-ios-Package(构建包内的所有目标):
swift build-Xswiftc"-sdk"-Xswiftc"$(xcrun--sdk iphone模拟器--show-sdk-path)"-Xswiftc"-target"-Xswiftc"arm64-apple-ios15.0-模拟器"
[137/137]构建完成!
现在尝试只为macOS构建PackageName
:
swift build-Xswiftc"-sdk"-Xswiftc"$(xcrun--sdk macosx--show-sdk-path)"--产品"PackageName"
[1/1]规划构建警告:'--produc'不能与自动产品'PackageName'一起使用;改为构建默认目标
它继续为macOS平台构建默认目标long-pack-name-ios-Package
,该平台显然由于无法导入而失败,例如UIKit或任何其他仅iOS框架。
问题
如何指定只为macOS平台构建PackageName
?我对创建Xcode Package、Schemes和其他不同的配置持开放态度,但最终目标应该是:
long-package-name-ios-Package
(所有目标)PackageName
编辑:虽然我最初的答案使错误消失,但实际上无法将库导入插件。(它无法编译并出现“没有这样的模块”错误。)这似乎是预期的行为。
错误中的“自动产物”是指PackageName
没有配置的库类型。如果您配置其类型(动态
或静态
),错误就会消失,并且可以构建目标:
.library(
name: "PackageName",
type: .dynamic,
targets: ["PackageName"]
)