Slide 1

Slide 1 text

@giginet 2024/10/25 @giginet Creating Intuitive Developer Tool in Swift Slide

Slide 2

Slide 2 text

Self Introduction • giginet / Kohki Miki • X / GitHub : @giginet • Tokyo 🇯🇵 • Work for LY Corporation(2022~) • iOS DevOps Engineer for LINE • iOS Development experience since iOS 4 (2010~) • ❤ 👾 Gaming

Slide 3

Slide 3 text

Agenda and Goals • Finding the issue • History of Swift ecosystem • Practical Examples of Developer tools • Implement your tool • Implementation / Testing • For the more usable tools • Documentation / Deployment / CI • Contribute to Community

Slide 4

Slide 4 text

My OSS Contribution as a core contributor fastlane Carthage XcodeGen

Slide 5

Slide 5 text

My Recent Work : giginet/Scipio (⭐450) • A next-generation build tool to generate XCFramework • Convert Swift Package to XCFramework • Share prebuilt frameworks among developers 1. Resolve and checkout package manifest with SwiftPM 2. Scipio generates Xcode Project from each package 3. Build the projects with xcodebuild 4. xcodebuild generates XCFramework How does Scipio work? Resolve manifests Fetch packages Generate Xcode Project Build XCFrameworks https://speakerdeck.com/giginet/standardizing-build-system-using-modern-swift-packages-in-line

Slide 6

Slide 6 text

giginet/swift-testing-revolutionary (⭐200) • Convert test cases written in XCTest into swift-testing • Providing Command Plugin and Xcode GUI

Slide 7

Slide 7 text

Finding the issue History and practical example of developer tools

Slide 8

Slide 8 text

Tool Developments What should I develop? How to develop? How to spread? Why should I publish it?

Slide 9

Slide 9 text

History of iOS Developer’s Tools 2014 2019 Prehistoric Period Dawn Period Maturity Period Swift is released Maturation of Swift ecosystem

Slide 10

Slide 10 text

Before Swift era(~2015) • ObjC is not suitable for tool development • Most tools were developed in Ruby or other languages • CocoaPods(2011) • fastlane(2015) • danger(2015) • xcpretty • xcode-select

Slide 11

Slide 11 text

Swift released (2015~2019) • Some useful tools are available • Carthage(2015) • SwiftLint(2015) • XcodeGen(2017) • tuist(2018) • No de-facto standard foundations • SwiftCLI / Commandant / Commander (argument parser) • Quick / Nimble / Spectre… (Testing Framework)

Slide 12

Slide 12 text

Today : Ecosystem of tools development • The o ff i cial development foundations are available • Swift Package Manager (2015) • Xcode Integration (2019) • swift-syntax(2017) • swift-argument-parser(2020) • Package Plugin (2022) • swift-testing(2023)

Slide 13

Slide 13 text

What should we develop?

Slide 14

Slide 14 text

Begin to develop for your team!

Slide 15

Slide 15 text

Practical Example : line-tools • In-house tool collections for LINE development • Implemented many features in Swift • Build script of dependencies • Prebuilt tasks • CI scripts • linter / formatter

Slide 16

Slide 16 text

Example 1 : Building dependencies • Share XCFrameworks using Remote Server • Based on Scipio • Features • Resolve Swift Packages • Build XCFramework • Download XCFrameworks

Slide 17

Slide 17 text

Example 2 : Prebuilt Tasks • Useful wrapper tools of XcodeGen • Features • Verify Project Spec and dependencies • Generate Xcode projects from Project Specs

Slide 18

Slide 18 text

Example 3 : CI script • A tool generates TestPlan on CI for Pull Requests Builder • Generate Test Plan from Pull Request fi le di ff s • Features • Generate TestPlan by PR di ff s

Slide 19

Slide 19 text

Example 4 : Extend IDE features • A linter to warn company rules • Run custom linter on Xcode • We can use swift-syntax • Features • Lint dependency tree • Lint coding guidelines

Slide 20

Slide 20 text

Benefit of developing tools in Swift • Ubiquitous Language • Write complex tasks with a powerful language feature • Using Swift foundations (e.g. swift-syntax) • Maintainability • Testability • Type Safety

Slide 21

Slide 21 text

Implement your tools Basic techniques to create your tools

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

CI / Testing

Slide 24

Slide 24 text

Documentation

Slide 25

Slide 25 text

Distribution

Slide 26

Slide 26 text

Backward Compatibility

Slide 27

Slide 27 text

For useful developer tools • Various technics • CI / Tests • Documentation • Cross-platform / Multi versioning • Binary distribution • These also help for OSS or in-house tool

Slide 28

Slide 28 text

Kind of developer tools • Executable • Good for any purpose • Difficult to distribute • Package Plugin (Introduced from Swift 5.6) • Build Tools Plugin • Command Plugin

Slide 29

Slide 29 text

Build Tools Plugin • A mechanism to distribute build hooks via Swift Package ecosystem • Introduced in Swift 5.6 • Code Generator ( Pre-built hook) • SwiftGen / openapi-generator / License generator • Linter / Formatter (Post-built hook) • SwiftLint / SwiftFormat

Slide 30

Slide 30 text

Command Plugin • Distributing command via Swift Package ecosystem • Can provide Command Line Interface / Xcode GUI • Example • docc-plugin • swift-testing-revolutionary • See ”Meet Package Plugins" in WWDC22 • https://developer.apple.com/videos/play/wwdc2022/110359/

Slide 31

Slide 31 text

