Bazel { fast, correct } choose two Klaus Aehlig February 45, 2017 - - PowerPoint PPT Presentation

bazel
SMART_READER_LITE
LIVE PREVIEW

Bazel { fast, correct } choose two Klaus Aehlig February 45, 2017 - - PowerPoint PPT Presentation

Bazel How Bazel Works Open-Sourcing Summary Bazel { fast, correct } choose two Klaus Aehlig February 45, 2017 Bazel How Bazel Works Open-Sourcing Summary Bazel What is Bazel? Bazel How Bazel Works Open-Sourcing Summary Bazel


slide-1
SLIDE 1

Bazel How Bazel Works Open-Sourcing Summary

Bazel

{fast, correct} – choose two Klaus Aehlig February 4–5, 2017

slide-2
SLIDE 2

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

slide-3
SLIDE 3

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
slide-4
SLIDE 4

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool

like make, etc, it organises compiling/creating artifacts (libraries, executables, . . . ) from sources

slide-5
SLIDE 5

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
slide-6
SLIDE 6

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
  • core part of a tool

used internally at Google since over a decade

slide-7
SLIDE 7

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
  • core part of a tool

used internally at Google since over a decade

  • ptimized for Google’s internal use case
slide-8
SLIDE 8

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
  • core part of a tool

used internally at Google since over a decade

  • ptimized for Google’s internal use case
  • large code base in a single source tree (≈ 107 files)
slide-9
SLIDE 9

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
  • core part of a tool

used internally at Google since over a decade

  • ptimized for Google’s internal use case
  • large code base in a single source tree (≈ 107 files)
  • majority of engineers (≈ 104.5) actively working
  • n that single code base.
slide-10
SLIDE 10

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
  • core part of a tool

used internally at Google since over a decade

  • ptimized for Google’s internal use case (large mono-repo)
slide-11
SLIDE 11

Bazel How Bazel Works Open-Sourcing Summary

Bazel

What is Bazel?

  • Bazel is a build tool
  • core part of a tool

used internally at Google since over a decade

  • ptimized for Google’s internal use case (large mono-repo)
  • open-sourced only in 2015

(in fact, still going on)

slide-12
SLIDE 12

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

slide-13
SLIDE 13

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
slide-14
SLIDE 14

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching
slide-15
SLIDE 15

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching without losing correctness

(i.e., all artifacts as if freshly built from source)

slide-16
SLIDE 16

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching without losing correctness
slide-17
SLIDE 17

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching without losing correctness
  • declarative style of BUILD files
slide-18
SLIDE 18

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching without losing correctness
  • declarative style of BUILD files
  • separation of concerns

writing code vs choosing correct (cross) compiling strategy

slide-19
SLIDE 19

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching without losing correctness
  • declarative style of BUILD files
  • separation of concerns

writing code vs choosing correct (cross) compiling strategy

  • central maintenance point for build rules
slide-20
SLIDE 20

Bazel How Bazel Works Open-Sourcing Summary

What is Bazel Good for?

What is Bazel? And what is special about it?

  • optimized for large mono-repos, therefore. . .
  • aggressive caching without losing correctness
  • declarative style of BUILD files
slide-21
SLIDE 21

Bazel How Bazel Works Open-Sourcing Summary

Overview of a bazel build

What is Bazel? And how does it build?

slide-22
SLIDE 22

Bazel How Bazel Works Open-Sourcing Summary

Overview of a bazel build

What is Bazel? And how does it build?

  • load the BUILD files (all that are needed)
slide-23
SLIDE 23

Bazel How Bazel Works Open-Sourcing Summary

Overview of a bazel build

What is Bazel? And how does it build?

  • load the BUILD files (all that are needed)
  • analyze dependencies between targets
slide-24
SLIDE 24

Bazel How Bazel Works Open-Sourcing Summary

Overview of a bazel build

What is Bazel? And how does it build?

  • load the BUILD files (all that are needed)
  • analyze dependencies between targets
  • from rules generate action graph
slide-25
SLIDE 25

Bazel How Bazel Works Open-Sourcing Summary

Overview of a bazel build

What is Bazel? And how does it build?

  • load the BUILD files (all that are needed)
  • analyze dependencies between targets
  • from rules generate action graph
  • execute actions (unless already cached)
slide-26
SLIDE 26

