Slide 1

Slide 1 text

Working With Alterna/ve Build Systems Gautam Korlam & Kurt Nelson ! Developer Pla4orm at Uber

Slide 2

Slide 2 text

Gradle at scale

Slide 3

Slide 3 text

The configura-on phase becomes slow

Slide 4

Slide 4 text

Groovy and Kotlin are full programming languages, not configura8on languages

Slide 5

Slide 5 text

Gradle holds the whole project model in the IDE

Slide 6

Slide 6 text

Performance tuning is hard Tuning 3rdparty plugins is harder

Slide 7

Slide 7 text

Working with mul/ple languages is not easy

Slide 8

Slide 8 text

Reproducibility is key

Slide 9

Slide 9 text

Dependency management

Slide 10

Slide 10 text

Extensibility with plugins

Slide 11

Slide 11 text

Enterprise feature set

Slide 12

Slide 12 text

How do we fix these issues?

Slide 13

Slide 13 text

A language built for builds - Starlark Determinis)c, Herme)c, immutable, performant, simple and built with tooling in mind

Slide 14

Slide 14 text

What are the alterna*ve build systems?

Slide 15

Slide 15 text

Bazel Buck

Slide 16

Slide 16 text

Bazel and Buck are language and toolchain agnos3c build systems that use starlark and are tailored towards large modular codebases

Slide 17

Slide 17 text

Bazel Built by Google Used by Dropbox, Google, Ly2, Spo4fy, Square, Uber

Slide 18

Slide 18 text

Buck Built by Facebook Used by Airbnb, Facebook, Ly3, Square, Uber

Slide 19

Slide 19 text

Okbuck Built by Uber Hybrid inter-op between Gradle and Buck

Slide 20

Slide 20 text

Example configura0ons using Starlark and Bazel

Slide 21

Slide 21 text

Example android kotlin app1 load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") kt_android_library( name = "lib", srcs = glob(["java/com/example/bazel/*.kt"]), custom_package = "com.example.bazel", manifest = "AndroidManifest.xml", resource_files = glob(["res/**"]), visibility = ["//:__pkg__"], deps = [ "@maven//:androidx_appcompat_appcompat", "@maven//:androidx_core_core", "@maven//:androidx_core_core_ktx", "@maven//:androidx_drawerlayout_drawerlayout", "@maven//:androidx_fragment_fragment", "@maven//:androidx_lifecycle_lifecycle_common", "@maven//:androidx_lifecycle_lifecycle_viewmodel", ], ) 1 For more examples, checkout github

Slide 22

Slide 22 text

Example android kotlin app1 android_binary( name = "app", custom_package = "com.example.bazel", manifest = "AndroidManifest.xml", deps = [ ":lib", ], ) 1 For more examples, checkout github

Slide 23

Slide 23 text

Why use an alterna-ve build system?

Slide 24

Slide 24 text

They are fast!

Slide 25

Slide 25 text

Scale be(er as your codebase grows

Slide 26

Slide 26 text

Design differences Gradle Bazel Task Graph Ac,on Graph Lazy if configured by task All targets lazy by default Combining different languages in one build is difficult Fully na,ve graph of different languages possible

Slide 27

Slide 27 text

Combining Languages cc_library( name = "main-jni-lib", srcs = [ "@local_jdk//:jni_header", "@local_jdk//:jni_md_header-linux", "Main.cc" ], hdrs = [ "Main.h" ], includes = [ "external/local_jdk/include", "external/local_jdk/include/linux" ], ) cc_binary( name = "libmain-jni.so", deps = [ ":main-jni-lib" ], linkshared = 1, )

Slide 28

Slide 28 text

Combining Languages java_binary( name = "Main", srcs = [ "Main.java" ], main_class = "Main", data = [ ":libmain-jni.so" ], jvm_flags = [ "-Djava.library.path=." ], )

Slide 29

Slide 29 text

Fool proof extensibility Gradle Bazel Caching is opt-in Caching is built in Easy to have side effects Impossible to have side effects Need to understand plugin api and internals Standard Starlark Modifying exis@ng behavior is not straight forward All rules can be wrapped in a macro

Slide 30

Slide 30 text

Extending using macros2 def kt_android_library(name, exports = [], visibility = None, **kwargs): """Creates an Android sandwich library. `srcs`, `deps`, `plugins` are routed to `kt_jvm_library` the other android related attributes are handled by the native `android_library` rule. """ native.android_library( name = name, exports = exports + _kt_android_artifact(name, **kwargs), visibility = visibility, testonly = kwargs.get("testonly", default=0), ) 2 For more details on bazel kotlin rules, checkout github

Slide 31

Slide 31 text

Extending using macros2 def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], **kwargs): """Delegates Android related build attributes to the native rules but uses the Kotlin builder to compile Java and Kotlin srcs. Returns a sequence of labels that wrapping macro should export. """ base_name = name + "_base" kt_name = name + "_kt" base_deps = deps + ["@io_bazel_rules_kotlin//kotlin/internal/jvm:android_sdk"] native.android_library( name = base_name, visibility = ["//visibility:private"], exports = base_deps, **kwargs ) _kt_jvm_library( name = kt_name, srcs = srcs, deps = base_deps + [base_name], plugins = plugins, testonly = kwargs.get("testonly", default=0), visibility = ["//visibility:private"], ) return [base_name, kt_name] 2 For more details on bazel kotlin rules, checkout github

Slide 32

Slide 32 text

Organiza(onal Gradle Bazel Popular standard for Java/Kotlin Any Language or pla8orm, including iOS Android developers know it already Android developers can build iOS or backend Follow Android plugin updates Local control over when updates happen Supported by Google and usable out of the box Requires resourcing

Slide 33

Slide 33 text

How do alterna,ve build systems solve problems at scale?

Slide 34

Slide 34 text

Herme%c and reproducible builds out of the box

Slide 35

Slide 35 text

Tooling exists for large refactorings of the build graph

Slide 36

Slide 36 text

Shared infrastructure for all All languages are on equal foo.ng All targets can be remotely built and cached All pla&orms can share common code like models

Slide 37

Slide 37 text

Changes the developer experience

Slide 38

Slide 38 text

Flakiness is a thing of the past!

Slide 39

Slide 39 text

Take updates on your own cadence

Slide 40

Slide 40 text

Adding new targets is simple Developers naturally build smaller targets

Slide 41

Slide 41 text

All developers are empowered to extend the build system

Slide 42

Slide 42 text

Downsides

Slide 43

Slide 43 text

Immediate access to latest Android build features o3en requires work

Slide 44

Slide 44 text

IDE integra,on is not the best

Slide 45

Slide 45 text

Learning curve for engineers

Slide 46

Slide 46 text

Community and resources3 3 More info about BazelCon

Slide 47

Slide 47 text

Should I switch to an alterna2ve build system?

Slide 48

Slide 48 text

When should I consider it?

Slide 49

Slide 49 text

How do I go about switching to an alterna4ve?

Slide 50

Slide 50 text

Thanks Ques%ons?