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
63 changes: 44 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
// swift-tools-version:5.7

import Foundation
import PackageDescription

let environment = ProcessInfo.processInfo.environment
let slim = environment["SWIFT_BUNDLER_SLIM"] == "1"
let requireBuilderAPI = environment["SWIFT_BUNDLER_REQUIRE_BUILDER_API"] == "1"

let package = Package(
name: "swift-bundler",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .macCatalyst(.v13)],
products: [
products: [],
dependencies: [],
targets: []
)

// Builder API
if !slim || requireBuilderAPI {
package.products += [
.library(name: "SwiftBundlerBuilders", targets: ["SwiftBundlerBuilders"])
]

package.dependencies += [
.package(url: "https://github.com/gregcotten/AsyncProcess", from: "0.0.5")
]

package.targets += [
.target(
name: "SwiftBundlerBuilders",
dependencies: [
.product(
name: "ProcessSpawnSync",
package: "AsyncProcess",
condition: .when(platforms: [.linux])
)
]
)
]
}

// Rest of products/targets/dependencies
if !slim {
package.products += [
.executable(name: "swift-bundler", targets: ["swift-bundler"]),
.library(name: "SwiftBundler", targets: ["SwiftBundler"]),
.library(name: "SwiftBundlerRuntime", targets: ["SwiftBundlerRuntime"]),
.library(name: "SwiftBundlerBuilders", targets: ["SwiftBundlerBuilders"]),
.plugin(name: "SwiftBundlerCommandPlugin", targets: ["SwiftBundlerCommandPlugin"]),
],
dependencies: [
]

package.dependencies += [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-log", from: "1.5.4"),
.package(url: "https://github.com/pointfreeco/swift-parsing", .upToNextMinor(from: "0.13.0")),
Expand All @@ -32,14 +68,14 @@ let package = Package(
.package(url: "https://github.com/apple/swift-crypto", from: "3.10.0"),
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1"),
.package(url: "https://github.com/adam-fowler/async-collections.git", from: "0.1.0"),
.package(url: "https://github.com/gregcotten/AsyncProcess", from: "0.0.5"),

// File watcher dependencies
.package(url: "https://github.com/sersoft-gmbh/swift-inotify", "0.4.0"..<"0.5.0"),
.package(url: "https://github.com/apple/swift-system", from: "1.2.0"),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.3"),
],
targets: [
]

package.targets += [
.executableTarget(name: "swift-bundler", dependencies: ["SwiftBundler"]),
.target(
name: "SwiftBundler",
Expand Down Expand Up @@ -125,17 +161,6 @@ let package = Package(
]
),

.target(
name: "SwiftBundlerBuilders",
dependencies: [
.product(
name: "ProcessSpawnSync",
package: "AsyncProcess",
condition: .when(platforms: [.linux])
)
]
),

.target(
name: "HotReloadingProtocol",
dependencies: [
Expand Down Expand Up @@ -186,4 +211,4 @@ let package = Package(
]
),
]
)
}
14 changes: 13 additions & 1 deletion Sources/SwiftBundler/Bundler/ProjectBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,21 @@ enum ProjectBuilder {
isGUIExecutable: false
)

// Let Swift Bundler know that we only need the builder API. This
// greatly reduces the length of the dependency resolution phase for
// clean builds (which is the bottleneck for single-file builders),
// and greatly improves incremental build performance on Windows where
// package trees with lots of files seem to result in pretty terrible
// incremental build performance.
let environment = [
"SWIFT_BUNDLER_SLIM": "1",
"SWIFT_BUNDLER_REQUIRE_BUILDER_API": "1",
]

return await SwiftPackageManager.build(
product: builderProductName,
buildContext: buildContext
buildContext: buildContext,
additionalEnvironmentVariables: environment
).andThen { _ in
await SwiftPackageManager.getProductsDirectory(buildContext)
}.mapError { error in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ enum SwiftPackageManager {
/// - Parameters:
/// - product: The product to build.
/// - buildContext: The context to build in.
/// - additionalEnvironmentVariables to add to SwiftPM CLI invocations.
/// - Returns: If an error occurs, returns a failure.
static func build(
product: String,
buildContext: BuildContext
buildContext: BuildContext,
additionalEnvironmentVariables: [String: String] = [:]
) async -> Result<Void, SwiftPackageManagerError> {
return await createBuildArguments(
product: product,
Expand All @@ -91,6 +93,7 @@ enum SwiftPackageManager {
let process = Process.create(
"swift",
arguments: arguments,
environment: additionalEnvironmentVariables,
directory: buildContext.genericContext.projectDirectory,
runSilentlyWhenNotVerbose: false
)
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftBundler/Commands/BundleCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
self.hotReloadingEnabled = hotReloadingEnabled
}

static func validateArguments(

Check warning on line 67 in Sources/SwiftBundler/Commands/BundleCommand.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 13 (cyclomatic_complexity)

Check warning on line 67 in Sources/SwiftBundler/Commands/BundleCommand.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 13 (cyclomatic_complexity)
_ arguments: BundleArguments,
platform: Platform,
skipBuild: Bool,
Expand Down Expand Up @@ -170,7 +170,7 @@
return true
}

static func resolveCodesigningContext(

Check warning on line 173 in Sources/SwiftBundler/Commands/BundleCommand.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)

Check warning on line 173 in Sources/SwiftBundler/Commands/BundleCommand.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
codesignArgument: Bool?,
identityArgument: String?,
provisioningProfile: URL?,
Expand Down Expand Up @@ -607,11 +607,13 @@
}

let dependenciesScratchDirectory = outputDirectory / "projects"
var dependencyContext = buildContext.genericContext
dependencyContext.scratchDirectory = dependenciesScratchDirectory

let dependencies = try await ProjectBuilder.buildDependencies(
appConfiguration.dependencies,
packageConfiguration: configuration,
context: buildContext.genericContext,
context: dependencyContext,
appName: appName,
dryRun: skipBuild
).unwrap()
Expand Down
Loading