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

Swiftにおけるインポートとリンクの仕組みを探る

 Swiftにおけるインポートとリンクの仕組みを探る

Swiftにおけるインポートとリンクの仕組みを探る
iOSDC 2019

Kishikawa Katsumi

September 06, 2019
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. Swiftʹ͓͚ΔΠϯϙʔτͱ
    ϦϯΫͷ࢓૊ΈΛ୳Δ

    View full-size slide

  2. ࠓ೔࿩͢͜ͱ
    • SwiftͰओʹ࢖༻Ͱ͖ΔϥΠϒϥϦͷܗࣜ

    • ֤ܗࣜͷҧ͍ͱಛ௃

    • Πϯϙʔτͱ͸Կ͔

    • ϥΠϒϥϦΛImport͢ΔͨΊʹඞཁͳ͜ͱ

    • ϦϯΫͱ͸Կ͔

    • ϥΠϒϥϦΛϦϯΫ͢ΔͨΊʹඞཁͳ͜ͱ

    View full-size slide

  3. ϚχϡΞϧͰઃఆ
    XcodeͷػೳΛར༻͢Δ
    CocoaPods, CarthageΛར༻͢Δ
    ϥΠϒϥϦͷར༻ํ๏

    View full-size slide

  4. ϚχϡΞϧͰઃఆ
    XcodeΛར༻͢Δ
    CocoaPods, CarthageΛར༻͢Δ
    ໰୊ղܾͷ೉қ౓
    Hard
    Easy

    View full-size slide

  5. ϚχϡΞϧͰઃఆ
    XcodeΛར༻͢Δ
    CocoaPods, CarthageΛར༻͢Δ
    ໰୊ղܾͷ೉қ౓
    Hard
    Easy

    View full-size slide

  6. ͳͥΠϯϙʔτͱϦϯΫʹ͍ͭͯ
    ஌Δඞཁ͕͋Δͷ͔
    • ιϑτ΢ΣΞ։ൃͰ֎෦ͷϥΠϒϥϦΛར༻͢ΔͨΊ

    • ϥΠϒϥϦΛར༻͠ͳ͍͜ͱ͸ͳ͍ʢe.g. UIKitʣ

    • ϥΠϒϥϦͷར༻ऀͱͯ͠ɺར༻ʹ·ͭΘΔτϥϒϧΛղܾͰ
    ͖Δ

    • ϥΠϒϥϦͷ࡞੒ऀͱͯ͠ɺ഑෍ͷํ๏Λٕज़తʹ൑அͰ͖Δ

    • ϦϯΫͷઃఆ͸ར༻ऀ͕΍Δ΋ͷͳͷͰར༻ऀͷεΩϧͷ޲্
    ͸ɺ࡞੒ऀɾར༻ऀͱ΋ʹϋοϐʔʹͳΔɻ

    View full-size slide

  7. ͳͥΠϯϙʔτͱϦϯΫ͕
    ೉͍͠ͷ͔
    • ϥΠϒϥϦ͸ݟͨ໨Ͱ൑அͰ͖ͳ͍ҧ͍͕େ͖͍

    • SwiftͰ͸IDE΍ίϯύΠϥʢυϥΠόʔʣʹΑΔ҉໧తͳॲཧ͕
    ଟ͍

    • ΠϯϙʔτͱϦϯΫ͸ಉ࣌ʹղܾ͞ΕΔΑ͏ʹΈ͑Δ͕ɺ࣮ࡍʹ
    ͸̎ͭʢҎ্ʣͷҟͳΔϑΣʔζͱϓϩηε

    • Τϥʔ͕ىͬͨ͜ͱ͖ɺද૚ͷΤϥʔϝοηʔδ͔Β͸ݪҼ͕ಡ
    ΈऔΕͳ͍

    • ಉ͡ΤϥʔϝοηʔδͰ΋ݪҼ͸͞·͟·

    View full-size slide

  8. ͳͥΠϯϙʔτͱϦϯΫ͕
    ೉͍͠ͷ͔
    • ൚༻తͳ஌ࣝͱXcode΍Swiftݻ༗ͷ஌ࣝͷ྆ํ͕ඞཁ

    • ݕࡧ͢ΔͱࣅͨΤϥʔϝοηʔδͷؔ܎ͳ͍࿩͕ͲΜͲΜ
    ग़ͯ͘Δ

    • Java΍RubyɺJavaScriptͳͲ͸VMͰಈ͘ͷͰωΠςΟϒ
    ίʔυͱͷϦϯΫΛΑΓ΋ચ࿅͞Εͨ࢓૊Έ͕͋Γɺͦ
    ͕͜τϥϒϧʹͳΔ͜ͱ͸গͳ͍

    View full-size slide

  9. ࣮͸Τϥʔͷύλʔϯ͸গͳ͍

    View full-size slide

  10. ࣮͸Τϥʔͷύλʔϯ͸গͳ͍

    View full-size slide

  11. ࣮͸Τϥʔͷύλʔϯ͸গͳ͍

    View full-size slide

  12. ࠓ೔ͷ࿩ͰಘΒΕΔ͜ͱ
    • ϥΠϒϥϦͷܗࣜʹؔ͢Δ஌ࣝ

    • ΠϯϙʔτͱϦϯΫͷ஌ࣝ

    • ΠϯϙʔτͱϦϯΫʹ·ͭΘΔτϥϒϧղܾͷೳྗ
    جૅ
    Ԡ༻
    • ϥΠϒϥϦ࡞੒ʹ͓͚Δ഑෍ܗଶͷٕज़൑அ

    • ύοέʔδϚωʔδϟͷߴ౓ͳར༻

    View full-size slide

  13. ϥΠϒϥϦʹ͍ͭͯ

    View full-size slide

  14. ϥΠϒϥϦͷܗࣜ
    ֤ܗࣜͷҧ͍ͱಛ௃

    View full-size slide

  15. ϥΠϒϥϦͷܗࣜͱҧ͍
    ϥΠϒϥϦͷܗࣜͱҧ͍
    ΠϯϙʔτͱϦϯΫʢXcodeΛ࢖༻ͯ͠ઃఆʣ
    ΠϯϙʔτͱϦϯΫʢϚχϡΞϧ࡞ۀͰઃఆʣ
    Ϟδϡʔϧͱ͸
    ϦϯΫͱ͸

    View full-size slide

  16. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ
    ϑϨʔϜϫʔΫ
    (e.g. UIKit.framework, RxSwift.framework)
    μΠφϛοΫɾϥΠϒϥϦ
    (e.g. libsqlite3.dylib, libz.dylib)
    ελςΟοΫɾϥΠϒϥϦ
    (e.g. libssl.a, libcrypto.a)

    View full-size slide

  17. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ
    μΠφϛοΫɾϑϨʔϜϫʔΫ
    μΠφϛοΫɾϥΠϒϥϦ
    ελςΟοΫɾϥΠϒϥϦ
    ελςΟοΫɾϑϨʔϜϫʔΫ

    View full-size slide

  18. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ
    ϞδϡʔϧΛؚΉμΠφϛοΫɾϑϨʔϜϫʔΫ
    μΠφϛοΫɾϥΠϒϥϦ
    ελςΟοΫɾϥΠϒϥϦ
    ϞδϡʔϧΛؚ·ͳ͍μΠφϛοΫɾϑϨʔϜϫʔΫ
    ϞδϡʔϧΛؚΉελςΟοΫɾϑϨʔϜϫʔΫ
    ϞδϡʔϧΛؚ·ͳ͍ελςΟοΫɾϑϨʔϜϫʔΫ

    View full-size slide

  19. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ

    View full-size slide

  20. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ

    View full-size slide

  21. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ
    ✖ ✖

    View full-size slide

  22. SwiftͰओʹ࢖༻Ͱ͖Δ
    ϥΠϒϥϦͷܗࣜ

    View full-size slide

  23. ݟͨ໨ͰΘ͔Γʹ͍͘
    ҧ͍ͷ૊Έ߹Θͤ
    ϑϨʔϜϫʔΫ
    ϥΠϒϥϦ
    μΠφϛοΫ
    ελςΟοΫ
    Swift
    Objective-C
    C
    Ϟδϡʔϧ༗Γ
    Ϟδϡʔϧແ͠
    ✖ ✖ ✖ ΞʔΩςΫνϟɾ
    ϓϥοτϑΥʔϜ

    View full-size slide

  24. ݟͨ໨ͰΘ͔ʹ͍͘ͳ͍
    ҧ͍ͷ૊Έ߹Θͤ
    ϑϨʔϜϫʔΫ
    ϥΠϒϥϦ
    μΠφϛοΫ
    ελςΟοΫ
    Swift
    Objective-C
    C
    Ϟδϡʔϧ༗Γ
    Ϟδϡʔϧແ͠
    ✖ ✖ ΞʔΩςΫνϟɾ
    ϓϥοτϑΥʔϜ


    View full-size slide

  25. ݟͨ໨ͰΘ͔ʹ͍͘ͳ͍
    ҧ͍ͷ૊Έ߹Θͤ
    ϑϨʔϜϫʔΫ
    ϥΠϒϥϦ
    μΠφϛοΫ
    ελςΟοΫ
    Swift
    Objective-C
    C
    Ϟδϡʔϧ༗Γ
    Ϟδϡʔϧແ͠
    ✖ ΞʔΩςΫνϟɾ
    ϓϥοτϑΥʔϜ



    View full-size slide

  26. ݟͨ໨ͰΘ͔ʹ͍͘ͳ͍
    ҧ͍ͷ૊Έ߹Θͤ
    ϑϨʔϜϫʔΫ
    ϥΠϒϥϦ
    μΠφϛοΫ
    ελςΟοΫ
    Swift
    Objective-C
    C
    Ϟδϡʔϧ༗Γ
    Ϟδϡʔϧແ͠
    ΞʔΩςΫνϟɾ
    ϓϥοτϑΥʔϜ

    ✖ ✖

    View full-size slide

  27. ݟͨ໨ͰΘ͔ʹ͍͘ͳ͍
    ҧ͍ͷ૊Έ߹Θͤ
    ϑϨʔϜϫʔΫ
    ϥΠϒϥϦ
    μΠφϛοΫ
    ελςΟοΫ
    Swift
    Objective-C
    C
    Ϟδϡʔϧ༗Γ
    Ϟδϡʔϧແ͠
    ΞʔΩςΫνϟɾ
    ϓϥοτϑΥʔϜ
    ✖ ✖ ✖

    View full-size slide

  28. ݟͨ໨ͰΘ͔ʹ͍͘ͳ͍
    ҧ͍ͷ૊Έ߹Θͤ
    ϑϨʔϜϫʔΫ
    ϥΠϒϥϦ
    μΠφϛοΫ
    ελςΟοΫ
    Swift
    Objective-C
    C
    Ϟδϡʔϧ༗Γ
    Ϟδϡʔϧແ͠
    ΞʔΩςΫνϟɾ
    ϓϥοτϑΥʔϜ
    ✖ ✖ ✖ ✖

    View full-size slide

  29. ϑϨʔϜϫʔΫͱ
    ϥΠϒϥϦͷҧ͍

    View full-size slide

  30. ϑϨʔϜϫʔΫͱϥΠϒϥϦͷҧ͍
    όϯυϧΛ࣋ͭ
    όϯυϧΛ࣋ͨͳ͍
    όϯυϧΛ࣋ͨͳ͍

    View full-size slide

  31. όϯυϧͱ͸ʁ
    Appόϯυϧ Projectόϯυϧ Settingsόϯυϧ Frameworkόϯυϧ

    View full-size slide

  32. όϯυϧͱ͸ʁ

    View full-size slide

  33. ελςΟοΫϦϯΫ
    μΠφϛοΫϦϯΫ

    View full-size slide

  34. ελςΟοΫϦϯΫ
    μΠφϛοΫϦϯΫ
    Static Library (*.a)
    Static Framework (*.framework)
    Dynamic Framework (*.framework)
    Dynamic Library (*.dylib)

    View full-size slide

  35. ελςΟοΫϦϯΫ
    ίϯύΠϧ Static Linking

    View full-size slide

  36. μΠφϛοΫϦϯΫ
    ίϯύΠϧ Dynamic Linking

    View full-size slide

  37. ελςΟοΫϦϯΫ
    μΠφϛοΫϦϯΫ
    ʓʓ.app ××.app

    View full-size slide

  38. ελςΟοΫϥΠϒϥϦ͔
    μΠφϛοΫϥΠϒϥϦ͔Λௐ΂Δ
    $ file
    Usage: file [-bcCdEhikLlNnprsvzZ0] [--apple] [--extension] [--mime-encoding]
    [--mime-type] [-e ] [-F ] [-f ]
    [-m ] [-P ] ...
    file -C [-m ]
    file [--help]
    file ίϚϯυ

    View full-size slide

  39. ελςΟοΫϥΠϒϥϦ͔
    μΠφϛοΫϥΠϒϥϦ͔Λௐ΂Δ
    $ file Logger.framework/Logger
    Logger.framework/Logger: Mach-O universal binary with 2 architectures:
    [x86_64:Mach-O 64-bit x86_64 dynamically linked shared library,...
    [arm64:Mach-O 64-bit arm64 dynamically linked shared library,...

    View full-size slide

  40. όϯυϧ༗Γ όϯυϧແ͠
    ελςΟοΫϦϯΫ
    μΠφϛοΫϦϯΫ
    Static Library
    Static Framework
    Dynamic Library
    Dynamic Framework

    View full-size slide

  41. ΠϯϙʔτͱϦϯΫ

    View full-size slide

  42. ΠϯϙʔτͱϦϯΫ
    ϥΠϒϥϦͷܗࣜͱҧ͍
    ΠϯϙʔτͱϦϯΫʢXcodeΛ࢖༻ͯ͠ઃఆʣ
    ΠϯϙʔτͱϦϯΫʢϚχϡΞϧ࡞ۀͰઃఆʣ
    Ϟδϡʔϧͱ͸
    ϦϯΫͱ͸

    View full-size slide

  43. Πϯϙʔτ
    • ֎෦ϥΠϒϥϦʢࣗ෼͕ॻ͍ͨίʔυҎ֎ʣΛࣗ෼ͷ
    ίʔυϕʔεͰར༻Մೳʹ͢Δߏจɾݴޠػೳ

    • ϥΠϒϥϦ͕ެ։͍ͯ͠ΔγϯϘϧʢΫϥεɾؔ਺ͳͲʣ
    Λࣗ෼ͷίʔυͰࢀরͰ͖ΔΑ͏ʹ͢Δ

    • ֤ϑΝΠϧʢίϯύΠϧ୯ҐʣΛίϯύΠϧ͢Δ࣌఺Ͱղ
    ܾ͞ΕΔ

    View full-size slide

  44. ϦϯΫ
    • ιʔείʔυΛίϯύΠϧͯ͠ੜ੒͞ΕͨΦϒδΣΫτ
    ϑΝΠϧɺ͓Αͼ֎෦ϥΠϒϥϦΛ͢΂ͯ࿈݁ʢϦϯΫʣ
    ͯ̍ͭ͠ͷ࣮ߦܗࣜϑΝΠϧɺ͋Δ͍͸ϥΠϒϥϦΛੜ੒
    ͢Δ

    • ϦϯΧ͕ߦ͏

    • ͢΂ͯͷιʔείʔυΛίϯύΠϧͨ͠ޙʹߦΘΕΔ

    • ͢΂ͯͷγϯϘϧ͕ղܾ͞ΕΔ

    View full-size slide

  45. ࣮ࡍʹ֬ೝͯ͠ΈΑ͏

    View full-size slide

  46. ϥΠϒϥϦΛར༻͢Δ
    Ұൠతʢ҉໧తʣͳํ๏

    View full-size slide

  47. XcodeΛ࢖ͬͯ֎෦ϥΠϒϥϦΛ
    ར༻Մೳʹ͢Δ

    View full-size slide

  48. Xcode͸҉໧తʹ
    ԿΛ͍ͯ͠Δͷ͔

    View full-size slide

  49. Updated on Xcode 11

    View full-size slide

  50. Xcode͕ઃఆ͢Δ΋ͷ
    • FRAMEWORK_SEARCH_PATHSʹϑϨʔϜϫʔΫ͕͋Δ
    σΟϨΫτϦͷ਌σΟϨΫτϦΛ௥Ճ

    • Linked Framework and LibrariesʹϑϨʔϜϫʔΫΛ௥Ճ

    • Build PhaseʹCopy Files PhaseΛ௥Ճͯ͠ϑϨʔϜϫʔΫ
    ΛΞϓϦέʔγϣϯόϯυϧͷFrameworksσΟϨΫτϦ
    ʹίϐʔ͢Δ

    View full-size slide

  51. FRAMEWORK_SEARCH_PATHSΛ
    ௐ΂Δ

    View full-size slide

  52. ΠϯϙʔτͰΤϥʔ

    View full-size slide

  53. Copy Files PhaseΛ
    ௐ΂Δ

    View full-size slide

  54. Automatic Linking

    View full-size slide

  55. Automatic LinkingΛ
    ແޮʹ͢Δ

    View full-size slide

  56. -disable-autolink-framework

    View full-size slide

  57. Import == Link
    Automatic Linking

    View full-size slide

  58. ΠϯϙʔτͱϦϯΫ
    ϥΠϒϥϦͷܗࣜͱҧ͍
    ΠϯϙʔτͱϦϯΫʢXcodeΛ࢖༻ͯ͠ઃఆʣ
    ΠϯϙʔτͱϦϯΫʢϚχϡΞϧ࡞ۀͰઃఆʣ
    Ϟδϡʔϧͱ͸
    ϦϯΫͱ͸

    View full-size slide

  59. ϑϨʔϜϫʔΫ͔Β
    ϑΝΠϧΛফͯ͠ΈΔ

    View full-size slide

  60. ϑϨʔϜϫʔΫ͔Β
    ϑΝΠϧΛফͯ͠ΈΔ

    View full-size slide

  61. ϑϨʔϜϫʔΫ͔Β
    ϑΝΠϧΛফͯ͠ΈΔ

    View full-size slide

  62. ϑϨʔϜϫʔΫ͔Β
    ϑΝΠϧΛফͯ͠ΈΔ

    View full-size slide

  63. Ϟδϡʔϧͱ͸
    ϥΠϒϥϦͷܗࣜͱҧ͍
    ΠϯϙʔτͱϦϯΫʢXcodeΛ࢖༻ͯ͠ઃఆʣ
    ΠϯϙʔτͱϦϯΫʢϚχϡΞϧ࡞ۀͰઃఆʣ
    Ϟδϡʔϧͱ͸
    ϦϯΫͱ͸

    View full-size slide

  64. BUILD_LIBRARY_FOR_DISTRIBUTION = YES

    View full-size slide

  65. ϞδϡʔϧʢSwiftҎ֎ʣ

    View full-size slide

  66. ಠࣗϞδϡʔϧΛఆٛ͢Δ

    View full-size slide

  67. Module MapϑΝΠϧͷྫ

    View full-size slide

  68. Bridging Headerͱͷҧ͍
    • Module Map͸Bridging Headerͷ্Ґޓ׵

    • Bridging Header͸ΞϓϦέʔγϣϯλʔήοτͰ͔͠࢖
    ͑ͳ͍ʢϑϨʔϜϫʔΫͷ։ൃͰ͸࢖͑ͳ͍ʣ

    • Bridging Header͸άϩʔόϧʹ࡞༻͢ΔͷͰඞཁͳͱ͜
    ͱ͚ͩͰImport͢Δͱ͍͏͜ͱ͕Ͱ͖ͳ͍

    • ϓϩδΣΫτʹObjective-CͷϑΝΠϧ͕ࠞ͟Δ৔߹ʹͩ
    ͚࢖͏ͷ͕Α͍ʢͦͷ৔߹Ͱ΋Module Map͸࢖͑Δʣ

    View full-size slide

  69. Ϟδϡʔϧͷ໾ׂ
    • Swift͕ϥΠϒϥϦΛΠϯϙʔτ͢Δʹ͸Ϟδϡʔϧ͕ඞ
    ཁʢʹΠϯϙʔτ͸Ϟδϡʔϧ͚ͩ͋Ε͹ྑ͍ʣ

    • PublicͳAPIͷએݴ

    • Objective-C/CͷϥΠϒϥϦΛΠϯϙʔτ͢Δʹ͸ɺϔο
    μϑΝΠϧ (.h) ΛModulemapͰϞδϡʔϧʹม׵͢Δ

    • Swift੡ͷϥΠϒϥϦͰ͸Ϟδϡʔϧ͸ίϯύΠϥ͕ࣗಈ
    తʹੜ੒͢Δ

    View full-size slide

  70. Module Stability

    View full-size slide

  71. https://forums.swift.org/t/plan-for-module-stability/14551
    Module Stability

    View full-size slide

  72. ϞδϡʔϧΛΠϯϙʔτ͢Δʹ͸
    import Logger
    Logger
    Logger

    View full-size slide

  73. ϞδϡʔϧΛΠϯϙʔτ͢Δʹ͸
    FRAMEWORK_SEARCH_PATHS
    Modules
    import Logger
    Logger
    Logger

    View full-size slide

  74. ϞδϡʔϧΛΠϯϙʔτ͢Δʹ͸
    import Marketo
    Marketo
    Marketo

    View full-size slide

  75. ϞδϡʔϧΛΠϯϙʔτ͢Δʹ͸
    SWIFT_INCLUDE_PATHS
    module.modulemap
    import Marketo
    Marketo
    Marketo

    View full-size slide

  76. ϦϯΫͱ͸
    ϥΠϒϥϦͷܗࣜͱҧ͍
    ΠϯϙʔτͱϦϯΫʢXcodeΛ࢖༻ͯ͠ઃఆʣ
    ΠϯϙʔτͱϦϯΫʢϚχϡΞϧ࡞ۀͰઃఆʣ
    Ϟδϡʔϧͱ͸
    ϦϯΫͱ͸

    View full-size slide

  77. ϦϯΫͱ͸
    • ίϯύΠϧͰੜ੒͞ΕͨΦϒδΣΫτϑΝΠϧͱϥΠϒϥ
    ϦʢΦϒδΣΫτϑΝΠϧͷू߹ʣΛ̍ͭʹ࿈݁ʢϦϯ
    Ϋʣ͢Δ

    • ίϯύΠϧͰੜ੒͞ΕͨΦϒδΣΫτϑΝΠϧͷϦϯΫ͸
    ࣦഊ͠ͳ͍ͷͰɺΤϥʔ͕ى͜Δͱͨ͠Β֎෦ϥΠϒϥϦ
    ͱͷϦϯΫ

    View full-size slide

  78. ϦϯΫͱ͸
    ίϯύΠϧ Static Linking
    ίϯύΠϧ Dynamic Linking

    View full-size slide

  79. ϥΠϒϥϦΛϦϯΫ͢Δʹ͸ʢXcodeʣ

    View full-size slide

  80. ϑϨʔϜϫʔΫΛϦϯΫ͢Δʹ͸
    • FRAMEWORK_SEARCH_PATHSʹϑϨʔϜϫʔΫ͕͋Δ
    σΟϨΫτϦͷ਌σΟϨΫτϦΛࢦఆ͢Δ

    • OTHER_LDFLAGSʹ-framework
    ͱࢦఆ͢Δ

    ʢe.g. -framework RxSwift, -framework "Alamofire"ʣ

    View full-size slide

  81. ϑϨʔϜϫʔΫΛϦϯΫ͢Δʹ͸

    View full-size slide

  82. ϥΠϒϥϦΛϦϯΫ͢Δʹ͸
    • ϥΠϒϥϦͷ͋ΔσΟϨΫτϦͷ਌σΟϨΫτϦΛ
    LIBRARY_SEARCH_PATHSʹࢦఆ͢Δ

    • OTHER_LDFLAGSʹ-lͱࢦఆ͢Δ

    ʢe.g. -lsqlite3, -l"crypto"ʣ

    • ϥΠϒϥϦ໊ͷϧʔϧ

    ʢlibsqlite3.dylib => sqlite3
    ɹlibssl.a => sslʣ

    View full-size slide

  83. ϥΠϒϥϦΛϦϯΫ͢Δʹ͸

    View full-size slide

  84. ϥΠϒϥϦΛϦϯΫ͢Δʹ͸
    libssl.a
    FRAMEWORK_SEARCH_PATHS
    LIBRARY_SEARCH_PATHS
    OTHER_LDFLAGS = -framework "RxSwift" -l"ssl"
    RxSwift

    View full-size slide

  85. ϥΠϒϥϦΛϦϯΫ͢Δʹ͸

    View full-size slide

  86. ΞʔΩςΫνϟɾϓϥοτϑΥʔϜ͕
    Ұக͠ͳ͚Ε͹ͳΒͳ͍
    iOS Simulator
    x86_64
    iOS Device
    arm7v
    iOS Device
    arm64
    .app
    iOS Device
    arm64



    View full-size slide

  87. αʔνύεΛม਺Խ͢Δ

    View full-size slide

  88. CONFIGURATION_BUILD_DIR
    αʔνύεΛม਺Խ͢Δ
    CONFIGURATION_BUILD_DIR
    BUILD_DIR CONFIGURATION EFFECTIVE_PLATFORM_NAME
    .../Build/Products Debug -iphoneos
    FRAMEWORK_SEARCH_PATHS = "$(CONFIGURATION_BUILD_DIR)/Firebase"
    e.g.

    View full-size slide

  89. Universal (Fat) Binary
    https://darkdonno.wordpress.com/2010/11/06/a-look-at-mach-o/

    View full-size slide

  90. Universal Binary (lipo)
    $ xcrun lipo -create <...> <...> -output <...>

    View full-size slide

  91. Universal Binary (lipo)
    $ xcrun lipo -info <...>

    View full-size slide

  92. Universal Binary (Carthage)

    View full-size slide

  93. μΠφϛοΫϑϨʔϜϫʔΫͷ৔߹

    View full-size slide

  94. μΠφϛοΫϑϨʔϜϫʔΫͷ৔߹
    @executable_path/Frameworks
    OTHER_LDFLAGS = -framework "RxSwift"
    @loader_path
    @rpath

    View full-size slide

  95. ໰୊ղܾYES/NOνϟʔτ
    ϥΠϒϥϦͷܗࣜͱҧ͍
    ΠϯϙʔτͱϦϯΫʢXcodeΛ࢖༻ͯ͠ઃఆʣ
    ΠϯϙʔτͱϦϯΫʢϚχϡΞϧ࡞ۀͰઃఆʣ
    Ϟδϡʔϧͱ͸
    ϦϯΫͱ͸

    View full-size slide

  96. ໰୊ղܾYES/NOνϟʔτ
    YESʢϦϯΫͷΤϥʔʣ
    Q1
    ϦϯΫΤϥʔͰ͔͢ʁ
    NOʢΠϯϙʔτͷΤϥʔʣ

    View full-size slide

  97. ໰୊ղܾYES/NOνϟʔτ
    YESʢ*.frameworkʣ
    Q2
    Πϯϙʔτ͠Α͏ͱ͍ͯ͠Δͷ͸
    ϑϨʔϜϫʔΫͰ͔͢ʁ
    NOʢ*.aʣ

    View full-size slide

  98. ໰୊ղܾYES/NOνϟʔτ
    YES
    Q3
    ϑϨʔϜϫʔΫʹϞδϡʔϧ͸
    ؚ·Ε͍ͯ·͔͢ʁ
    NO

    View full-size slide

  99. ໰୊ղܾYES/NOνϟʔτ
    A
    αʔνύε͕ਖ਼͍͔֬͠ೝ͍ͯͩ͘͠͞

    View full-size slide

  100. యܕతͳΤϥʔ

    View full-size slide

  101. యܕతͳΤϥʔ

    View full-size slide

  102. యܕతͳΤϥʔ

    View full-size slide

  103. యܕతͳΤϥʔ

    View full-size slide

  104. యܕతͳΠϯϙʔτΤϥʔ
    • αʔνύε͕ؒҧ͍ͬͯΔ

    • Ϟδϡʔϧ͕ͳ͍

    • Module Mapʹॻ͔Ε͍ͯΔϔομ͕ࢀরͰ͖ͳ͍

    • Swift 5.0·Ͱ͸όʔδϣϯͷҧ͏ίϯύΠϥͰϏϧυͨ͠Ϟ
    δϡʔϧΛΠϯϙʔτͰ͖ͳ͍

    • ModuleMapͷ໊લ͕ϧʔϧ͔Β֎Ε͍ͯΔ

    -Xcc -fmodule-map-file="....modulemap"

    View full-size slide

  105. యܕతͳϦϯΫΤϥʔ
    • αʔνύε͕ؒҧ͍ͬͯΔ

    • ର৅ͷΞʔΩςΫνϟɾϑϨʔϜϫʔΫͷόΠφϦ͕Ϗϧυ͞Εͯͳ
    ͍

    • dyld: image not found

    • μΠφϛοΫϑϨʔϜϫʔΫ͕ίϐʔ͞Εͯͳ͍

    • େจࣈখจࣈͷҧ͍

    • Swift 4.2·Ͱ͸όʔδϣϯͷҧ͏ίϯύΠϥͰϏϧυͨ͠όΠφϦΛ
    ϦϯΫͰ͖ͳ͍

    View full-size slide

  106. ΞʔΩςΫνϟ͕ݟ͔ͭΒͳ͍
    • xcrun lipo -info ...

    • CocoaPodsΛ࢖͍ͬͯΔͳΒ͢΂ͯͷΞʔΩςΫνϟ͕
    Ϗϧυ͞Ε͍ͯΔ͔

    • Ϗϧυߏ੒ͷ໰୊

    View full-size slide

  107. CϥΠϒϥϦʹґଘʢϦϯΫʣ͢Δ
    ϑϨʔϜϫʔΫΛ࡞੒͢Δ
    1. ར༻ऀ͕ࣗ෼ͰCϥΠϒϥϦͷϦϯΫΛઃఆ͢Δ

    2. ར༻ऀ͔Β͸CϥΠϒϥϦͷଘࡏ͸Ӆ͍ͨ͠

    View full-size slide

  108. CocoaPodsΛϫʔΫεϖʔεʹ
    ౷߹ͤͣʹ࢖༻͢Δ
    • CocoaPods͕αʔνύε΍ϦϯΧϑϥάࣗಈઃఆ͢Δػ
    ೳΛ࢖Θͣʹɺࣗ෼Ͱ֤ϥΠϒϥϦΛϏϧυ͠ϦϯΫͷ
    ઃఆΛ͢Δɻ

    ϫʔΫεϖʔεʹCocoaPodsͷઃఆ͕ࠞ͟Βͣʹॊೈ͔
    ͭγϯϓϧʹར༻Ͱ͖Δ͜ͱ͕ϝϦοτɻ

    View full-size slide

  109. CarthageͰϏϧυͤͣʹ
    ϓϩδΣΫτࢀরͰ؅ཧ͢Δ
    • Carhage͸ϢχόʔαϧόΠφϦΛࣗಈతʹϏϧυͯ͘͠
    ΕΔ͕ɺσόοά͠ʹ͍͘ͳͲσϝϦοτ΋͋ΔͷͰɺϏ
    ϧυͤͣʹϓϩδΣΫτͷνΣοΫΞ΢τ͚ͩͯ͠ར༻͢
    Δɻ

    View full-size slide

  110. ෳ਺ͷμΠφϛοΫϑϨʔϜϫʔΫΛ
    ̍ͭͷϑϨʔϜϫʔΫʹ౷߹͢Δ
    • μΠφϛοΫϑϨʔϜϫʔΫ͕૿͑ͯ͘Δͱىಈ࣌ؒʹӨ
    ڹΛ༩͑Δʢdyld2ͷ৔߹ʣ

    ͦͷͨΊ֤ϑϨʔϜϫʔΫΛελςΟοΫϦϯΫͯ͠ɺ̍
    ͭͷେ͖ͳμΠφϛοΫϑϨʔϜϫʔΫʹ͢Δ

    • Ϟδϡʔϧ͸ݩͷ෼͔Εͨঢ়ଶͰࢀর͢ΔͱศརʢΠϯ
    ϙʔτ͸ίϯύΠϧ͚࣌ͩͳͷͰϑϨʔϜϫʔΫͷߏ଄ͱ
    ঢ়ଶ͕ҟͳͬͯ΋໰୊ͳ͍ʣ

    View full-size slide

  111. Recap
    • Πϯϙʔτ͸ϞδϡʔϧΛࣗ෼ͷίʔυϕʔεͰར༻Մೳ
    ʹ͢Δ

    • ϦϯΫ͸͢΂ͯͷϑΝΠϧͷίϯύΠϧޙɺΦϒδΣΫτ
    ϑΝΠϧͱϥΠϒϥϦΛ݁߹͢Δ

    • αʔνύεͱίϯύΠϥϑϥάͰίϯτϩʔϧ

    • ίϯύΠϥͱϦϯΧ͸ίϯϐϡʔλαΠΤϯεͷͲਅΜத

    • ௿ϨΠϠʔΛ୳ࡧָ͍ͯ͘͠͠͞

    View full-size slide

  112. Reference
    • Creation of pure Swift module

    https://railsware.com/blog/creation-of-pure-swift-module/

    • Mach-O Universal / Fat Binaries – Symbol Crash

    https://www.symbolcrash.com/2019/02/26/mach-o-universal-fat-binaries/

    • Parsing Mach-O files - Low Level Bits

    https://lowlevelbits.org/parsing-mach-o-files/

    • Swift Imports

    https://thoughtbot.com/blog/swift-imports

    View full-size slide

  113. Reference
    • Static and Dynamic Libraries

    https://pewpewthespells.com/blog/static_and_dynamic_libraries.html

    • Framework vs Library (Cocoa, iOS) – Knowledge Stack

    http://www.knowstack.com/framework-vs-library-cocoa-ios/

    • Static linking vs dyld3

    https://allegro.tech/2018/05/Static-linking-vs-dyld3.html

    • Understanding Xcode Build System

    https://www.vadimbulavin.com/xcode-build-system/

    View full-size slide

  114. Reference
    • Static and Dynamic Libraries and Frameworks in iOS

    https://www.vadimbulavin.com/static-dynamic-frameworks-and-libraries/

    • Static Library, Dynamic Library and Framework in iOS

    https://medium.com/@arkilis/static-library-dynamic-library-and-framework-in-ios-df137f29a3e9

    • Dynamic Versus Static Framework in iOS - CA for Developers

    https://www.ca.com/en/blog-developers/dynamic-versus-static-framework-in-ios.html

    • Overview: iOS Static and Dynamic Frameworks and Libraries

    https://www.runtastic.com/blog/en/frameworks-ios/

    View full-size slide

  115. Reference
    • Undocumented Mac OS Xɿୈ12ճɹUniversal Binaryʲલฤʳ (1/5)

    https://www.itmedia.co.jp/enterprise/articles/0711/30/news014.html

    • Undocumented Mac OS Xɿୈ13ճɹUniversal Binaryʲޙฤʳ (1/4)

    https://www.itmedia.co.jp/enterprise/articles/0712/27/news012.html

    View full-size slide