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

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

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

9bf923e39671cde83584e3e926296c13?s=128

Kishikawa Katsumi

September 06, 2019
Tweet

Transcript

  1. 6.

    ͳͥΠϯϙʔτͱϦϯΫʹ͍ͭͯ ஌Δඞཁ͕͋Δͷ͔ • ιϑτ΢ΣΞ։ൃͰ֎෦ͷϥΠϒϥϦΛར༻͢ΔͨΊ • ϥΠϒϥϦΛར༻͠ͳ͍͜ͱ͸ͳ͍ʢe.g. UIKitʣ • ϥΠϒϥϦͷར༻ऀͱͯ͠ɺར༻ʹ·ͭΘΔτϥϒϧΛղܾͰ ͖Δ

    • ϥΠϒϥϦͷ࡞੒ऀͱͯ͠ɺ഑෍ͷํ๏Λٕज़తʹ൑அͰ͖Δ • ϦϯΫͷઃఆ͸ར༻ऀ͕΍Δ΋ͷͳͷͰར༻ऀͷεΩϧͷ޲্ ͸ɺ࡞੒ऀɾར༻ऀͱ΋ʹϋοϐʔʹͳΔɻ
  2. 38.

    ελςΟοΫϥΠϒϥϦ͔ μΠφϛοΫϥΠϒϥϦ͔Λௐ΂Δ $ file Usage: file [-bcCdEhikLlNnprsvzZ0] [--apple] [--extension] [--mime-encoding]

    [--mime-type] [-e <testname>] [-F <separator>] [-f <namefile>] [-m <magicfiles>] [-P <parameter=value>] <file> ... file -C [-m <magicfiles>] file [--help] file ίϚϯυ
  3. 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,...
  4. 48.
  5. 49.
  6. 50.
  7. 51.
  8. 52.
  9. 53.
  10. 55.
  11. 57.
  12. 58.
  13. 59.
  14. 60.
  15. 61.
  16. 62.

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

    Build PhaseʹCopy Files PhaseΛ௥Ճͯ͠ϑϨʔϜϫʔΫ ΛΞϓϦέʔγϣϯόϯυϧͷFrameworksσΟϨΫτϦ ʹίϐʔ͢Δ
  17. 67.
  18. 68.
  19. 69.
  20. 71.
  21. 74.
  22. 76.
  23. 77.
  24. 78.
  25. 91.

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

    • Bridging Header͸άϩʔόϧʹ࡞༻͢ΔͷͰඞཁͳͱ͜ ͱ͚ͩͰImport͢Δͱ͍͏͜ͱ͕Ͱ͖ͳ͍ • ϓϩδΣΫτʹObjective-CͷϑΝΠϧ͕ࠞ͟Δ৔߹ʹͩ ͚࢖͏ͷ͕Α͍ʢͦͷ৔߹Ͱ΋Module Map͸࢖͑Δʣ
  26. 99.
  27. 129.

    యܕతͳΠϯϙʔτΤϥʔ • αʔνύε͕ؒҧ͍ͬͯΔ • Ϟδϡʔϧ͕ͳ͍ • Module Mapʹॻ͔Ε͍ͯΔϔομ͕ࢀরͰ͖ͳ͍ • Swift

    5.0·Ͱ͸όʔδϣϯͷҧ͏ίϯύΠϥͰϏϧυͨ͠Ϟ δϡʔϧΛΠϯϙʔτͰ͖ͳ͍ • ModuleMapͷ໊લ͕ϧʔϧ͔Β֎Ε͍ͯΔ
 -Xcc -fmodule-map-file="....modulemap"
  28. 130.

    యܕతͳϦϯΫΤϥʔ • αʔνύε͕ؒҧ͍ͬͯΔ • ର৅ͷΞʔΩςΫνϟɾϑϨʔϜϫʔΫͷόΠφϦ͕Ϗϧυ͞Εͯͳ ͍ • dyld: image not

    found • μΠφϛοΫϑϨʔϜϫʔΫ͕ίϐʔ͞Εͯͳ͍ • େจࣈখจࣈͷҧ͍ • Swift 4.2·Ͱ͸όʔδϣϯͷҧ͏ίϯύΠϥͰϏϧυͨ͠όΠφϦΛ ϦϯΫͰ͖ͳ͍
  29. 132.
  30. 138.

    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
  31. 139.

    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/
  32. 140.

    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/
  33. 141.

    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