Bazel How Bazel Works Open-Sourcing Summary

Overview of a bazel build

What is Bazel? And how does it build?

  • load the BUILD files (all that are needed)
  • analyze dependencies between targets
  • from rules generate action graph
  • execute actions (unless already cached)
  • n subsequent builds, update the graphs

(client-server architecture to keep graph in memory)

slide-27
SLIDE 27

Bazel How Bazel Works Open-Sourcing Summary

An Example

Let’s look at a helloworld example.

slide-28
SLIDE 28

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c

  • main program helloworld.c
slide-29
SLIDE 29

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c

  • main program helloworld.c

#include "lib/hello.h" int main(int argc, char **argv) { greet("world"); return 0; }

slide-30
SLIDE 30

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c

  • main program helloworld.c,

depending on a library

slide-31
SLIDE 31

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c lib hello.h

  • main program helloworld.c,

depending on a library

  • a library with headers (lib/hello.h)

#ifndef HELLO H #define HELLO H void greet(char *); #endif

slide-32
SLIDE 32

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c lib hello.h hello.c

  • main program helloworld.c,

depending on a library

  • a library with headers (lib/hello.h)

. . . and implementation (lib/hello.c) #include "hello.h" #include <stdio.h> void greet(char *it) { printf("Hello %s!", it); }

slide-33
SLIDE 33

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c lib hello.h hello.c

  • main program helloworld.c,

depending on a library

  • a library with headers (lib/hello.h)

. . . and implementation (lib/hello.c)

slide-34
SLIDE 34

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c lib hello.h hello.c WORKSPACE

  • main program helloworld.c,

depending on a library

  • a library with headers (lib/hello.h)

. . . and implementation (lib/hello.c)

  • then we can have an empty WORKSPACE file
slide-35
SLIDE 35

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c lib hello.h hello.c WORKSPACE BUILD BUILD

  • main program helloworld.c,

depending on a library

  • a library with headers (lib/hello.h)

. . . and implementation (lib/hello.c)

  • then we can have an empty WORKSPACE file

. . . and the following declarative BUILD files cc binary( name="helloworld", srcs=["helloworld.c"], deps=["//lib:hello"], ) cc library( name="hello", srcs=glob(["*.c"]), hdrs=glob(["*.h"]), )

slide-36
SLIDE 36

Bazel How Bazel Works Open-Sourcing Summary

An Example

helloworld.c lib hello.h hello.c WORKSPACE BUILD BUILD

  • main program helloworld.c,

depending on a library

  • a library with headers (lib/hello.h)

. . . and implementation (lib/hello.c)

  • then we can have an empty WORKSPACE file

. . . and the following declarative BUILD files cc binary( name="helloworld", srcs=["helloworld.c"], deps=["//lib:hello"], ) cc library( name="hello", srcs=glob(["*.c"]), hdrs=glob(["*.h"]), ) Note: CC, link options, host/target architecture, etc, taken care of elsewhere.

slide-37
SLIDE 37

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld

command

Now let’s see what happens if we want to build :helloworld. . .

slide-38
SLIDE 38

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld

command target

We look at the target :helloworld

slide-39
SLIDE 39

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld //

command target pkg

We look at the target :helloworld, in package //

slide-40
SLIDE 40

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD

command target pkg file system

We look at the target :helloworld, in package //, in file BUILD

slide-41
SLIDE 41

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c

command target pkg file system

Two declared dependencies

slide-42
SLIDE 42

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c

command target pkg file system

Two declared dependencies . . . and implicit dependency on the C tool chain (not drawn in this diagram)

slide-43
SLIDE 43

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD

command target pkg file system

Two declared dependencies, one in a different package Note: We construct dependency graph over package boundaries! (no recursive calling)

slide-44
SLIDE 44

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"])

command target pkg file system glob

We discover glob expressions

slide-45
SLIDE 45

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

command target pkg file system glob

We discover glob expressions, and read the directory.

slide-46
SLIDE 46

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

command target pkg file system glob

artefact

The rules tell us, which artifacts to build.

slide-47
SLIDE 47

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

BUILD helloworld.c lib/ BUILD hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

file system

artefact

slide-48
SLIDE 48

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Dependencies

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

command target pkg file system glob

artefact

slide-49
SLIDE 49

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

command target pkg file system glob

artefact

