Skip to content

Instantly share code, notes, and snippets.

@aherrmann
Last active December 5, 2022 17:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aherrmann/da5db753b827ff013b09bdf691ec9827 to your computer and use it in GitHub Desktop.
Save aherrmann/da5db753b827ff013b09bdf691ec9827 to your computer and use it in GitHub Desktop.
Buck2-Bazel-differences
  • Starlark supports type annotations
  • Executable targets return RunInfo next to DefaultInfo. RunInfo can define the arguments (including inputs).
  • Buck2 has transitive-sets tset instead of depset. To use tsets you must define projections up-front on the specific transitive set type. Projections turn values in the tset into cmd_args or JSON values. Transitive sets also support reductions, which must also be defined up-front. And they support ad-hoc iteration, however, this is an escape hatch and has an O(set) performance penalty. At the moment the ordering is non-configurable.
  • Use cmd_args instead of ctx.actions.args to collect arguments to a command to run.
  • Use ctx.actions.run([..., input, output.as_output()]) instead of ctx.actions.run(..., inputs = .., outputs = ...). I.e. inputs and outputs are part of the cmd_args object.
    • cmd.hidden to add inputs and outputs that don’t appear in the command-line itself.
  • Prefer Python scripts for complex build actions over shell scripts. In particular, there is no ctx.actions.run_shell.
  • ctx.actions.download_file can be used to download a file in a regular build action.
  • Buck2 supports (scoped) dynamic dependencies via ctx.actions.dynamic_output.
  • Buck2 supports incremental actions, i.e. actions that take previous outputs as inputs.
  • Targets can define a default platform to build them for. C.f. this Bazel proposal proposing to add this to Bazel.
  • Build files are often called TARGET (for Buck v1&v2) or TARGET.v2 (for Buck v2 only) instead of BUILD. However, the name can be configured in .buckconfig.
  • Buck2 does not have external workspaces, instead it has "Cells". A Cell is a subdirectory of the project and can be referenced via a cell-alias that can be defined for each cell in .buckconfig.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment