Slide 1

Slide 1 text

ͱʹ͔͘஗͍!! ஗͍ Xcode ΛͳΜͱ͔͢Δํ๏ @niw 9/12/2022 — Tokyo, Japan iOSDC Japan 2022 Xcode ͕஗͍!

Slide 2

Slide 2 text

Yoshimasa Niwa @niw

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Xcode ஗͍Ͱ͢ΑͶ

Slide 5

Slide 5 text

Xcode ͕஗͍ ීஈͷΫϦʔϯϏϧυ͸10෼͘Β͍ͰऴΘΔ ϫʔΫεʔϖʔεΛ։͍ͯϏϧυͨ͠Β Xcode ͕ࢭ·Δ ৔߹ʹΑͬͯ͸ Xcode ͕൓Ԡ͠ͳ͘ͳͬͯ͠·͏ ͳ͔ͥ೔ʹΑͬͯ͸ͱͯ΋Ϗϧυʹ͕͔͔࣌ؒΔ

Slide 6

Slide 6 text

ϫʔΫεʔϖʔεΛ։͍ͯ Ϗϧυ͢Δͱࢭ·Δ໰୊

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

ϫʔΫεʔϖʔεΛ։͍ͯ
 Ϗϧυ͢Δͱࢭ·Δ໰୊ Ϗϧυ͢Δͱ Planning Ͱͱ·ͬͯɺProvisioning ͱදࣔ͞ Εͯਐ·ͳ͍ ͜ͷঢ়ଶͩͱϏϧυΛࢭΊΔ͜ͱ΋Ͱ͖ͳ͍

Slide 9

Slide 9 text

ϫʔΫεʔϖʔεΛ։͍ͯ
 Ϗϧυ͢Δͱࢭ·Δ໰୊ Xcode ڧ੍ऴྃ͢Δ͔͠ͳ͍ Activity Monitor ΛݟΔͱ XCBBuildService ͕ 900% ͘Β͍ CPUΛ࢖ͬͯΔ

Slide 10

Slide 10 text

͜Ε͸ Xcode ͷ໰୊

Slide 11

Slide 11 text

Xcode ͷ໰୊ ϫʔΫεϖʔεΛ։͘ͱɺݟ͑Δશ෦ͷϓϩδΣΫτͷΠϯ σοΫεΛ࡞Ζ͏ͱ͢Δ ΠϯσοΫε࡞੒ͷ࡞ۀΛ XCBBuildService ʹґཔ͢Δ ͜ͷ࡞ۀͷͳ͔Ͱ͋ΔόάΛ;Ή ͦͷ݁Ռ XCBBuildService ͕൓Ԡ͠ͳ͘ͳΔ

Slide 12

Slide 12 text

XCBBuildService ͱ͸ Xcode ͷϏϧυΛ͔ͭ͞ͲΔผͷϓϩάϥϜ Xcode ͱ͸ϓϩηεؒ௨৴Λ͍ͯ͠Δ

Slide 13

Slide 13 text

Xcode ͷ໰୊ XCBBuildService ͕όάΛ౿Ήͱ൓Ԡ͠ͳ͘ͳΔ Xcode ͕ϏϧυϦΫΤετΛૹͬͯ΋൓Ԡ͠ͳ͍ͷͰࢭΊΔ ͜ͱ΋Ͱ͖ͳ͍

Slide 14

Slide 14 text

ճආࡦ

Slide 15

Slide 15 text

Xcode ͷ໰୊͋ΔڍಈΛ્ࢭ͢Δ ΠϯσοΫεͷػೳͦͷ΋ͷΛࢭΊΔඞཁ͸ͳ͍ ϫʔΫεϖʔεΛ։͍ͨޙʹى͜Δ໰୊ͷ͋Δશ෦ͷΠϯ σοΫεΛ࡞ΔڍಈΛ્ࢭ͢Ε͹ྑ͍

Slide 16

Slide 16 text

Xcode ͷ໰୊͋ΔڍಈΛ્ࢭ͢Δ Xcode ͱ XCBBuildService ͱͷؒʹԿ͔͍Εͯɺશ෦ͷΠ ϯσοΫεΛ࡞ΔϦΫΤετΛ્ࢭ͢Ε͹Α͍ͷͰ͸? ϦΫΤετΛ્ࢭ

Slide 17

Slide 17 text

XCBBUILDSERVICE_PATH ࣮͸ XCBBuildService ͸ XCBBUILDSERVICE_PATH ؀ڥม ਺ͰมߋͰ͖Δ XCBBuildService Λஔ͖׵͑ͯ Xcode ͱΦϦδφϧͷ XCBBuildService ͷؒʹೖͬͯϓϩηεؒ௨৴Λ๦֐͢Ε͹ ͍͍

Slide 18

Slide 18 text

github.com/MobileNativeFoundation/XCBBuildServiceProxyKit XCBBuildServiceProxyKit SwiftNIO ϕʔεͷ࣮૷ HybridXCBBuildService Λ࢖͑͹࣮ݱͰ͖Δ

Slide 19

Slide 19 text

XCBBuildServiceProxyKit Λ࢖͏

Slide 20

Slide 20 text

XCBBuildServiceProxyKit Λ࢖͏ ࣗલͷ XCBBuildService Λ࡞ΓɺHybridXCBBuildService ࢖ͬͯϦΫΤετΛୣ͏ ෳ਺ͷλʔήοτͷΠϯσοΫεΛ࡞Δ CreateBuildRequest ͕͖ͨΒ્ࢭ ͦΕҎ֎͸ΦϦδφϧͷ XCBBuildService ʹԣྲྀ͠

Slide 21

Slide 21 text

func handleRequest( _ request: RPCRequest, ... ) { switch request.payload { case let .createBuildRequest(message): let buildRequest = message.buildRequest if buildRequest.parameters.action == "indexbuild", buildRequest.configuredTargets.count > 1 { context.sendErrorResponse("Abort", request: request) return } default: break } context.forwardRequest() }

Slide 22

Slide 22 text

XCBBuildServiceProxyKit Xcode Λىಈ͢Δͱ͖ʹ open --env XCBBUILDSERVICE_PATH=ࣗ෼ͷ XCBBuildService /Applications/Xcode.app ͱ͢Δ

Slide 23

Slide 23 text

͜ͷճආࡦͷ໰୊఺ Xcode ͕ࢭ·ͬͯ͠·͏໰୊͸ճආͰ͖Δ ςετεΩʔϚͳͲෳ਺λʔήοτͷϏϧυΛ͢Δͱࢭ·Δ ͷ͸௚ͤͳ͍ɻಉ͡ঢ়ଶʹͳͬͯ͠·͏ɻ Create build description ͕ͱͯ΋஗͍ͳͲɺ࣮ࡍͷϏϧυ͕ ஗͍໰୊͸ճආͰ͖ͳ͍

Slide 24

Slide 24 text

࣮͸…

Slide 25

Slide 25 text

Xcode 14 ͦ΋ͦ΋ͷ XCBBuildService ͷόά͕ Xcode 14 Beta 2 Ͱͳ ͓Γ·ͨ͠ Xcode 14 ͷ Release Candidate ΋ϦϦʔε͞Ε·ͨ͠

Slide 26

Slide 26 text

͜ͷճආࡦ͸طʹෆཁ

Slide 27

Slide 27 text

ͨ·ʹීஈΑΓ
 Ϗϧυ͕஗͘ͳΔ໰୊

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

ͨ·ʹීஈΑΓϏϧυ͕஗͘ͳΔ໰୊ Ϗϧυ͕ਐΜͰ͍ͳ͍Α͏ʹݟ͑Δ Activity Monitor ΛΈΔͱҰͭͷ swift-frontend ΍ clang ͚͕ͩ ಈ࡞͍ͯ͠Δ CPU͕Ջͯ͠Δ

