File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// swift-tools-version: 5.9
22import PackageDescription
3+ import Foundation
34
45let package = Package (
56 name: " MacLocalAPI " ,
Original file line number Diff line number Diff line change 1+ // BuildInfo.swift
2+ // Auto-generated build information - DO NOT EDIT MANUALLY
3+
4+ struct BuildInfo {
5+ static let version : String ? = " v0.5.0-dirty "
6+ }
Original file line number Diff line number Diff line change @@ -13,10 +13,15 @@ func handleShutdown(_ signal: Int32) {
1313}
1414
1515struct MacLocalAPI : ParsableCommand {
16+ static let buildVersion : String = {
17+ // Check if BuildVersion.swift exists with generated version
18+ return BuildInfo . version ?? " dev-build "
19+ } ( )
20+
1621 static let configuration = CommandConfiguration (
1722 commandName: " afm " ,
1823 abstract: " macOS server that exposes Apple's Foundation Models through OpenAI-compatible API " ,
19- version: " 1.0.0 "
24+ version: buildVersion
2025 )
2126
2227 @Option ( name: . shortAndLong, help: " Port to run the server on " )
@@ -58,7 +63,7 @@ struct MacLocalAPI: ParsableCommand {
5863 globalServer = server
5964 try await server. start ( )
6065 } catch {
61- print ( " Error starting server: \( error) " )
66+ print ( " Error starting server. CTRL-C to stop : \( error) " )
6267 shouldKeepRunning = false
6368 }
6469 }
Original file line number Diff line number Diff line change @@ -74,6 +74,32 @@ echo ""
7474# Validate Swift version before building
7575validate_swift_version
7676
77+ # Generate version from git
78+ get_version () {
79+ # Try git describe first (handles both exact tags and tags with distance)
80+ if git describe --tags --always --dirty 2> /dev/null; then
81+ return
82+ else
83+ # Fallback if no tags exist
84+ echo " 0.0.0-$( git rev-parse --short HEAD) -$( date +%Y%m%d) "
85+ fi
86+ }
87+
88+ BUILD_VERSION=$( get_version | tr -d ' \n' )
89+ echo -e " ${BLUE} 📋 Build version: $BUILD_VERSION ${NC} "
90+ echo " "
91+
92+ # Generate BuildInfo.swift with version
93+ echo -e " ${BLUE} 📝 Generating version file...${NC} "
94+ cat > Sources/MacLocalAPI/BuildInfo.swift << EOF
95+ // BuildInfo.swift
96+ // Auto-generated build information - DO NOT EDIT MANUALLY
97+
98+ struct BuildInfo {
99+ static let version: String? = "$BUILD_VERSION "
100+ }
101+ EOF
102+
77103# Clean previous builds
78104echo -e " ${BLUE} 🧹 Cleaning previous builds...${NC} "
79105swift package clean
Original file line number Diff line number Diff line change @@ -55,7 +55,24 @@ validate_swift_version() {
5555 echo " "
5656}
5757
58- VERSION=${1:- " 0.2.0" }
58+ # Generate version from git
59+ get_version () {
60+ # Try git describe first (handles both exact tags and tags with distance)
61+ if git describe --tags --always --dirty 2> /dev/null; then
62+ return
63+ else
64+ # Fallback if no tags exist
65+ echo " 0.0.0-$( git rev-parse --short HEAD) -$( date +%Y%m%d) "
66+ fi
67+ }
68+
69+ # Use provided version or auto-generate from git
70+ if [ -n " $1 " ]; then
71+ VERSION=" $1 "
72+ else
73+ VERSION=$( get_version | tr -d ' \n' )
74+ fi
75+
5976ARCH=" arm64"
6077
6178echo " Building afm (Apple Foundation Models API) v$VERSION for $ARCH ..."
@@ -65,7 +82,18 @@ validate_swift_version
6582
6683# Clean previous builds
6784rm -rf release-v$VERSION
68- rm -f maclocal-api-v$VERSION -$ARCH .tar.gz
85+ rm -f afm-v$VERSION -$ARCH .tar.gz
86+
87+ # Generate BuildInfo.swift with version
88+ echo " Generating version file..."
89+ cat > Sources/MacLocalAPI/BuildInfo.swift << EOF
90+ // BuildInfo.swift
91+ // Auto-generated build information - DO NOT EDIT MANUALLY
92+
93+ struct BuildInfo {
94+ static let version: String? = "$VERSION "
95+ }
96+ EOF
6997
7098# Build release binary
7199echo " Building release binary..."
You can’t perform that action at this time.
0 commit comments