rules_closure icon indicating copy to clipboard operation
rules_closure copied to clipboard

Disable default externs

Open jart opened this issue 8 years ago • 0 comments

Closure Compiler by default is --env=BROWSER which causes 28,606 lines of @externs code to be added to each compilation. This has a four second impact on compilation time. It can't really be optimized away because externs aren't namespaced. So we'd be better off if we:

  1. Only load es{3,5,6}.js by default, depending on the input language.
  2. Define a closure_js_library for each browser externs file, e.g. //closure/externs/browser:html5
  3. Update //closure/library to have the minimum number of deps on these externs. Break hard edges if possible. For example, if only one .js file in Closure Library depends on the gigantic webgl.js externs, then maybe that part of Closure Library should be broken out into a separate build rule.
  4. Define a combined //closure/externs/browser rule for the lazy, that basically exports all the libraries in the package. Adding that as a dep will be equivalent to saying --env=BROWSER.
  5. Repeat for contrib externs, e.g. //closure/externs/contrib/angular:v1_5, as per #51.
  6. Write a file_test() that checks the directory listing of externs.zip so Closure Rules maintainers integrating a compiler new release can be informed when they need to update our externs rules.

This is a breaking change that deviates from the design chosen by the Closure Compiler team. I think this is a good idea for two reasons:

  1. It makes compiles go four seconds faster.
  2. It will teach new users about externs.

If the user gets an error saying, "hey! document is undefined. you probably want to depend on @io_bazel_rules_closure//closure/externs/browser:window!" Then he's going to wonder what externs are. He'll read the file. See how Closure rigorously defines type information for everything—even code that isn't in the compilation. And then he's going to begin to understand the Closure Compiler and why it is good.

Blocked by: #80

jart avatar May 28 '16 19:05 jart