Module Stability๋Š” ๋ฌด์—‡์ผ๊นŒ? ๊ณต์‹๋ฌธ์„œ๋ฅผ ํ†ตํ•ด ์•Œ์•„๋ณด์ž.

Module

Swift์—์„œ Module์€ ๋ฌด์—‡์„ ๋งํ• ๊นŒ? Swift๋Š” ์ ‘๊ทผ ์ œ์–ด์˜ ๊ธฐ์ค€์œผ๋กœ Module์„ ์‚ฌ์šฉํ•œ๋‹ค. ์ฝ”๋“œ ๋ฐฐํฌ์˜ ๋‹จ์œ„๋กœ์จ import ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋“ค์ด ๋ชจ๋‘ ๋ชจ๋“ˆ์ด๋‹ค.

Xcode์—์„œ buildํ•  ์ˆ˜ ์žˆ๋Š” ํƒ€๊ฒŸ (App Bundle, Framework etc) ๋“ค์€ ๋ชจ๋‘ Swift์—์„œ Module๋กœ ์ทจ๊ธ‰ํ•œ๋‹ค.

Module Stability

Compile Time์— ์„œ๋กœ ๋‹ค๋ฅธ ๋ฒ„์ „์˜ Swift๋กœ ์ž‘์„ฑ๋œ Module(framework)๋ฅผ ์„ž์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ

์ด์ „์— ๋ฐฐ์šด ABI Stability๋Š” Runtime์— ๊ด€๋ จ๋œ ๊ฒƒ๋“ค์ด์—ˆ๋‹ค. ์ฆ‰, ์ด๋ฏธ Compile์ด ์™„๋ฃŒ๋œ binary file๋“ค์— ๋Œ€ํ•ด ํ˜ธํ™˜์ด ๊ฐ€๋Šฅํ•œ์ง€์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด์—ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” Compile์‹œ์— ํ˜ธํ™˜๋˜๋Š” ๊ฐœ๋…์— ๋Œ€ํ•ด ๋งํ•˜๊ณ  ์žˆ๋‹ค.

์„œ๋กœ ๋‹ค๋ฅธ Swift version์ด ์žˆ์„ ๊ฒฝ์šฐ, compile์‹œ ๋‚ด product์˜ Swift version๊ณผ ๋งž์ง€ ์•Š๋‹ค๋ฉด, ๊ธฐ์กด์—๋Š” ๋‹ค๋ฅธ library์˜ ์ฝ”๋“œ๋ฅผ migrationํ•œ ๋’ค์— compile์ด ๊ฐ€๋Šฅํ–ˆ์—ˆ๋‹ค. ํ•˜์ง€๋งŒ Module Stability๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋˜๋ฉด์„œ ์ด์ „ Swift version์œผ๋กœ ์ž‘์„ฑ๋œ module์„ ์ดํ›„ Swift version์—์„œ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค.

  • Swift 5.0 ์ดํ•˜
    • Module์˜ interface๋ฅผ ์ •์˜ํ•˜๋Š” .swiftmodule format(์ผ์ข…์˜ header~~?~~)์ด compiler version์— ์˜์กด์„ฑ์„ ๊ฐ–๋Š”๋‹ค.
    • ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ ๋ฒ„์ „์˜ swift๋กœ compile๋œ module์„ ์„ž์–ด์„œ linkํ•  ์ˆ˜ ์—†๋‹ค.
    • Swift version์ด ์˜ฌ๋ผ๊ฐˆ ๋•Œ๋งˆ๋‹ค ๋ชจ๋“  framework๋ฅผ ๋‹ค์‹œ compile ํ•ด์•ผ ํ•œ๋‹ค.
  • Swift 5.1์—์„œ Module Stability ํ™•๋ณด๋จ
    • Xcode > Build Settings > Build Options > Build Libraries For Distribution: Yes
    • .swiftinterface๋ผ๋Š” ์ƒˆ๋กœ์šด format์˜ ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ชจ๋“ˆ๊ฐ„์˜ link ์ˆ˜ํ–‰
      • compiler version์— ์˜์กด์„ฑ์„ ๊ฐ–์ง€ ์•Š์Œ

Module Stability์˜ Trade-off

.swiftmodule.swiftmoduleinterface
Compiled Module FormatSwift Module Interface
Serialized, binary formatTextual listing of public API
Internal compiler data structure
Changes between compiler versionCompatible across compiler versions
โ€Build Libraries For Distributionโ€ OFFโ€Build Libraries For Distributionโ€ ON

Trade Off๊ฐ€ ์žˆ์„ ์ˆ˜ ๋ฐ–์— ์—†๋‹ค. ํ•ด๋‹น ๊ธฐ๋Šฅ์„ Test๋กœ ํ•œ ๊ฒฝ์šฐ, ์ตœ์ ํ™”๋ณด๋‹ค๋Š” ์œ ์—ฐ์„ฑ์— ์ดˆ์ ์ด ๋งž์ถฐ์ง€๊ฒŒ ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

Reference