$30 off During Our Annual Pro Sale. View Details »

Faster iOS Builds with Bazel

Faster iOS Builds with Bazel

TruongThi Doan
LINE App Dev 4 Software Engineer
https://linedevday.linecorp.com/jp/2019/sessions/S2-9

LINE DevDay 2019

November 21, 2019
Tweet

More Decks by LINE DevDay 2019

Other Decks in Technology

Transcript

  1. 2019 DevDay
    Faster iOS Builds With Bazel
    > TruongThi Doan
    > LINE App Dev 4 Software Engineer

    View Slide

  2. Agenda > Problems
    > Challenges
    > Room for Improvement

    View Slide

  3. Overview
    LINE iOS
    Modules
    224
    Lines of Code
    1.4m
    Source Files
    8.4k

    View Slide

  4. Problems
    > “Works on my machine” problems
    > Release builds must be full clean builds
    > Long build times as project grows

    View Slide

  5. https://bazel.build
    Bazel
    Growing LINE for iOS • Thursday, 14:30
    > Fast & Reproducible
    > Remote Caching
    > Extensible

    View Slide

  6. Incremental Adoption
    Prebuilt Static Frameworks
    Ƃ
    load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
    swift_library(
    name = "LineServices",
    srcs = glob(["*.swift"]),
    deps = [":Thrift"],
    )

    View Slide

  7. Incremental Adoption
    Prebuilt Static Frameworks
    Ƃ
    load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
    load("@build_bazel_rules_apple//apple:ios.bzl", "ios_static_framework")
    swift_library(
    name = "LineServices",
    srcs = glob(["*.swift"]),
    deps = [":Thrift"],
    )
    ios_static_framework(
    name = "LineServicesFramework",
    bundle_name = "LineServices",
    minimum_os_version = "11.0",
    deps = [":LineServices"],
    )

    View Slide

  8. > Swift dependencies
    Carthage
    Git Submodules
    > Dependencies that aren’t directly related to iOS
    CocoaPods
    > Objective-C dependencies
    Dependencies

    View Slide

  9. > Pod2BUILD
    > Manually writing BUILD files
    Objective-C static frameworks
    Swift static frameworks
    > .swiftdoc & .swiftmodule weren’t bundled
    > Post-processing ios_static_framework()
    Cont’d
    Dependencies

    View Slide

  10. Mixed Objective-C & Swift
    Frameworks

    View Slide

  11. Mixed Targets
    > Generating module map
    from Obj-C headers
    Ƃ
    native.genrule(
    name = "objc_module_map",
    srcs = hdrs,
    outs = ["module.modulemap"],
    cmd = """
    echo "module {} {{" >> $@
    for src in $(SRCS); do
    echo " header \\"$${{src}}\\"" >> $@
    done
    echo "}}" >> $@
    """.format(module_name),
    )

    View Slide

  12. Mixed Targets
    > Generating module map
    from Obj-C headers
    > swift_library() with all
    Swift source files
    Ƃ
    native.swift_library(
    name = "LineServices",
    module_name = "LineServices",
    srcs = native.glob(["*.swift"]),
    copts = [
    "-import-underlying-module",
    "-Xfrontend",
    "-enable-objc-interop",
    "-Xcc",
    "-fmodule-map-file=$(execpath :module.modulemap)",
    ],
    swiftc_inputs = hdrs + ["module.modulemap"],
    features = ["swift.no_generated_module_map"],
    )

    View Slide

  13. Mixed Targets
    > Generating module map
    from Obj-C headers
    > swift_library() with all
    Swift source files
    > objc_library() with all
    Obj-C source files
    Ƃ
    native.objc_library(
    name = "LineServices_umbrella",
    module_name = "LineServices",
    hdrs = hdrs,
    srcs = native.glob(["*.m"]),
    deps =[":LineServices"],
    )

    View Slide

  14. Ƃ
    Local Development
    > Generating Xcode project from
    BUILD files with Tulsi
    > Breakpoints work by overriding
    an LLDB setting
    # ~/.lldbinit
    settings set target.source-map "./" "~/line-ios/"

    View Slide

  15. Remote Caching
    > Any HTTP/1.1 backend
    > Google Cloud Storage
    > bazel-remote
    • github.com/buchgr/bazel-remote
    > Don’t use Bazel 1.1
    Ƃ

    View Slide

  16. Clean Build Times
    No Cache
    With Cache
    0෼ 6෼ 12෼ 18෼ 24෼ 30෼
    Bazel
    Xcode

    View Slide

  17. Room for Improvement
    > Developer experience
    > Improving shared remote cache
    > Swift Package Manager support

    View Slide

  18. Thank You

    View Slide