Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swiftビルド弾丸ツアー - Swift Buildが作る新しいエコシステム

Avatar for giginet giginet PRO
September 20, 2025

Swiftビルド弾丸ツアー - Swift Buildが作る新しいエコシステム

Avatar for giginet

giginet PRO

September 20, 2025
Tweet

More Decks by giginet

Other Decks in Programming

Transcript

  1. $ swift build —target MyExecutable Building for debugging... [8/8] Applying

    MyExecutable Build complete! (0.69s) $ Swift/swift-build-tour/MyExecutable .build/debug/MyExecutable Hello, world!
  2. MyApp.o ContentView.o $ swiftc -c MyApp.swift ContentView.swift MyApp.swift ContentView.swift $

    ld -o MyApp \ -platform_version macos 15.0.0 15.0.0 \ -syslibroot $(xcrun --show-sdk-path) \ -lSystem \ -L $(xcrun --toolchain swift --show-sdk- path)/usr/lib/swift \ MyApp.o ContentView.o \ -lswiftCore \ -lobjc \ -lc++ ./MyApp ld swiftc/clang
  3. Swift Compiler 5 — Open Source Swift Workshop, try! Swift

    Tokyo 2024, @kitasuke https://speakerdeck.com/kitasuke/open-source-swiftc-workshop?slide=5 thanks: @kitasuke
  4. Ϗϧυϓϩηε w ࣮ߦϑΝΠϧͷੜ੒ w ίϯύΠϧͱϦϯΫ w Ϧιʔεͷม׵ w "TTFU$BUBMPH $PSF%BUB

    9$4USJOH 4UPSZCPBSE w "QQ#VOEMFͷ૊Έཱͯ w #VJME4DSJQUͷ࣮ߦ ŋŋŋ
  5. ϏϧυγεςϜͷඞཁੑ • େྔͷૢ࡞Λߴ଎ʹਖ਼͍͠ॱংͰ࣮ߦ͢Δඞཁ͕͋Δ • ႈ౳ੑͷ୲อ • ࣮ߦ͝ͱʹ݁Ռ͕ಉҰ • ΠϯΫϦϝϯλϧͳ࣮ߦ •

    มߋ͕͋ͬͨͱ͜Ζ͚ͩΛ࣮ߦ͠ɺෆཁͳ࣮ߦΛආ͚Δ • ༗໊ͳϏϧυγεςϜ • CMake, Bazel, Ninja https://github.com/swiftlang/swift-llbuild
  6. a.swiftΛίϯύΠϧ b.swiftΛίϯύΠϧ ΦϒδΣΫτϑΝΠϧΛϦϯΫ Asset CatalogͷίϯύΠϧ Code Sign ΞϓϦόϯυϧͷ࡞੒ #VJME5BTL a.swift

    a.o b.swift a.o b.o MyApp Assets.xcasset Asset.car MyApp Asset.car MyApp.app MyApp.app MyApp.app b.o
  7. llbuildϚχϑΣετ • શମͷϏϧυʹඞཁͳૢ࡞ΛҰཡͨ͠΋ͷ • ֤Ϗϧυεςοϓͷ࣮ߦίϚϯυɺೖྗɺग़ྗΛએݴ • ্ҐͷϏϧυγεςϜ(Xcode, SwiftPM)͕ੜ੒ • ͦΕͧΕͷλεΫ΍ґଘؔ܎ΛYAML/JSONͰهड़

    • SwiftPM: .build/debug.yaml • Xcode: <DerivedData>/manifest.json • llbuild͸ϚχϑΣετͷ࣮ߦͷΈΛߦ͏ https://github.com/swiftlang/swift-llbuild
  8. lient: name: basic file-system: device-agnostic ools: {} argets: "MyExecutable-arm64-apple-macosx15.0-debug.exe": ["<MyExecutable-arm64-apple-macosx15.0-debug.exe>"]

    "MyExecutable-arm64-apple-macosx15.0-debug.module": ["<MyExecutable-arm64-apple-macosx15.0-debug.module>"] "PackageStructure": ["<PackageStructure>"] "main": ["<MyExecutable-arm64-apple-macosx15.0-debug.exe>","<MyExecutable-arm64-apple-macosx15.0-debug.module>"] "test": ["<MyExecutable-arm64-apple-macosx15.0-debug.exe>","<MyExecutable-arm64-apple-macosx15.0-debug.module>"] efault: "main" odes: "/Users/giginet/work/Swift/swift-build-tour/MyExecutable/Sources/": is-directory-structure: true content-exclusion-patterns: [".git",".build"] "/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable": is-mutated: true ommands: "/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable-entitlement.plist": tool: write-auxiliary-file inputs: ["<entitlement-plist>","<com.apple.security.get-task-allow>"] outputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable-entitlement.plist"] description: "Write auxiliary file /Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable-entitlement.plist" "/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/sources": tool: write-auxiliary-file inputs: ["<sources-file-list>","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/Sources/main.swift"] outputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/sources"] description: "Write auxiliary file /Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/sources" "/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.product/Objects.LinkFileList": tool: write-auxiliary-file inputs: ["<link-file-list>","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/main.swift.o"] outputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.product/Objects.LinkFileList"] description: "Write auxiliary file /Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.product/Objects.LinkFileList" "/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/swift-version--44D72886A502174.txt": tool: write-auxiliary-file inputs: ["<swift-get-version>","/Applications/Xcode-16.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc"] outputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/swift-version--44D72886A502174.txt"] always-out-of-date: "true" description: "Write auxiliary file /Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/swift-version--44D72886A502174.txt" "<MyExecutable-arm64-apple-macosx15.0-debug.exe>": tool: phony inputs: ["<MyExecutable-arm64-apple-macosx15.0-debug.exe-CodeSigning>"] outputs: ["<MyExecutable-arm64-apple-macosx15.0-debug.exe>"] "<MyExecutable-arm64-apple-macosx15.0-debug.module>": tool: phony inputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/main.swift.o","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/Modules/MyExecutable.swiftmodule"] outputs: ["<MyExecutable-arm64-apple-macosx15.0-debug.module>"] "C.MyExecutable-arm64-apple-macosx15.0-debug.exe": tool: shell inputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/main.swift.o","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.product/Objects.LinkFileList"] outputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable"] description: "Linking ./.build/arm64-apple-macosx/debug/MyExecutable" args: ["/Applications/Xcode-16.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc","-L","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug","-o","/Users/giginet/work/Swift/swift-build-tour/ yExecutable/.build/arm64-apple-macosx/debug/MyExecutable","-module-name","MyExecutable","-Xlinker","-no_warn_duplicate_libraries","-emit-executable","-Xlinker","-alias","-Xlinker","_MyExecutable_main","-Xlinker","_main","-Xlinker","-rpath","- linker","@loader_path","@/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable.product/Objects.LinkFileList","-Xlinker","-rpath","-Xlinker","/Applications/Xcode-16.4.app/Contents/Developer/Toolchains/ codeDefault.xctoolchain/usr/lib/swift-5.5/macosx","-target","arm64-apple-macosx10.13","-Xlinker","-add_ast_path","-Xlinker","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/Modules/MyExecutable.swiftmodule","-sdk","/ pplications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk","-F","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks","-F","/Applications/Xcode-16.4.app/Contents/Developer/ latforms/MacOSX.platform/Developer/Library/PrivateFrameworks","-I","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib","-L","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib","-g"] "C.MyExecutable-arm64-apple-macosx15.0-debug.exe-entitlements": tool: shell inputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable-entitlement.plist"] outputs: ["<MyExecutable-arm64-apple-macosx15.0-debug.exe-CodeSigning>"] description: "Applying debug entitlements to ./.build/arm64-apple-macosx/debug/MyExecutable" args: ["codesign","--force","--sign","-","--entitlements","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/MyExecutable-entitlement.plist","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/ ebug/MyExecutable"] "C.MyExecutable-arm64-apple-macosx15.0-debug.module": tool: shell inputs: ["/Users/giginet/work/Swift/swift-build-tour/MyExecutable/Sources/main.swift","/Users/giginet/work/Swift/swift-build-tour/MyExecutable/.build/arm64-apple-macosx/debug/swift-version--44D72886A502174.txt","/Users/giginet/work/Swift/swift-build-tour/ yExecutable/.build/arm64-apple-macosx/debug/MyExecutable.build/sources"]
  9. "C.MyExecutable-arm64-apple-macosx15.0-debug.module": tool: shell inputs: [ "main.swift", ".build/arm64-apple-macosx/debug/swift-version--44D72886A502174.txt", ".build/arm64-apple-macosx/debug/MyExecutable.build/sources" ] outputs:

    [ ".build/arm64-apple-macosx/debug/MyExecutable.build/main.swift.o", ".build/arm64-apple-macosx/debug/Modules/MyExecutable.swiftmodule" ] description: "Compiling Swift Module 'MyExecutable' (1 sources)" args: ["/Applications/Xcode-16.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc","- module-name","MyExecutable","-emit-dependencies","-emit-module","-emit-module-path","/.build/arm64-apple-macosx/ debug/Modules/MyExecutable.swiftmodule","-output-file-map","/.build/arm64-apple-macosx/debug/MyExecutable.build/ output-file-map.json","-incremental","-c","@/.build/arm64-apple-macosx/debug/MyExecutable.build/sources","- I","/.build/arm64-apple-macosx/debug/Modules","-target","arm64-apple-macosx10.13","-enable-batch-mode","-index- store-path","/.build/arm64-apple-macosx/debug/index/store","-Onone","-enable-testing","-j16","-DSWIFT_PACKAGE","- DDEBUG","-module-cache-path","/.build/arm64-apple-macosx/debug/ModuleCache","-parseable-output","-Xfrontend","- entry-point-function-name","-Xfrontend","MyExecutable_main","-color-diagnostics","-swift-version","6","-sdk","/ Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk","-F","/ Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks","-F","/ Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks","- I","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib","-L","/ Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib","-g","-Xcc","- isysroot","-Xcc","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ MacOSX15.5.sdk","-Xcc","-F","-Xcc","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/MacOSX.platform/ Developer/Library/Frameworks","-Xcc","-F","-Xcc","/Applications/Xcode-16.4.app/Contents/Developer/Platforms/ MacOSX.platform/Developer/Library/PrivateFrameworks","-Xcc","-fPIC","-Xcc","-g","-package-name","myexecutable"]
  10. llbuild llbuildϚχϑΣετΛ࡞੒͢Δ CLIίϚϯυͷ࣮ߦ swiftc / ld / clang / ͦͷଞͷπʔϧ

    Swift Package Manager Xcode Xcode Project Package.swift ϓϩδΣΫτɾύοέʔδΛಡΈࠐΉ
  11. ݱঢ়ͷϏϧυγεςϜͷ໰୊఺ w MMCVJMEͷϑϩϯτΤϯυͷ࣮૷͕ෳ਺ଘࡏ w 9DPEF YDCVJME  w 4XJGU1. w

    ͭͷϏϧυγεςϜʹػೳ͕ࠩੜ·ΕΔ w ରԠϓϥοτϑΥʔϜ w ϚΫϩɺύοέʔδϓϥάΠϯ https://forums.swift.org/t/evolving-swiftpm-builds-with-swift-build/77596
  12. 4XJGU#VJMEͷ໨తϏϧυମݧͷ౷Ұ w 4XJGU1BDLBHF.BOBHFSͱ9DPEFͰϏϧυύε͕ҟͳΔ w ػೳ͕ࠩ͋Δ w 9DPEFϚΫϩ΍1BDLBHF1MVHJOΛ௚઀ѻ͑ͳ͍ w 4XJGU1.J04޲͚ʹϏϧυ͕Ͱ͖ͳ͍ w

    ΫϩείϯύΠϧͷͨΊͷج൫ͷఏڙ w "QQMF"OESPJE-JOVY8JOEPXT8"4. https://forums.swift.org/t/evolving-swiftpm-builds-with-swift-build/77596
  13. 4XJGU#VJMEͷ໨తϏϧυ࠷దԽ w ϏϧυγεςϜͷ࡮৽ʹΑΔϏϧυ࠷దԽ w ฒྻ౓ͷ޲্ͳͲ w &YQMJDJUMZ#VJME.PEVMFͷಋೖ w ϏϧυάϥϑΛઌʹߏஙͯ͠࠷దԽ͢Δ৽͍͠Ϗϧυख๏ w

    ΠϯΫϦϝϯλϧϏϧυͷϏϧυΩϟογϡར༻཰ͷ޲্ w 9DPEF͔Βඪ४Խ w ͭ·Γྑ͍ײ͡ʹͳΔ https://forums.swift.org/t/evolving-swiftpm-builds-with-swift-build/77596
  14. 4XJGU#VJMEͰ1*'ΛϏϧυ͢Δ # Dump PIF from Xcode Project $ /usr/bin/xcrun xcodebuild

    -dumpPIF /path/to/MyApp.pif -project MyApp.xcodeproj # Dump PIF from Swift Package $ swift package dump-pif > MyPackage.pif
  15. }, { "buildSettings" : { "CLANG_ENABLE_OBJC_ARC" : "YES", "CODE_SIGNING_REQUIRED" :

    "NO", "CODE_SIGN_IDENTITY" : "", "COPY_PHASE_STRIP" : "YES", "DEBUG_INFORMATION_FORMAT" : "dwarf-with-dsym", "DRIVERKIT_DEPLOYMENT_TARGET" : "19.0", "DYLIB_INSTALL_NAME_BASE" : "@rpath", "ENABLE_TESTABILITY" : "YES", "ENABLE_TESTING_SEARCH_PATHS" : "YES", "ENTITLEMENTS_REQUIRED" : "NO", "FRAMEWORK_SEARCH_PATHS[__platform_filter=ios;ios-simulator]" : [ "$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks" ], "FRAMEWORK_SEARCH_PATHS[__platform_filter=macos]" : [ "$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks" ], "FRAMEWORK_SEARCH_PATHS[__platform_filter=tvos;tvos-simulator]" : [ "$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks" ], "GCC_OPTIMIZATION_LEVEL" : "s", "GCC_PREPROCESSOR_DEFINITIONS" : [ "$(inherited)", "SWIFT_PACKAGE" ], "IPHONEOS_DEPLOYMENT_TARGET" : "12.0", "IPHONEOS_DEPLOYMENT_TARGET[__platform_filter=ios-maccatalyst]" : "13.0", "KEEP_PRIVATE_EXTERNS" : "NO", "MACOSX_DEPLOYMENT_TARGET" : "10.13", "OTHER_LDRFLAGS" : [ ], "PRODUCT_NAME" : "$(TARGET_NAME)",
  16. 4XJGU#VJMEͰ1*'ΛϏϧυ͢Δ # Build PIF with Swift Build $ swbuild build

    \ —con f iguration release \ —target MyApp MyApp.pif \ —derivedData DerivedData swbuild = Swift Buildʹ෇ଐ͍ͯ͠ΔCLIπʔϧ
  17. $ swbuild build \ --configuration release MyApp.pif \ —-target MyApp

    \ --derivedDataPath DerivedData 96 {"kind":"planningOperationStarted","planningOperationID":"4B9C6712 -57C2-4019-AD58-F4B09217C4DB"} 201 {"executionDescription":"Compute target dependency graph","id":1,"kind":"taskStarted","ruleInfo":"ComputeTargetDepend encyGraph","serializedDiagnosticsPaths": [],"signature":"\u0001compute_target_graph"} 347 {"appendToOutputStream":true,"childDiagnostics":[],"component": {"componentType":"default"},"fixIts":[],"kind":"note","location": {"locationType":"unknown"},"locationContext": {"locationType":"globalTask","taskID":1},"locationContext2": {"taskSignature":"\u0001compute_target_graph"},"message":"Building
  18. 4XJGU#VJMEඪ४ԽͷͨΊʹ w OBUJWFϏϧυϞʔυͱͷػೳޓ׵ੑ w 4XJGU#VJMEͰαϙʔτ͞Ε͍ͯͳ͍4XJGU1BDLBHFͷػೳ͕͋Δ w ϚΫϩ w ϓϥάΠϯ w

    ϚϧνϓϥοτϑΥʔϜରԠ w 4XJGU#VJME͸8JOEPXT-JOVY"OESPJEαϙʔτ͕ෆ׬શ https://forums.swift.org/t/evolving-swiftpm-builds-with-swift-build/77596
  19. ·ͱΊ w 4XJGU#VJME͕ొ৔ͨ͜͠ͱͰ4XJGU1.ͱ9DPEFϏϧυͷύε͕౷߹͞ΕΔ w ͭͷϏϧυγεςϜͷػೳࠩҟ͕ຒ·͍ͬͯ͘ w ΫϩεϓϥοτϑΥʔϜϏϧυ΋͞Βʹਪਐ͞ΕΔ w ΞʔΩςΫνϟ͕Ұ৽͞Εͨ͜ͱͰߴ଎Խ΍࠷దԽ͕ΑΓਐΜͰ͍͘ w

    ΦʔϓϯιʔεԽ͞Εͨ͜ͱͰɺϒϥοΫϘοΫεͩͬͨ9DPEFϏϧυͷ ಈ࡞ৄࡉΛௐࠪ͠΍͘͢ͳͬͨ https://forums.swift.org/t/evolving-swiftpm-builds-with-swift-build/77596