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

    • ϥΠϒϥϦͷ࡞੒ऀͱͯ͠ɺ഑෍ͷํ๏Λٕज़తʹ൑அͰ͖Δ • ϦϯΫͷઃఆ͸ར༻ऀ͕΍Δ΋ͷͳͷͰར༻ऀͷεΩϧͷ޲্ ͸ɺ࡞੒ऀɾར༻ऀͱ΋ʹϋοϐʔʹͳΔɻ
  2. ελςΟοΫϥΠϒϥϦ͔ μΠφϛοΫϥΠϒϥϦ͔Λௐ΂Δ $ 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. ελςΟοΫϥΠϒϥϦ͔ μΠφϛοΫϥΠϒϥϦ͔Λௐ΂Δ $ 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. Xcode͕ઃఆ͢Δ΋ͷ • FRAMEWORK_SEARCH_PATHSʹϑϨʔϜϫʔΫ͕͋Δ σΟϨΫτϦͷ਌σΟϨΫτϦΛ௥Ճ • Linked Framework and LibrariesʹϑϨʔϜϫʔΫΛ௥Ճ •

    Build PhaseʹCopy Files PhaseΛ௥Ճͯ͠ϑϨʔϜϫʔΫ ΛΞϓϦέʔγϣϯόϯυϧͷFrameworksσΟϨΫτϦ ʹίϐʔ͢Δ
  5. Bridging Headerͱͷҧ͍ • Module Map͸Bridging Headerͷ্Ґޓ׵ • Bridging Header͸ΞϓϦέʔγϣϯλʔήοτͰ͔͠࢖ ͑ͳ͍ʢϑϨʔϜϫʔΫͷ։ൃͰ͸࢖͑ͳ͍ʣ

    • Bridging Header͸άϩʔόϧʹ࡞༻͢ΔͷͰඞཁͳͱ͜ ͱ͚ͩͰImport͢Δͱ͍͏͜ͱ͕Ͱ͖ͳ͍ • ϓϩδΣΫτʹObjective-CͷϑΝΠϧ͕ࠞ͟Δ৔߹ʹͩ ͚࢖͏ͷ͕Α͍ʢͦͷ৔߹Ͱ΋Module Map͸࢖͑Δʣ
  6. యܕతͳΠϯϙʔτΤϥʔ • αʔνύε͕ؒҧ͍ͬͯΔ • Ϟδϡʔϧ͕ͳ͍ • Module Mapʹॻ͔Ε͍ͯΔϔομ͕ࢀরͰ͖ͳ͍ • Swift

    5.0·Ͱ͸όʔδϣϯͷҧ͏ίϯύΠϥͰϏϧυͨ͠Ϟ δϡʔϧΛΠϯϙʔτͰ͖ͳ͍ • ModuleMapͷ໊લ͕ϧʔϧ͔Β֎Ε͍ͯΔ
 -Xcc -fmodule-map-file="....modulemap"
  7. యܕతͳϦϯΫΤϥʔ • αʔνύε͕ؒҧ͍ͬͯΔ • ର৅ͷΞʔΩςΫνϟɾϑϨʔϜϫʔΫͷόΠφϦ͕Ϗϧυ͞Εͯͳ ͍ • dyld: image not

    found • μΠφϛοΫϑϨʔϜϫʔΫ͕ίϐʔ͞Εͯͳ͍ • େจࣈখจࣈͷҧ͍ • Swift 4.2·Ͱ͸όʔδϣϯͷҧ͏ίϯύΠϥͰϏϧυͨ͠όΠφϦΛ ϦϯΫͰ͖ͳ͍
  8. 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
  9. 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/
  10. 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/
  11. 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