Slide 30

Slide 30 text

ϩοΫػߏͷ໰୊

Slide 31

Slide 31 text

ͨ·ʹීஈΑΓϏϧυ͕஗͘ͳΔ໰୊ clang ಺෦ʹ͋Δ llvm ͷϩοΫػߏ͕ݪҼ clang ͕Ұ͔ͭ͠ಈ͚ͳ͍ঢ়گ͕͋Δ Swift ΋಺෦Ͱ clang ࢖ͬͯΔ

Slide 32

Slide 32 text

clang.llvm.org/docs/Modules.html clang ͷϞδϡʔϧͱϩοΫ ௨ৗ clang ͸ϞδϡʔϧΛ୳࣌͢ʹɺσΟεΫʹ͋ΔϞ δϡʔϧΩϟογϡΛ࢖͏ ϞδϡʔϧΩϟογϡ͸ίϯύΠϧ࣌ͷϑϥάͳͲͷઃఆ͝ ͱʹผʑͷ΋ͷ͕࡞ΒΕΔ ݟ͔ͭΒͳ͔ͬͨΒͦͷ࣌ʹ࡞ΒΕΔ

Slide 33

Slide 33 text

clang.llvm.org/docs/Modules.html clang ͷϞδϡʔϧͱϩοΫ ͜͜Ͱෳ਺ͷ clang ͕ಉ࣌ʹಉ͡ϞδϡʔϧΛඞཁͱͨ͠৔ ߹ɺಉ͡ϞδϡʔϧΛ࡞ΔͷΛ๷͙ͨΊʹϩοΫΛऔΔ ϞδϡʔϧϑΝΠϧͷύεΛ llvm::LockFileManager Λ࢖ͬ ͯϩοΫ͢Δ

Slide 34

Slide 34 text

llvm::LockFileManager ϑΝΠϧͷύε͝ͱʹྡʹ .lock ϑΝΠϧΛ࡞ͬͯɺϓϩη ε͝ͱʹϩοΫΛऔΕΔ࢓૊Έ ϩοΫ͕औΕͳ͔ͬͨΒղ์͞ΕΔ·Ͱ଴ͭػೳ͕͋Δ

Slide 35

Slide 35 text

͜ͷϩοΫػߏʹ໰୊͕͋Δ

Slide 36

Slide 36 text

llvm::LockFileManager::waitForUnlock() Ethernet ͷিಥݕग़ʹࣅͨ࢓૊Έ ·ͣ 10 ms * ͋Δൣғͷཚ਺ (࠷େ500 ms) Λ଴ͭ ·ͩղ์͞Εͳ͔ͬͨΒൣғΛ2ഒʹͯ͠·ͨ଴ͭɻ͜ΕΛ ܁Γฦ͢ɻσϑΥϧτͰ࠷େ1෼30ඵ଴ͭɻ

Slide 37

Slide 37 text

clang ͕ϩοΫͷղ์Λ଴ͯͳ͔ͬͨ৔߹ clang ͸ϩοΫ͕औΕͣɺղ์͕଴ͯͳ͔ͬͨ৔߹ɺطଘͷ ϩοΫΛ࡟আͯ͠΋͏Ұ౓ϩοΫΛऔΖ͏ͱ͢Δ ෳ਺ͷ clang ͕ಉ͡ϞδϡʔϧΛ୳͍ͯͨ͠৔߹ɺ͜͜Ͱ ϩοΫͷऔΓ߹͍ʹͳΔ

Slide 38

Slide 38 text

clang ͕ϩοΫͷղ์Λ଴ͯͳ͔ͬͨ৔߹ ͋Δ clang ͕ͱͬͨϩοΫ͕ղ์੍ݶ࣌ؒ·Ͱʹղ์͞Εͳ ͍ͱɺ͜ΕΛ܁Γฦ͢ ͜ͷ݁Ռɺӡྑ͘ϩοΫ͕औΕͨҰͭͷ clang ͔͠࢓ࣄ͕ Ͱ͖ͳ͍͕࣌ؒͰ͖Δ