slide-50
SLIDE 50

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

command target pkg file system glob

artefact

slide-51
SLIDE 51

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

command target pkg file system glob

artefact

slide-52
SLIDE 52

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

command target pkg file system glob

artefact

slide-53
SLIDE 53

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

command target pkg file system glob

artefact

slide-54
SLIDE 54

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

lib/foo.pic.o

command target pkg file system glob

artefact

slide-55
SLIDE 55

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

lib/foo.pic.o

command target pkg file system glob

artefact

slide-56
SLIDE 56

Bazel How Bazel Works Open-Sourcing Summary

Example cont’d: Adding a File

build //:helloworld //:helloworld // BUILD //lib:hello helloworld.c //lib lib/ BUILD glob(["*.c"]) glob(["*.h"]) hello.c hello.h

lib/libhello.{a,so} lib/hello.pic.o helloworld helloworld.pic.o

foo.c

lib/foo.pic.o

command target pkg file system glob

artefact

slide-57
SLIDE 57

Bazel How Bazel Works Open-Sourcing Summary

Actions

slide-58
SLIDE 58

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building
slide-59
SLIDE 59

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time

slide-60
SLIDE 60

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

slide-61
SLIDE 61

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
slide-62
SLIDE 62

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself
slide-63
SLIDE 63

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel

slide-64
SLIDE 64

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel

  • so, no .done foo targets,
  • and only reading declared inputs
slide-65
SLIDE 65

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel

slide-66
SLIDE 66

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel facilitate correct I/O by running actions in “sandboxes”

slide-67
SLIDE 67

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel facilitate correct I/O by running actions in “sandboxes”

  • isolated environment
  • only declared inputs/tools present
  • only declared outputs copied out
slide-68
SLIDE 68

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel facilitate correct I/O by running actions in “sandboxes”

  • isolated environment
  • only declared inputs/tools present
  • only declared outputs copied out
  • depending on OS, different approaches

(chroot, temp dir, . . . )

slide-69
SLIDE 69

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel facilitate correct I/O by running actions in “sandboxes”

slide-70
SLIDE 70

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel facilitate correct I/O by running actions in “sandboxes”

  • bonus: remote execution
slide-71
SLIDE 71

Bazel How Bazel Works Open-Sourcing Summary

Actions

  • action do the actual work of building

. . . and hence take the most time particularly interesting to avoid unnecessary actions

  • dependency graph shows if prerequisites changed
  • caching of input/output-relation itself

! requires all inputs/outputs to be known to bazel facilitate correct I/O by running actions in “sandboxes”

  • bonus: remote execution

⇒ enables shared caches. (All engineers working on the same code base!)

slide-72
SLIDE 72

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

slide-73
SLIDE 73

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
slide-74
SLIDE 74

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • specialized rules with knowledge about certain languages

cc library, cc binary, java library, java binary, . . .

slide-75
SLIDE 75

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • specialized rules with knowledge about certain languages

cc library, cc binary, java library, java binary, . . .

  • generic ones, in particular genrule
slide-76
SLIDE 76

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • specialized rules with knowledge about certain languages

cc library, cc binary, java library, java binary, . . .

  • generic ones, in particular genrule

→ just specify a shell command (with $@, $<, . . . )

slide-77
SLIDE 77

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • specialized rules with knowledge about certain languages

cc library, cc binary, java library, java binary, . . .

  • generic ones, in particular genrule

→ just specify a shell command (with $@, $<, . . . ) (basically the only rule available in a Makefile)

slide-78
SLIDE 78

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
slide-79
SLIDE 79

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale
slide-80
SLIDE 80

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language

slide-81
SLIDE 81

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

slide-82
SLIDE 82

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • Python-like language (familiar syntax)
slide-83
SLIDE 83

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • Python-like language (familiar syntax)
  • but restricted to a simple core

without global state, complicated features, . . .

slide-84
SLIDE 84

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • Python-like language (familiar syntax)
  • but restricted to a simple core

without global state, complicated features, . . . deterministic, hermetic evaluation

slide-85
SLIDE 85

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

slide-86
SLIDE 86

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules
slide-87
SLIDE 87

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules

“that sh-script with these params; always create 5 targets . . . ”

slide-88
SLIDE 88

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules macros
slide-89
SLIDE 89

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules macros

