Swift Package Manager

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Konstantin
November 19, 2016

Swift Package Manager

Let’s make dependency manager great, Finally!

Konstantin

November 19, 2016

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

49 slides
  1. Kostiantyn Koval @Agens AS • Swift from day 1 •

    Swift Hight Performance • Swift Package Manager • @KostiaKoval
  2. How it used to be ! ... • Static libraries

    lib.a • Copied source • Subproject + Workspace • Submodules
  3. The problems ! • Closed code / Precompiled • Hard

    to discover • No versioning • Duplicate Symbols a->c, b->c App ->(a, b) Duplicate 'c'
  4. CocoaPods - Easy • Centralized • Podspec • Static Libs

    + Frameworks • Modifies Xcode projects + workspace Res: Workspace
  5. Carthage - Simple • Decentralized • No Podspec • Git

    + Xcode • Frameworks Res: Frameworks
  6. Problems • Not integrated with ! • Xcode private API

    and Format • Custom scripts • Limited
  7. SwiftPM Cross platform, Convention approach, Decentralized is a tool to

    automate the process of downloading, compiling, and linking dependencies. — Swift .org
  8. "swift package" clean Delete build artifacts describe Describe the current

    package dump-package Print parsed Package.swift as JSON fetch Fetch package dependencies generate-xcodeproj Generates an Xcode project init Initialize a new package reset Reset the complete cache/build directory show-dependencies Print the resolved dependency graph update Update package dependencies
  9. What is a Swift Package ? • Swift, C, C++,

    Objective-C, Objective-C++ One language per module • library (static, dynamic), executable, system-module
  10. Package Convention Source in - /Sources Tests in - /Tests

    Executable - main.swift Lib - SomeLib.swift C headers - /include/Baz.h
  11. Package //executable lib with tests . . ├── Package.swift ├──

    Package.swift ├── Sources ├── Sources └── main.swift │ └── Lib.swift └── Tests ├── LibTests │ └── LibTests.swift └── LinuxMain.swift
  12. Package // 2 Modules system-module . . ├── Package.swift ├──

    Package.swift └── Sources └── module.modulemap ├── A │ └── A.swift └── B └── someCode.swift
  13. Package + Git = ! let package = Package( name:

    "Empty" dependencies: [ .Package(url: "https://github.com/MyAwesomePackage", majorVersion: 0), ] ) semver, semver, semver -> Semver.org
  14. Package Dependency let package = Package( name: "Empty" dependencies: [

    .Package(url: "https://github.com/MyAwesomePackage", majorVersion: 0), .Package(url: "https://github.com/MyAwesomePackage", majorVersion: 1, minor: 4), .Package(url: "ssh://[email protected]/Greeter.git", versions: Version(1,0,0)..<Version(2,0,0)), .Package(url: "../StringExtensions", "1.0.0-alpha+001"), .Package(url: "../Package", version: Version(0, 1, 0), .Package(url: "../AwesomePackage", version: Version(0, 1, 0, prereleaseIdentifiers: ["alpha"], buildMetadataIdentifier: "001"), ] )
  15. Package Power Package( name: String, dependencies: [Package.Dependency] = [], targets:

    [Target] = [], exclude: [String] = [] pkgConfig: String? = nil, providers: [SystemPackageProvider]? = nil, )
  16. Package Targets 3 Targets: Core, Network, Login . ├── Package.swift

    └── Sources ├── Core │ └── core.swift ├── Login │ └── loginAPI.swift └── Network └── coreNetwork.swift
  17. Package Targets 3 Targets: Core, Network, Login let package =

    Package( name: "App", targets: [ Target(name: "Login", dependencies: ["Core", "Network"]), ] )
  18. Package exclude let package = Package( name: "Lib", exclude: ["Sources/mocJSON",

    "Sources/LibAReadme.md", "Tests/FooTests/images"] )
  19. Package pkg-config // module.modulemap module Clibgit [system] { header "/usr/local/include/git2.h"

    link "git2" export * } swift build -Xcc -I.. -Xlinker -L/usr/local/lib/
  20. Package Providers let package = Package( name: "Clibgit", pkgConfig: "libgit2",

    providers: [ .Brew("libgit2"), .Apt("libgit2") ] )
  21. Coming Soon ... Product Definitions let package = Package( name:

    "MyServer", ... products: [ .Library(name: "ClientLib", type: .static, targets: ["ClientAPI"]), .Library(name: "ServerLib", type: .dynamic, targets: ["ServerAPI"]), .Executable(name: "myserver", targets: ["ServerDaemon"]), ] ) "Package Manager Product Definitions"
  22. Xcode Integration swift package generate-xcodeproj . ├── Package.swift └── Sources

    ├── A │ └── A.swift └── B └── Code.swift
  23. Xcode Integration swift package generate-xcodeproj --xcconfig-overrides Config.xcconfig . ├── Package.swift

    └── Sources ├── A │ └── A.swift └── B └── Code.swift
  24. SwiftPM • 19 Modules • 31 Targets • 13 Test

    Modules • A lot of Code an Tests
  25. Does the SwiftPM solves the issue? YES!, kind off, it

    will. ! • Painless config • Right Xcode project integration • Full Build & Tests control • Open Source • Many, many more ...

More Decks by Konstantin

Other Decks in Programming