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

Bazel Recipes @ Tink

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Bazel Recipes @ Tink

From the bazel build //stockholm/...
How Bazel helps in streamlining the Tink development workflow

Avatar for Kiril Videlov

Kiril Videlov

August 29, 2019

Other Decks in Programming

Transcript

  1. //introduction meetup_presenter( name = “Kiril Videlov”, work = “@tink//:software_eng”, exports

    = [ “//bazel/presentation” ], twitter = “@krlvi” ) #Bazel contributor, commit hash: d96e1cdbe71d117f76e55c668bb4a0f976bf0bc0
  2. //background • Tink is a fast growing company -> Colleagues

    & Code • Facilitate high rate of change • Quality for end users
  3. Rate of change vs Quality As per convention: “Integrate small

    & often with as many tests as possible” But those build times...
  4. Build & Test only targets that were affected by a

    change Most changes are small and isolated It would be great not to have to rebuild the world Binary compatibility is tricky What if we could...
  5. //Bazel semantics Isolation of Targets Dependency DAG Reproducibility Parallel Artifact

    execution caching Parsimony (endgame) Fully specified HD*(Hermetic & Deterministic) java_library( ) java_binary( ) go_library( ) container_image( ) inputs -> inputs -> inputs -> inputs -> inputs -> inputs -> inputs -> inputs -> inputs -> -> outputs -> outputs -> outputs -> outputs
  6. //Bazel semantics Isolation of Targets Dependency DAG Reproducibility Parallel Artifact

    execution caching Parsimony (endgame) Dependencies graph Target’s inputs and outputs form a Directed Acyclic Graph Example:
  7. //Bazel semantics Isolation of Targets Dependency DAG Reproducibility Parallel Artifact

    execution caching Parsimony (endgame) Reproducibility java_library( name = "lib", src = ["Foo.java", "Bar.java"] deps = ["//db:client"], ) • Construct a Merkle (hash) tree from inputs • Build in a sandbox* of only the defined inputs • Name artifact after the hash
  8. //Bazel semantics Isolation of Targets Dependency DAG Reproducibility Parallel Artifact

    execution caching Parsimony (endgame) Cashing Artifact are cached locally. … But sharing is caring Remote caching speeds up builds
  9. //Bazel semantics Isolation of Targets Dependency DAG Reproducibility Parallel Artifact

    execution caching Parsimony (endgame) Parallel execution • Targets can be built in parallel • Extra tricks - compile ABI first • Remote execution Example:
  10. //Bazel semantics Isolation of Targets Dependency DAG Reproducibility Parallel Artifact

    execution caching Parsimony (endgame) Parsimony parsimony (n.) early 15c., from Latin parsimonia "sparingness, frugality, thrift," from pars-, past participle stem of parcere "to spare, save, refrain from, use moderately" (which is said to be unrelated to Latin parvus "small," parum "too little") + -monia, suffix signifying action, state, or condition. A.k.a.: Only build what is necessary Option A: Hit the cache Option B: Query the graph
  11. //Option B: Query the graph Ingredients: • List of files

    created, updated or removed • Bazel Prep: • With the list of files, query for packages ◦ `bazel query “path/to/file”` • With the list of packages, query for targets of interest ◦ `bazel query ‘kind(docker_push_rule, allpaths(//…, packages))’` Serving: • Warm, with a pinch of CI
  12. Q&A