swift-argument-parser • A first-party library to make Command Line Interface(CLI) • https://github.com/apple/swift-argument-parser

Slide 32

Slide 32 text

import ArgumentParser @main struct Repeat: ParsableCommand { @Flag(help: "Include a counter with each repetition.") var includeCounter = false @Option(name: .shortAndLong, help: "The number of times to repeat 'phrase'.") var count: Int? = nil @Argument(help: "The phrase to repeat.") var phrase: String mutating func run() throws { let repeatCount = count ?? 2 for i in 1...repeatCount { if includeCounter { print("\(i): \(phrase)") } else { print(phrase) } } } } Options

Slide 33

Slide 33 text

import ArgumentParser @main struct Repeat: ParsableCommand { @Flag(help: "Include a counter with each repetition.") var includeCounter = false @Option(name: .shortAndLong, help: "The number of times to repeat 'phrase'.") var count: Int? = nil @Argument(help: "The phrase to repeat.") var phrase: String mutating func run() throws { let repeatCount = count ?? 2 for i in 1...repeatCount { if includeCounter { print("\(i): \(phrase)") } else { print(phrase) } } } } Implementations

Slide 34

Slide 34 text

To write tests my-awesome-tool executable • Difficult to write tests for single executable target

Slide 35

Slide 35 text

Package Architecture • Separate targets executable and frameworks my-awesome-tool MyAwesomeKit MyAwesomeKitTests executable framework test target Testable

Slide 36

Slide 36 text

Package Architecture • Good for minimize the dependencies my-awesome-tool MyAwesomeKit MyAwesomeKitTests executable framework test target swift-argument-parser other dependencies

Slide 37

Slide 37 text

Implement your tool!

Slide 38

Slide 38 text

For the more usable tools Tips for getting many users for your tool

Slide 39

Slide 39 text

README • Badges • https://shields.io/ • Installation methods • Feature Lists • LICENSE

Slide 40

Slide 40 text

README • Badges • https://shields.io/ • Installation methods • Feature Lists • LICENSE

Slide 41

Slide 41 text

README • Badges • https://shields.io/ • Installation methods • Feature Lists • LICENSE

Slide 42

Slide 42 text

README • Badges • https://shields.io/ • Installation methods • Feature Lists • LICENSE

Slide 43

Slide 43 text

Write articles with DocC

Slide 44

Slide 44 text

Build DocC Archive • Use DocC plugin • https://github.com/swiftlang/swift-docc-plugin • Distributing to GitHub Pages • Update DocC page with every commits Swift Package DocC Archive GitHub Pages

Slide 45

Slide 45 text

Register to Swift Package Index • Register your package to Swift Package Index • https://swiftpackageindex.com/add-a-package

Slide 46

Slide 46 text

Distribution • Many methods for distribution • Source Build • Binary / Artifact Bundle • Command Plugin • Homebrew

Slide 47

Slide 47 text

Source Builds • Nothing to do for developers • No official way to manage binaries for the user side • Mint • https://github.com/yonaskolb/Mint • No way to distribute prebuilt binaries • Need to build by users

Slide 48

Slide 48 text

Artifact Bundle • The official distribution format for executables • Host executables for multi architecture in ZIP file • https://github.com/swiftlang/swift-evolution/blob/main/proposals/ 0305-swiftpm-binary-target-improvements.md

Slide 49

Slide 49 text

Build Artifact Bundle • No official way to make Artifact Bundles • freddi-kit/ArtifactBundleGen • Command Plugin to wrap executables in Artifact Bundle format • https://github.com/freddi-kit/ArtifactBundleGen

Slide 50

Slide 50 text

Use Artifact Bundle • No official way to manage it • mtj0928/nest • Download and run prebuilt binary using Artifact Bundle • https://github.com/mtj0928/nest

Slide 51

Slide 51 text

Prepare CI environment • Must prepare CI environment! • CI provides some automation • Tests • Lint • Documentation • Generate DocC Archive • Distribute to GitHub pages • Distribution • Build Artifact Bundle

Slide 52

Slide 52 text

GitHub Action • Using GitHub Action solves everything • Separate workflows for purposes • tests/lints/release/docc

Slide 53

Slide 53 text

name: Tests on: push: branches: - main pull_request: branches: - '*' jobs: Tests: strategy: matrix: xcode_version: - "15.2" # 5.9 - "15.4" # 5.10 - "16.0" # 6.0 env: DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer" runs-on: macos-14 steps: - name: Get swift version run: swift --version - uses: actions/checkout@v2 - name: Run Tests run: | swift test --verbose env: ENABLE_INTEGRATION_TESTS: 1 IS_CI: 1 Make PR builder Build for multi versions

Slide 54

Slide 54 text

Contribute to community Make your tools great

Slide 55

Slide 55 text

Why publish a tool? • Improve your presence and career • Give inspires to communities • Receive feedback / Make collaboration Your Team Community Contributions / Inspires Feedback / Improvements

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Use your tool • Just publishing to OSS wouldn’t work fine • It’s difficult to maintain only for the community • You should be a heavy user Great Tool Contribute to Community Use your tools

Slide 58

Slide 58 text

Conclusion • Finding issues is the most important topic • Learn Techniques and Tips to Build Tools • Contributing to Swift community to publish your tool • Keep to use your tools

Slide 59

Slide 59 text

References • See my products for examples! • Scipio • swift-testing-revolutionary • Feel free to ask anything on X / Ask the Speaker • https://x.com/giginet

Slide 60

Slide 60 text

Thank you for listening!

Slide 61

Slide 61 text

No content