Skip to content

Commit 3c783a7

Browse files
committed
Further work on the plugins/artifact bundles
1 parent 3f166c0 commit 3c783a7

File tree

6 files changed

+92
-25
lines changed

6 files changed

+92
-25
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,16 @@ jobs:
139139
VERSION=${VERSION#v} # Remove 'v' prefix if present
140140
echo "Creating artifact bundle for version $VERSION"
141141
142-
# Make script executable and run
142+
# Make scripts executable and run
143143
chmod +x Scripts/spm-artifact-bundle.sh
144+
chmod +x Scripts/update-artifact-bundle.sh
144145
./Scripts/spm-artifact-bundle.sh "$VERSION"
145146
146-
# Update Package.swift with actual checksum and version
147-
CHECKSUM=$(cat swift-dependency-audit.artifactbundle.zip.checksum)
148-
sed -i "s/PLACEHOLDER_CHECKSUM_WILL_BE_UPDATED_ON_RELEASE/$CHECKSUM/" Package.swift
149-
sed -i "s/v1.0.0/v$VERSION/" Package.swift
147+
# Activate production Package.swift for releases
148+
cp Package-production.swift Package.swift
150149
151-
# Verify the changes
152-
echo "Updated Package.swift with:"
153-
echo "Version: v$VERSION"
154-
echo "Checksum: $CHECKSUM"
150+
# Update Package.swift with actual checksum and version
151+
./Scripts/update-artifact-bundle.sh "v$VERSION"
155152
156153
- name: Create traditional release archives
157154
run: |

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Docker-based cross-compilation for Linux platforms
1717
- SHA256 checksum verification for binary integrity
1818
- Artifact bundle generation script for automated distribution
19-
- Binary-only build tool plugin execution (required for Swift Package Manager plugins)
19+
- Hybrid binary/source build tool plugin execution following SwiftLint's proven pattern
2020

2121
- **Swift Build Tool Plugin Integration**
2222
- Automatic dependency validation during builds with Swift Package Manager build tool plugin
@@ -98,16 +98,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9898
- Added `Scripts/spm-artifact-bundle.sh` for automated artifact bundle generation
9999
- Created `Scripts/spm-artifact-bundle-info.template` for Swift Package Manager manifest generation
100100
- Implemented GitHub Actions workflow with matrix strategy for cross-platform builds
101-
- Docker-based Linux compilation using `swift:5.10` image with platform-specific builds
101+
- Docker-based Linux compilation using `swift:6.1` image with platform-specific builds
102102
- Binary optimization with `strip` for size reduction and `-Xswiftc -Osize` for performance
103103
- Artifact bundle structure following SPM schema version 1.0 with multi-platform variants
104104
- Automated checksum calculation with SHA256 for security verification
105-
- Binary-only distribution model required for Swift Package Manager build tool plugins
105+
- Hybrid distribution model with conditional binary targets for optimal platform support
106+
- Dedicated `Scripts/update-artifact-bundle.sh` script for automated Package.swift checksum updates
107+
- Conditional compilation patterns following Swift Package Manager best practices
106108

107109
- **Swift Build Tool Plugin Architecture**
108110
- Added `DependencyAuditPlugin` conforming to `BuildToolPlugin` protocol with `@main` annotation
109111
- Implemented `createBuildCommands(context:target:)` method for prebuild command generation
110-
- Binary-only execution using `context.tool(named:)` with artifact bundle dependencies
112+
- Hybrid execution using `context.tool(named:)` with conditional platform dependencies
111113
- Uses modern PackagePlugin API with `pluginWorkDirectoryURL` and `directoryURL` properties
112114
- Target filtering with `SourceModuleTarget` type checking to reduce overhead
113115
- Proper test target detection using `sourceTarget.kind != .test` instead of string matching

Package.swift

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
// swift-tools-version: 6.1
22
import PackageDescription
33

4+
// Conditional plugin dependencies based on platform
5+
// Note: Using source target for development until binary target is available
6+
let swiftDependencyAuditPluginDependencies: [Target.Dependency] = [.target(name: "SwiftDependencyAudit")]
7+
8+
// For production with binary target, use this instead:
9+
/*
10+
#if os(macOS)
11+
swiftDependencyAuditPluginDependencies = [.target(name: "SwiftDependencyAuditBinary")]
12+
#else
13+
swiftDependencyAuditPluginDependencies = [.target(name: "SwiftDependencyAudit")]
14+
#endif
15+
*/
16+
417
let package = Package(
518
name: "SwiftDependencyAudit",
619
platforms: [
@@ -35,12 +48,21 @@ let package = Package(
3548
.plugin(
3649
name: "DependencyAuditPlugin",
3750
capability: .buildTool(),
38-
dependencies: ["SwiftDependencyAuditBinary"]
39-
),
40-
.binaryTarget(
41-
name: "SwiftDependencyAuditBinary",
42-
url: "https://github.com/tonyarnold/swift-dependency-audit/releases/download/v1.0.0/swift-dependency-audit.artifactbundle.zip",
43-
checksum: "PLACEHOLDER_CHECKSUM_WILL_BE_UPDATED_ON_RELEASE"
51+
dependencies: swiftDependencyAuditPluginDependencies
4452
),
4553
]
4654
)
55+
56+
// Conditionally add binary target only on macOS
57+
// Note: Commented out for development until first release with binary target is created
58+
/*
59+
#if os(macOS)
60+
package.targets.append(
61+
.binaryTarget(
62+
name: "SwiftDependencyAuditBinary",
63+
url: "https://github.com/tonyarnold/swift-dependency-audit/releases/download/v0.1.0-test/swift-dependency-audit.artifactbundle.zip",
64+
checksum: "b7bf85dc914055edac980164ba7424c4d7b6f174ef5b85a95d4d3ba543ca04f6"
65+
)
66+
)
67+
#endif
68+
*/

Plugins/DependencyAuditPlugin/DependencyAuditPlugin.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct DependencyAuditPlugin: BuildToolPlugin {
1212
return []
1313
}
1414

15-
// Get the binary tool from the artifact bundle
1615
let tool = try context.tool(named: "swift-dependency-audit")
1716

1817
// Create output directory for plugin results

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SwiftDependencyAudit includes a Swift Package Manager build tool plugin that aut
9696

9797
### Plugin Integration
9898

99-
The build tool plugin uses pre-compiled binary targets for optimal performance across multiple platforms:
99+
The build tool plugin uses a hybrid approach for optimal performance and compatibility:
100100

101101
```swift
102102
// Package.swift
@@ -124,17 +124,28 @@ let package = Package(
124124
)
125125
```
126126

127-
**Note**: Build tool plugins require binary targets and cannot use source compilation. The plugin automatically uses the appropriate pre-compiled binary for your platform.
127+
### Hybrid Binary/Source Approach
128+
129+
Following the proven pattern from SwiftLint, SwiftDependencyAudit uses:
130+
131+
- **macOS**: Pre-compiled binary targets for optimal performance
132+
- **Other Platforms**: Source compilation for maximum compatibility
133+
134+
This approach provides:
135+
136+
- **Performance**: Binary targets eliminate compilation time on macOS
137+
- **Compatibility**: Source compilation works on all Swift-supported platforms
138+
- **Development**: Easy debugging and contribution with source access
139+
- **Production**: Optimized performance where it matters most
128140

129141
### Binary Target Distribution
130142

131-
SwiftDependencyAudit provides pre-compiled binary targets for multiple platforms:
143+
SwiftDependencyAudit provides pre-compiled binary targets for:
132144

133145
- **macOS**: Universal binary supporting both ARM64 (Apple Silicon) and x86_64 (Intel)
134-
- **Linux**: x86_64 and ARM64 architectures
135146
- **Cross-platform**: Artifact bundles compatible with Swift Package Manager
136147

137-
Binary targets provide significant performance improvements over source compilation, especially in CI/CD environments and large projects.
148+
Binary targets provide significant performance improvements over source compilation, especially in CI/CD environments and large projects, while maintaining full compatibility across all platforms.
138149

139150
### Plugin Features
140151

Scripts/update-artifact-bundle.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
readonly version="$1"
6+
readonly artifactbundle="swift-dependency-audit.artifactbundle.zip"
7+
8+
# Check if artifact bundle exists
9+
if [[ ! -f "$artifactbundle" ]]; then
10+
echo "Error: Artifact bundle '$artifactbundle' not found"
11+
exit 1
12+
fi
13+
14+
# Calculate checksum
15+
readonly checksum="$(shasum -a 256 "$artifactbundle" | cut -d " " -f1 | xargs)"
16+
17+
echo "Updating Package.swift with:"
18+
echo " Version: $version"
19+
echo " Checksum: $checksum"
20+
21+
# Update the download URL for the specific version
22+
sed -i '' \
23+
"s|.*github\.com/tonyarnold/swift-dependency-audit/releases/download/.*/swift-dependency-audit\.artifactbundle\.zip.*| url: \"https://github.com/tonyarnold/swift-dependency-audit/releases/download/$version/swift-dependency-audit.artifactbundle.zip\",|g" \
24+
Package.swift
25+
26+
# Update the checksum
27+
sed -i '' \
28+
"s/.*checksum.*/ checksum: \"$checksum\"/g" \
29+
Package.swift
30+
31+
echo "✅ Package.swift updated successfully"
32+
33+
# Verify the changes
34+
echo ""
35+
echo "Updated binary target configuration:"
36+
grep -A 3 -B 1 "SwiftDependencyAuditBinary" Package.swift | tail -5

0 commit comments

Comments
 (0)