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
620
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
970
Live on iOSDC2023
hcrane
4
1.2k
自販機で1000円を使い切りたいんじゃ!
hcrane
0
120
Vision.framework - 商品画像からのテキスト検出と並列化実装への試み
hcrane
1
680
DevRel/Japan 2023 - 1つの事業部だけで行う DevRel とは
hcrane
0
960
R2-D2をiOSで動かす
hcrane
2
2.7k
iOSDC2022 - SwiftUI in UIKit で開発する世界
hcrane
6
6.8k
iOSDC2022 - iPadOSDC Japan 2022
hcrane
2
3.8k
iOSDC2021 - Compositional Layoutsで実現する疎結合な実装
hcrane
3
5.1k
Other Decks in Technology
See All in Technology
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
170
ハイテク休憩
sat
PRO
2
150
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
120
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
220
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
150
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
310
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
120
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
Featured
See All Featured
Building Applications with DynamoDB
mza
91
6.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Designing for Performance
lara
604
68k
Thoughts on Productivity
jonyablonski
67
4.4k
Site-Speed That Sticks
csswizardry
2
190
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
How GitHub (no longer) Works
holman
311
140k
Scaling GitHub
holman
458
140k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Docker and Python
trallard
42
3.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
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