Bazel: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Created page with "Bazel is a tool that '''automates software builds and tests'''. Supported build tasks include running compilers and linkers to produce executable programs and libraries, and assembling deployable packages for Android, iOS and other target environments<ref>https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwix_f67rJqCAxUErlYBHc29CNkQFnoECAkQAw&url=https%3A%2F%2Fbazel.build%2Fabout%2Ffaq&usg=AOvVaw2LTedC5jnCi-zPHaBwVp9D&opi=89978449</re...")
 
 
(2 intermediate revisions by the same user not shown)
Line 18: Line 18:
== Tips and tricks ==
== Tips and tricks ==


* How to override the use of output when building with Bazel
=== How to override the use of output when building with Bazel ===
** The default output path is /tmp but depending on the version or default .bazelrc can be different output path, to override output path set <code>--output_base</code> to put all output in a non-default directory
* The default output path is /tmp but depending on the version or default .bazelrc can be different output path, to override output path set <code>--output_base</code> or --output_user_root to put all output in a non-default directory
** <code>bazel --output_base=/dir/path/you/want/to build //foo</code>
** <code>--output_base</code> startup option to override the default output base directory
** <code>--output_user_root</code> startup option to override the default install base and output base
* <code>bazel --output_base=/dir/path/you/want/to build //<whatever></code>
* <code>bazel --output_user_root=/dir/path/you/want/to build //<whatever></code>
 
* <code>bazel clean</code> does an <code>rm -rf</code> on the <code>outputPath</code> and the <code>action_cache</code> directory. It also removes the workspace symlinks. The <code>--expunge</code> option will clean the entire outputBase.<ref>https://bazel.build/remote/output-directories</ref>
 
=== Server terminated abruptly<ref>https://stackoverflow.com/questions/65605663/cannot-build-with-error-server-terminated-abruptly</ref> ===
 
* The most common cause we've seen for this kind of thing (can't say for sure without the <code>jvm.out</code>) is running out of memory which results in the OOM killer terminating the bazel server process.
** Using a lower <code>--jobs</code> is the most direct way to limit that.
** <code>--local_ram_resources</code> will help in theory, but bazel doesn't have a very good idea how much RAM each compilation command uses so it's very approximate.


== References ==
== References ==
<references />
<references />

Latest revision as of 08:35, 30 October 2023

Bazel is a tool that automates software builds and tests. Supported build tasks include running compilers and linkers to produce executable programs and libraries, and assembling deployable packages for Android, iOS and other target environments[1]

Install specific version of bazel

Bazel install page describes multiple way to install bazel, following is our preferred method for automated build scripts that uses various version of bazel depending on the projects.

#example version 6.3.2 
$export _version=6.3.2
$ wget https://github.com/bazelbuild/bazel/releases/download/$_version/bazel-$_version-installer-linux-x86_64.sh
$chmod +x bazel-$_version-installer-linux-x86_64.sh

# to install user only 
$./bazel-$_version-installer-linux-x86_64.sh --user

# to install system-wide  
$./bazel-$_version-installer-linux-x86_64.sh

Tips and tricks

How to override the use of output when building with Bazel

  • The default output path is /tmp but depending on the version or default .bazelrc can be different output path, to override output path set --output_base or --output_user_root to put all output in a non-default directory
    • --output_base startup option to override the default output base directory
    • --output_user_root startup option to override the default install base and output base
  • bazel --output_base=/dir/path/you/want/to build //<whatever>
  • bazel --output_user_root=/dir/path/you/want/to build //<whatever>
  • bazel clean does an rm -rf on the outputPath and the action_cache directory. It also removes the workspace symlinks. The --expunge option will clean the entire outputBase.[2]

Server terminated abruptly[3]

  • The most common cause we've seen for this kind of thing (can't say for sure without the jvm.out) is running out of memory which results in the OOM killer terminating the bazel server process.
    • Using a lower --jobs is the most direct way to limit that.
    • --local_ram_resources will help in theory, but bazel doesn't have a very good idea how much RAM each compilation command uses so it's very approximate.

References