Bazel: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
Line 20: Line 20:
* 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> or --output_user_root 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>--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_base=/dir/path/you/want/to build //<whatever></code>
** <code>bazel --output_user_root=/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>


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

Revision as of 14:40, 29 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]

References