Upgrade to Pro — share decks privately, control downloads, hide ads and more …

わいわいSwift Package Manager

giginet
September 12, 2018

わいわいSwift Package Manager

giginet

September 12, 2018
Tweet

More Decks by giginet

Other Decks in Programming

Transcript

  1. Motivation • App Store Connect APIΫϥΠΞϯτΛSwiftͰ࡞ͬͯͨ • ৄࡉ͸iOSDC Reject Conference

    Day1Ͱʂʂʂ • JSON Web TokenͷॲཧʹCͷϥΠϒϥϦΛ࢖͍͔ͨͬͨ
  2. shim.h #ifndef OpenSSLHelper_h #define OpenSSLHelper_h #include <openssl/conf.h> #include <openssl/evp.h> #include

    <openssl/err.h> #include <openssl/bio.h> #include <openssl/ssl.h> #include <openssl/md4.h> #include <openssl/md5.h> #include <openssl/sha.h> #include <openssl/hmac.h> #include <openssl/rand.h> #include <openssl/pkcs12.h> #include <openssl/x509v3.h> // (ry
  3. Package.swift import PackageDescription let package = Package( name: "OpenSSL", providers:

    [ .apt(["openssl libssl-dev"]), .brew(["openssl"]), ], products: [ .library( name: "OpenSSL", targets: ["OpenSSL"] ) ], targets: [ .target(name: "OpenSSL") ] )
  4. How to use • .packageͰଞͷύοέʔδͱಉ͡Α͏ʹ૊ΈࠐΊΔ • Swift͔Β؆୯ʹCͷAPIୟ͚Δ import PackageDescription let

    package = Package( name: "Wormhole", products: [ .library( name: "Wormhole", targets: ["Wormhole"]), ], dependencies: [ .package(url: "https://github.com/giginet/libjwt-swift.git", from: "1.0.0"), ], targets: [ .target( name: "Wormhole", dependencies: ["Result", "JWT"]), ] )
  5. ! import Foundation import JWT struct JWTEncoder { func encode(issuerID:

    UUID, keyID: String) throws -> String { let object = UnsafeMutablePointer<OpaquePointer?>.allocate(capacity: MemoryLayout<OpaquePointer>.size) jwt_new(object) defer { jwt_free(object.pointee) } let keyPointer = convertToCString(privateKey) defer { keyPointer.deallocate() } jwt_set_alg(object.pointee, JWT_ALG_ES256, keyPointer, Int32(privateKey.utf16.count + 1)) // https://github.com/benmcollins/libjwt/pull/71 jwt_add_header(object.pointee, "kid", keyID) jwt_add_grant(object.pointee, "iss", issuerID.uuidString.lowercased()) let expirationDate = Date().addingTimeInterval(expirationInterval) jwt_add_grant_int(object.pointee, "exp", Int(expirationDate.timeIntervalSince1970)) jwt_add_grant(object.pointee, "aud", "appstoreconnect-v1") guard let encodedCString = jwt_encode_str(object.pointee) else { throw Error.decodeError } return String(cString: encodedCString) } }
  6. System Library(>=4.2) • SPM Package Description v4.2͔ΒSystem Library͕αϙʔτ • System

    LibraryΛύοέʔδ͔Β௚઀ࢀরͰ͖ΔΑ͏ʹ • https://github.com/apple/swift-package-manager/blob/master/ Documentation/PackageDescriptionV4_2.md
  7. How to Use • .systemLibraryͷଘࡏ͸υΩϡϝϯτʹॻ͍ͯ͋Δ • ࢖͍ํͷυΩϡϝϯτ͕ͳ͍ • ॻ͖͔͚ͷυΩϡϝϯτ͕Ϛʔδ͞Εͯͳ͍ঢ়ଶͰൃݟ͞Εͨ •

    https://github.com/apple/swift-package-manager/blob/ 40d319d7bb1a8cb42b187a4cbfa72515c61ebc44/ Documentation/Usage.md
  8. // swift-tools-version:4.2 // The swift-tools-version declares the minimum version of

    Swift required to build this package. import PackageDescription let package = Package( name: "Wormhole", products: [ .library( name: "Wormhole", targets: ["Wormhole"]), ], targets: [ .systemLibrary(name: "JWT", path: "./Sources/jwt", providers: [.brew(["libjwt"]), .apt(["libjwt"])]), .target( name: "Wormhole", dependencies: ["Result", "JWT"]), ] )
  9. Local Package • PD v4.2͔ΒϩʔΧϧύεͰͷdependencyʹରԠ import PackageDescription let package =

    Package( name: "MyPackage", dependencies: [ .package(path: "../example-package-playingcard"), ], targets: [ .target( name: "MyPackage", dependencies: ["PlayingCard"] ), ] )
  10. Achievement • ~ͷల։͕όά͍ͬͯͨͷͰࡢ೔௚ͨ͠ • https://github.com/apple/swift-package-manager/pull/1779 $ swift build --disable-package-manifest-caching error:

    /Users/giginet/work/myexecutable/~/work/MyPackage has no manifest 'myexecutable' /Users/giginet/work/myexecutable: error: product dependency 'MyPackage' not found
  11. SPM • SwiftͰ։ൃՄೳ • llbuild͸C++ • ͪΐͬͱPython(2) • Ϗϧυͷཱྀ͕ͳ͍ •

    ϏϧυࡁΈToolchainΛ࢖͑͹ྑ͍ • SPMͱswift-llbuild͚ͩඞཁ