Skip to content

Commit

Permalink
Add support for SwiftPM using SPMCLI
Browse files Browse the repository at this point in the history
SPMCLI is an option since to compile SwiftGit2 we need to perform amounts of linking and passing flags during compilation which in turns very cumbersome. The other way is to use helper like Make or other automation.

SPMCLI is choosen because it supports resolving configuration in dependencies. For now, ZipArchive. The user doesn't need to manually state each updated link and flags because SPMCLI will handle it.
  • Loading branch information
muizidn committed Jul 24, 2019
1 parent 9cb184d commit 15c318d
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SPMGenerated.xcodeproj
.vscode/
.build/

Expand Down
1 change: 1 addition & 0 deletions Clibgit2/_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Avoid warning in SwiftPM invocation.
2 changes: 2 additions & 0 deletions MacOS.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OTHER_LDFLAGS = $(inherited) ./External/libgit2.a ./External/libssl.a ./External/libcrypto.a /usr/lib/libcurl.dylib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libz.tbd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libiconv.tbd
OTHER_CFLAGS = $(inherited) -DHAVE_INTTYPES_H -DHAVE_PKCRYPT -DHAVE_STDINT_H -DHAVE_WZAES -DHAVE_ZLIB -DMZ_ZIP_NO_SIGNING -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -fapplication-extension -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code-aggressive -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -fstrict-aliasing -Wdeprecated-declarations -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wno-semicolon-before-method-body
34 changes: 34 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"object": {
"pins": [
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble",
"state": {
"branch": null,
"revision": "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
"version": "7.3.4"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick",
"state": {
"branch": null,
"revision": "f2b5a06440ea87eba1a167cab37bf6496646c52e",
"version": "1.3.4"
}
},
{
"package": "ZipArchive",
"repositoryURL": "https://github.com/muizidn/ZipArchive",
"state": {
"branch": "master",
"revision": "403986421556d945ce28b64bfc171e4ff9403a37",
"version": null
}
}
]
},
"version": 1
}
42 changes: 42 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SwiftGit2",
platforms: [
.macOS(.v10_11),
],
products: [
.executable(
name: "example",
targets: ["example"]),
.library(
name: "SwiftGit2",
targets: ["SwiftGit2"]),
],
dependencies: [
.package(url: "https://github.com/Quick/Quick", from: "1.3.2"),
.package(url: "https://github.com/Quick/Nimble", from: "7.3.1"),
.package(url: "https://github.com/muizidn/ZipArchive", .branch("master")),
],
targets: [
.target(
name: "example",
dependencies: ["SwiftGit2"],
path: "example"),
.target(
name: "SwiftGit2",
dependencies: ["Clibgit2"],
path: "SwiftGit2",
sources: ["Swift"]),
.target(
name: "Clibgit2",
path: "Clibgit2"),
.testTarget(
name: "SwiftGit2Tests",
dependencies: ["SwiftGit2", "Quick", "Nimble", "ZipArchive"],
path: "SwiftGit2Tests"),
]
)
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ If you want to build a copy of SwiftGit2 without Carthage, possibly for developm
2. Run `git submodule update --init --recursive` to clone the submodules
3. Build in Xcode

## Swift Package Manager
To incorporate SwiftGit2 to your project, you may want to use [SPMCLI](https://github.com/pondok-programmer/spmcli) to automate tedious tasks including linking and passing flags.

We encourage you to check [SPMCLI.resolved](SPMCLI.resolved) file.

To generate Xcodeproj using SPMCLI, you need to use it's `xcproj` branch. It will automate set up OTHER_CFLAGS and OTHER_LDFLAGS.

## Contributions
We :heart: to receive pull requests! GitHub makes it easy:

Expand Down
63 changes: 63 additions & 0 deletions SPMCLI.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
mac:
build:
-Xcc:
- -DHAVE_INTTYPES_H
- -DHAVE_PKCRYPT
- -DHAVE_STDINT_H
- -DHAVE_WZAES
- -DHAVE_ZLIB
- -DMZ_ZIP_NO_SIGNING
- -Wnon-modular-include-in-framework-module
- -Werror=non-modular-include-in-framework-module
- -fapplication-extension
- -Wno-trigraphs
- -fpascal-strings
- -O0
- -fno-common
- -Wno-missing-field-initializers
- -Wno-missing-prototypes
- -Werror=return-type
- -Wunreachable-code-aggressive
- -Werror=deprecated-objc-isa-usage
- -Werror=objc-root-class
- -Wno-missing-braces
- -Wparentheses
- -Wswitch
- -Wunused-function
- -Wno-unused-label
- -Wno-unused-parameter
- -Wunused-variable
- -Wunused-value
- -Wempty-body
- -Wuninitialized
- -Wconditional-uninitialized
- -Wno-unknown-pragmas
- -Wno-shadow
- -Wno-four-char-constants
- -Wno-conversion
- -Wconstant-conversion
- -Wint-conversion
- -Wbool-conversion
- -Wenum-conversion
- -Wno-float-conversion
- -Wnon-literal-null-conversion
- -Wobjc-literal-conversion
- -Wshorten-64-to-32
- -Wpointer-sign
- -Wno-newline-eof
- -fstrict-aliasing
- -Wdeprecated-declarations
- -g
- -Wno-sign-conversion
- -Winfinite-recursion
- -Wcomma
- -Wblock-capture-autoreleasing
- -Wstrict-prototypes
- -Wno-semicolon-before-method-body
-Xlinker:
- ./External/libgit2.a
- ./External/libssl.a
- ./External/libcrypto.a
- /usr/lib/libcurl.dylib
- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libz.tbd
- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libiconv.tbd
13 changes: 13 additions & 0 deletions SPMCLI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mac:
build:
-Xlinker:
- ${PWD}/External/libgit2.a
- ${PWD}/External/libssl.a
- ${PWD}/External/libcrypto.a
- /usr/lib/libcurl.dylib

xcconfig:
name: MacOS.xcconfig
keys:
OTHER_LDFLAGS: -Xlinker
OTHER_CFLAGS: -Xcc
1 change: 1 addition & 0 deletions example/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import SwiftGit2

0 comments on commit 15c318d

Please sign in to comment.