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
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
350
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
120
フルカイテン株式会社 採用資料
fullkaiten
0
40k
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
180
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
180
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
860
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
How GitHub (no longer) Works
holman
310
140k
Practical Orchestrator
shlominoach
186
10k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Typedesign – Prime Four
hannesfritz
40
2.4k
Why Our Code Smells
bkeepers
PRO
334
57k
A designer walks into a library…
pauljervisheath
203
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
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