def mylang(name="", param="default", srcs=[]): script = str(Label("//rules/mylang:bld.sh")) native.genrule( name = name + " out", tools = [script], cmd = "env . . . $(location " + script + ")" + ". . . $@ $(SRCS)", . . . ) native.. . .

slide-90
SLIDE 90

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules macros
slide-91
SLIDE 91

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules macros
  • all extensions are loaded in BUILD files

load("//. . . .bzl", "mylang")

slide-92
SLIDE 92

Bazel How Bazel Works Open-Sourcing Summary

Extending Bazel

  • Bazel has built-in rules
  • but adding specialized rules for every language doesn’t scale

need ways to extend BUILD language: Skylark

  • simple case: can compose it from existing rules macros
  • all extensions are loaded in BUILD files

load("//. . . .bzl", "mylang")

  • not so simple case: rules

freely specify actions, argument declaration, . . .

slide-93
SLIDE 93

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

slide-94
SLIDE 94

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use

slide-95
SLIDE 95

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

slide-96
SLIDE 96

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
slide-97
SLIDE 97

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones

“We have those libs anyway, so let’s just use them.”

slide-98
SLIDE 98

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
slide-99
SLIDE 99

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
slide-100
SLIDE 100

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces
slide-101
SLIDE 101

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces

“I know all the uses of my interface, so I can easily change it.”

slide-102
SLIDE 102

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces
slide-103
SLIDE 103

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces
  • hard-coded paths everywhere
slide-104
SLIDE 104

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces
  • hard-coded paths everywhere

“I know how my environment and how my compiler is called.”

slide-105
SLIDE 105

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces
  • hard-coded paths everywhere
slide-106
SLIDE 106

Bazel How Bazel Works Open-Sourcing Summary

The Task of Open-Sourcing Bazel

Bazel became open-source only after years of internal use . . . on a single repository. (large, but just one)

  • lot of dependencies, including Google-specific ones
  • focus on the “Google languages” (and that built in)
  • no stable interfaces
  • hard-coded paths everywhere
  • . . .
slide-107
SLIDE 107

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

slide-108
SLIDE 108

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
slide-109
SLIDE 109

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
slide-110
SLIDE 110

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository

clear interfaces between bazel, and, e.g., Google’s use

slide-111
SLIDE 111

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
slide-112
SLIDE 112

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
slide-113
SLIDE 113

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
slide-114
SLIDE 114

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
slide-115
SLIDE 115

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
slide-116
SLIDE 116

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
  • remote execution API
slide-117
SLIDE 117

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
  • remote execution API
  • community repositories of Skylark rules
slide-118
SLIDE 118

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
  • remote execution API
  • community repositories of Skylark rules

Bazel more language agnostic tool

slide-119
SLIDE 119

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
  • remote execution API
  • community repositories of Skylark rules
slide-120
SLIDE 120

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
  • remote execution API
  • community repositories of Skylark rules
  • good story for remote repositories (including proper caching)
slide-121
SLIDE 121

Bazel How Bazel Works Open-Sourcing Summary

Bazel Roadmap

  • Big goal “1.0”. Properly open-source (expected 2018).
  • public primary repository
  • all design reviews public
  • core team consisting not only of Google employees
  • stable build language and APIs
  • On the way there, technical improvements
  • remote execution API
  • community repositories of Skylark rules
  • good story for remote repositories (including proper caching)
  • . . .
slide-122
SLIDE 122

Bazel How Bazel Works Open-Sourcing Summary

Summary

  • declarative BUILD files

. . . also supporting your own extensions

  • all dependencies tracked correctness

(sandboxes to ensure all I/O is known)

  • full knowledge enables fast builds

(caching of actions, remote execution, parallelism, . . . )

  • open-source
slide-123
SLIDE 123

Bazel How Bazel Works Open-Sourcing Summary

Try Bazel

Try Bazel yourself.

  • Homepage https://bazel.build/
  • Mailing lists
  • bazel-discuss@googlegroups.com
  • bazel-dev@googlegroups.com
  • Repository and issue tracker

https://github.com/bazelbuild/bazel

  • IRC #bazel on irc.freenode.net
  • Release key fingerprint

71A1 D0EF CFEB 6281 FD04 37C9 3D59 19B4 4845 7EE0 Thanks for your attention. Questions?