Slide 39

Slide 39 text

Module clang clang clang

Slide 40

Slide 40 text

Module clang clang clang

Slide 41

Slide 41 text

Module clang clang clang .lock !

Slide 42

Slide 42 text

Module clang clang clang .lock ! "

Slide 43

Slide 43 text

Module clang clang clang .lock ! " ⏳

Slide 44

Slide 44 text

Module clang clang clang .lock ! "

Slide 45

Slide 45 text

Module clang clang clang .lock ! "

Slide 46

Slide 46 text

Module clang clang clang "

Slide 47

Slide 47 text

Module clang clang

Slide 48

Slide 48 text

Module clang clang

Slide 49

Slide 49 text

Module clang clang .lock !

Slide 50

Slide 50 text

Module clang clang .lock ! "

Slide 51

Slide 51 text

Module clang clang .lock ! " ⏳

Slide 52

Slide 52 text

Module clang clang .lock ! "

Slide 53

Slide 53 text

Module clang clang .lock ! "

Slide 54

Slide 54 text

Module clang clang "

Slide 55

Slide 55 text

Module clang

Slide 56

Slide 56 text

Module clang

Slide 57

Slide 57 text

Module clang .lock !

Slide 58

Slide 58 text

Module clang .lock ! "

Slide 59

Slide 59 text

Module clang "

Slide 60

Slide 60 text

Module

Slide 61

Slide 61 text

ճආࡦ

Slide 62

Slide 62 text

ϩοΫ͠ͳ͍Α͏ʹ͢Δ ࠷ۙಋೖ͞ΕͨΦϓγϣϯ BuildingImplicitModuleUsesLock Ͱ ͜ͷϩοΫΛ࢖Θͳ͍Α͏ʹ͢Δ͜ͱ͕Ͱ͖Δ OTHER_CFLAGS ʹ -Xclang -fno-implicit-modules-use-lock Λ଍͢

Slide 63

Slide 63 text

͜ͷճආࡦͷ໰୊఺ ෳ਺ͷ clang ͕ಉ͡ϞδϡʔϧΛ࡞ΔՄೳੑ͕૿͑ΔͷͰ τʔλϧͰޮՌ͸͋Δ͔͸ঢ়گ࣍ୈ ͨͩɺϏϧυ͕ࢭ·Βͳ͘ͳΔͷͰؾ෼͸ྑ͍

Slide 64

Slide 64 text

ࠜຊతͳղܾ llvm::LockFileManager ΍ clang ͷڍಈΛม͑Δඞཁ͕͋Δ Xcode Ͱ͸ swift ΍ clang ͸πʔϧνΣʔϯͱͯ͠ఏڙ͞Εͯ ͍Δ

Slide 65

Slide 65 text

πʔϧνΣʔϯΛஔ͖׵͑Δ Xcode ͕࢖͏πʔϧνΣʔϯ͸ஔ͖׵͕͑Մೳ ͜ΕΒͷڍಈΛม͑ͨ clang ΛؚΉπʔϧνΣʔϯΛ࡞Δ ~/Library/Developer/Toolchains ʹ഑ஔ͢Δͱ Xcodeͷϝχϡʔ͔Β੾Γସ͑ΒΕΔ

Slide 66

Slide 66 text

πʔϧνΣʔϯΛஔ͖׵͑Δ ͨͩ͠ɺπʔϧνΣʔϯͷϏϧυ͸͔ͳΓେม clang ͚ͩͳΒɺCC ؀ڥม਺Ͱஔ͖׵͑Δͱ͍͏͜ͱ΋Ͱ͖ Δ

Slide 67

Slide 67 text

࣮͸…

Slide 68

Slide 68 text

