SPM
SPM Usage
仿照教學,建立 system lib(libgit2),並且在另一個專案引用 libgit2
產生 swift proj1
| swift package init --type executable
|
產生 XCode 專案1 2 3 4 5
| swift package \ -Xcc -std=c89 \ -Xswiftc -I/usr/local/include/git2 \ -Xlinker -L/usr/local/lib \ generate-xcodeproj
|
tree1 2 3 4 5 6 7
| ├── Package.swift ├── Sources │ └── Hello.swift └── Tests ├── HelloTests │ └── HelloTests.swift └── LinuxMain.swift
|
Require System Libraries (libgit2)
首先要先安裝 libgit2
,可自行選擇手動安裝或利用 brew
手動安裝
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
mkdir build && cd build
cmake .. \ -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" \ -DLIB_INSTALL_DIR=/usr/local/lib \ -DINCLUDE_INSTALL_DIR=/usr/local/include cmake --build . --target install
rm /usr/local/lib/libgit2.0.25.1.dylib rm /usr/local/lib/libgit2.25.dylib rm /usr/local/lib/libgit2.dylib rm /usr/local/lib/pkgconfig/libgit2.pc rm /usr/local/include/git2.h rm -rf /usr/local/include/git2
|
套件軟體安裝
建立 System Lib (Clibgit)
swift package init --type system-module
Package.swift1 2 3 4 5 6
| import PackageDescription
let package = Package( name: "Clibgit", pkgConfig: "libgit2" )
|
module.modulemap1 2 3 4 5
| module Clibgit [system] { header "/usr/local/include/git2.h" link "git2" export * }
|
tag 版本(Clibgit)1 2 3 4
| git init git add . git commit -m "Initial Commit" git tag 1.0.0
|
開始引用 System Lib
swift package init --type executable
Package.swift1 2 3 4 5 6 7 8
| import PackageDescription
let package = Package( name: "example", dependencies: [ .Package(url: "../Clibgit", majorVersion: 1) ] )
|
main.swift1 2 3 4
| import Clibgit
let options = git_repository_init_options() print(options)
|
執行
swift build -Xlinker -L/usr/local/lib/ && .build/debug/example
產生 XCode 專案
swift package -Xcc -std=c89 -Xswiftc -I/usr/local/include/git2 -Xlinker -L/usr/local/lib generate-xcodeproj
REPL include Clibgit
swift -I Clibgit
PackageDescription
Package1 2 3 4 5 6 7 8
| Package( name: String, pkgConfig: String? = nil, providers: [SystemPackageProvider]? = nil, targets: [Target] = [], dependencies: [Package.Dependency] = [], exclude: [String] = [] )
|
Target1
| Target(name: "Bar", dependencies: ["Foo"])
|
Package.Dependency1 2 3
| .Package(url: "ssh://git@example.com/Greeter.git", versions: Version(1,0,0)..<Version(2,0,0)), .Package(url: "../StringExtensions", "1.0.0"), .Package(url: "https://github.com/MyAwesomePackage", majorVersion: 1, minor: 4),
|
exclude1
| exclude: ["Sources/Fixtures", "Sources/readme.md", "Tests/FooTests/images"]
|
Provider1 2 3 4
| providers: [ .Brew("gtk+3"), .Apt("gtk3") ]
|
待 …