Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift 5.9 と C++ の互換性
Search
h.crane
March 06, 2024
Technology
1
580
Swift 5.9 と C++ の互換性
Event
集まれSwift好き!Swift愛好会 vol.80
Details
Qiita:
https://qiita.com/hcrane/items/081dd77bd593f1ea74af
h.crane
March 06, 2024
Tweet
Share
More Decks by h.crane
See All by h.crane
Getting started with controlling LEGO using Swift
hcrane
1
930
Live on iOSDC2023
hcrane
4
1.2k
自販機で1000円を使い切りたいんじゃ!
hcrane
0
110
Vision.framework - 商品画像からのテキスト検出と並列化実装への試み
hcrane
1
650
DevRel/Japan 2023 - 1つの事業部だけで行う DevRel とは
hcrane
0
930
R2-D2をiOSで動かす
hcrane
2
2.4k
iOSDC2022 - SwiftUI in UIKit で開発する世界
hcrane
6
6.6k
iOSDC2022 - iPadOSDC Japan 2022
hcrane
2
3.8k
iOSDC2021 - Compositional Layoutsで実現する疎結合な実装
hcrane
3
5k
Other Decks in Technology
See All in Technology
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
160
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
110
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
610
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
Lexical Analysis
shigashiyama
1
150
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
610
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Visualization
eitanlees
145
15k
How GitHub (no longer) Works
holman
310
140k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Navigating Team Friction
lara
183
14k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Transcript
March 7, 2024, ू·ΕSwift͖ʂSwiftѪձ vol.80 Hiromu Tsuruta @ Rakuten Group,
Inc. Swift 5.9 ͱ C++ ͷޓੑ
<Company> ・Rakuten Group, Inc <Application> ・Rakuma
<Role> ・iOS Developer ・Developer Relations <Account> ・Twitter:@hcrane14 Tech Lead
ࠓ·Ͱͷ Swift ͱ C++ ͷޓੑ
ᶃ Objective-C++ ͰϒϦοδ͢Δ ᶄ C ͰϒϦοδ͢ΔʢC++ ͷػೳ extern "C" Λ͏ʣ
ᶅ SPM ͔Β module.modulemap Ͱެ։͢Δ
ํ๏ ᶃ Objective-C++ ͰϒϦοδ͢Δ
Swift Objective-C++ C++
Live on iOSDC2023 Ҿ༻ɿhttps://photos.google.com/share/AF1QipNFYcoT0g9XcxuTm8rsNZp7i4JrBKj10iTzj4abxZfTfwTIEzHPF0OSow6P4ClskA?pli=1&key=VmVfLTU1aWExX1BRX21KMDJhajZqRktmZngzWmt3
iOSDCͷొஃ༰ ͜ͷํ๏Ͱͨ͠
Ҿ༻ɿhttps://speakerdeck.com/hcrane/live-on-iosdc2023?slide=47
Ҿ༻ɿhttps://speakerdeck.com/hcrane/live-on-iosdc2023?slide=48
؆୯ͳ࣮αϯϓϧ
C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ จࣈྻΛग़ྗ͢Δ͚ͩͷ؆୯ͳϝιουΛ࣋ͬͨΫϥε
Objective-C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ C++ͷίʔυΛݺͼग़͢ ϥούʔΫϥε
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ Objective-C++ ͷϔομʔΛՃ͢Δ
Swift ͷ࣮ߦϑΝΠϧ Swift ͔Β Objective-C++ Λݺͼग़ͤΔʂ → ݁Ռͱͯ͠ C++ Λݺͼग़ͤΔ
ํ๏ ᶄ C ͰϒϦοδ͢Δ ʢC++ ͷػೳ extern "C" Λ͏ʣ
Swift C C++
؆୯ͳ࣮αϯϓϧ
Step.1 Swift ͔Β C Λݺͼग़͢؆୯ͳྫ
Swift C ͱޓੑ͕͋Δ
C ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ จࣈྻΛग़ྗ͢Δ͚ͩͷ؆୯ͳϝιου
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ C ͷϔομʔΛՃ͢Δ
Swift ͔Β C Λݺͼग़ͤΔʂ ʢޓੑ͕͋ΔͷͰϔομʔΛՃ͢Δ͚ͩͰ؆୯ʂʣ Swift ͷ࣮ߦϑΝΠϧ
Step. 2 Swift ͔Β C ܦ༝Ͱ C++ Λݺͼग़͢؆୯ͳྫ
C++ ͷػೳ extern "C" Λ͏
extern "C" ʹؔͯ͠ • C++ ͷݴޠػೳ • C++ Λ Cݴޠͱͯ͠ѻ͏Α͏͢Δ
• C++ ͱ CݴޠͷίϯύΠϥͰޓੑ͕ͳ͍࣌ʹ extern "C" Ͱճආ͢Δ → Swift Ͱ͑ C++ Λݺͼग़͢ͷʹ͑Δ
C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ extern "C" ͰғͬͨจࣈྻΛग़ྗ ͢Δ͚ͩͷ؆୯ͳϝιου
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ C++ ͷϔομʔΛՃ͢Δ ʢ#include ͳ͜ͱʹҙʣ
Swift ͔Β C ܦ༝Ͱ C++ Λݺͼग़ͤΔʂ Swift ͷ࣮ߦϑΝΠϧ
͜ͷํ๏ͷ੍ • C++ͷؔΛCݴޠͱͯ͠એݴ͢Δ߹ɺܕCݴޠ͕αϙʔτ͢Δܕ Ͱͳ͚ΕͳΒͳ͍ɻ(C++ ͷಛఆͷܕɾࢀরɾΫϥε NGʣ • C++ͷ໊લम০͕ແޮԽ͞ΕΔɻʢΦʔόʔϩʔυ͞Εͨؔ NGʣ etc.
ํ๏ ᶅ SPM ͔Β module.modulemap Ͱެ։͢Δ
Swift Swift Package Manager C++ module.modulemap
module.modulemap ʹؔͯ͠ • Bridging Header ͷ্Ґޓ • Objective-C / C
ͷγϯϘϧʢؔɺมɺܕɺఆʣʹΞΫηεͰ͖Δ etc.
Swift ͔Β SPM ܦ༝Ͱ؆୯ʹ C++ Λݺͼग़ͤΔʂ module.modulemap ϑΝΠϧ
ઌʹհͨ͠ํ๏ ᶃ, ᶄ Ͱ SPM ͔Β͏͜ͱ͕Ͱ͖Δ
͜Ε͔Βͷ Swift ͱ C++ ͷޓੑ
C++ interoperability
؆୯ͳ࣮αϯϓϧ
C++ ͷ࣮ϑΝΠϧͱϔομʔϑΝΠϧ จࣈྻΛग़ྗ͢Δ͚ͩͷ؆୯ͳϝιουΛ࣋ͬͨΫϥε
ϓϩδΣΫτͷϔομʔϑΝΠϧ ϓϩδΣΫτͷϔομʔʹ C++ ͷϔομʔΛՃ͢Δ ʢ#include ͳ͜ͱʹҙʣ
interoperability ͷઃఆΛ C/Objective-C → C++/Objective-C++ ϓϩδΣΫτͷઃఆ
Swift ͔Β C++ Λݺͼग़ͤΔʂ Swift ͷ࣮ߦϑΝΠϧ
Objective-C / C ͱಉ͡ཁྖͰ C++ Λݺͼग़ͤΔʂ
ҙ ઃఆ͕มΘΔͷͰ C ݴޠϏϧυͰ͖ͳ͘ͳΔ ʢͨͩ͠ɺObjective-C ϏϧυͰ͖Δʣ → C ͱ C++
ͷίʔυΛࠞࡏͰ͖ͳ͘ͳΔ
Swift ͱ C++ Λߟͨ͠هࣄ Ҿ༻ɿhttps://kateinoigakukun.hatenablog.com/entry/2020/12/01/083949