ࠜຊతͳղܾ llvm::LockFileManager ͷ࣮૷ʹ͸ // FIXME: implement event-based waiting ͬͯॻ͍ͯ͋Δɻ

Slide 69

Slide 69 text

ͳ͓ͯ͠…

Slide 70

Slide 70 text

Xcode ΍ΊΔ?

Slide 71

Slide 71 text

Xcode ͷ໰୊఺ Xcode ΍ΊΔ? Xcode ͸جຊతʹ Apple ͔͠खग़͠Ͱ͖ͳ͍͏͑ʹߋ৽͕஗ ͍ Xcode ͸جຊతʹϓϩμΫτͱͯ͠ɺେ͖ͳΞϓϦΛϏϧυ ͢Δސ٬͕λʔήοτͰ͸ͳ͍Α͏ʹࢥ͑Δ

Slide 72

Slide 72 text

Xcode ͷར఺ Xcode ΍ΊΔ? ϓϥοτϑΥʔϜͷ৽͍͠ػೳʹଈ࠲ʹ௥ैͰ͖Δɻ macCatalyst ͳͲɻ Xcode ͸σϑΝΫτɻ΄ͱΜͲͷ։ൃऀ͕࢖͍ͬͯΔɻ

Slide 73

Slide 73 text

֎෦ͷϏϧυπʔϧ

Slide 74

Slide 74 text

ݱঢ়ɺۀքඪ४ͩͱࢥΘΕΔϏϧυπʔϧ Ұ؏ੑΛॏࢹͨ͠πʔϧͰɺͦͷ݁ՌΩϟογϡΛଟ༻Ͱ ͖ɺશମͷϏϧυ͕࣌ؒݮΔ ଟ͘ͷେ͖Ίͷ iOS ΞϓϦͰطʹଟ͘࢖ΘΕ͍ͯΔ Bazel

Slide 75

Slide 75 text

Xcode ͷϏϧυΛஔ͖׵͑Δ External Build System λʔήοτΛ࢖͏ Run Script Phase Λ࢖͏ XCBBuildService Λஔ͖׵͑Δ

Slide 76

Slide 76 text

Ϗϧυͷ৘ใ΁ͷΞΫηε XCBBuildService Ͱ͸Ϗϧυͷ৘ใ͸ Project Interchange Format (PIF) ͰऔಘͰ͖Δ Swift Package Manager ʹ࣮૷ͷ֓ཁ͕͋Δ

Slide 77

Slide 77 text

Xcode ͷϏϧυΛஔ͖׵͑Δ Ҡߦظʹ͸ XCBBuildService Λஔ͖׵͑ΔͳͲͷख๏Ͱ Xcode ͱ֎෦ͷϏϧυπʔϧΛཱ྆ͤ͞Δ ࠷ऴతʹ͸֎෦ͷϏϧυπʔϧ͚ͩʹ͢Δ Xcode ͷϓϩδΣΫτ΋֎෦ϏϧυπʔϧͰੜ੒͢ΔΑ͏ʹ ͢Δ

Slide 78

Slide 78 text

·ͱΊ Xcode ͷϏϧυ͸ XCBBuildService ͱ͍͏ผͷϓϩηε͕ ୲͍ͬͯΔ XCBBuildService ͸ஔ͖׵͕͑Մೳɻ஗͘ͳΔόάΛճආ͠ ͨΓɺ֎෦ϏϧυπʔϧΛ࢖͏ͷʹΤϯτϦϙΠϯτͱͯ͠ ࢖͑Δ

Slide 79

Slide 79 text

·ͱΊ Xcode ͕஗͍ͷ͸ clang ͳͲͷπʔϧνΣʔϯͷ໰୊Ͱ͋Δ ͜ͱ΋͋Δ ͜ΕΒ͸πʔϧνΣʔϯΛஔ͖׵͑Δ͜ͱͰ໰୊ΛճආͰ͖ Δ