Skip to content
ajohns edited this page Mar 8, 2017 · 22 revisions

Overview

Rez packages can be built and locally installed using the rez-build tool. This tool performs the following actions:

  • Iterates over a package's variants;
  • Constructs the build environment;
  • Runs the build system within this environment.

Each build occurs within a build path - this is typically either a build subdirectory, or a variant-specific subdirectory under build. For example, a package with two python-based variants might look like this:

+- package.py
+- CMakeLists.txt (or other build file)
+-build
  +-python-2.6  # build dir for python-2.6 variant
  +-python-2.7  # build dir for python-2.6 variant

The current working directory is set to the build path during a build.

The Build Environment

The build environment is a rez resolved environment. Its requirement list is constructed like so:

  • First, the package's requires list is used;
  • Then, the package's build_requires is appended. This is transitive - the build_requires of all other packages in the environment are also used;
  • Then, the package's private_build_requires is appended (unlike build_requires, it is not transitive).
  • Finally, if the package has variants, the current variant's requirements are appended.

A standard list of environment variables is also set (all prefixed with REZ_BUILD_) - you can see the full list here.

The build system is then invoked within this environment, for each variant.

The Build System

Rez supports multiple build systems, and new ones can be added as plugins. When a build is invoked, the build system is detected automatically. For example, if a CMakeLists.txt file is found in the package's root directory, the cmake build system is used.

Argument Passing

There are two ways to pass arguments to the build system.

First, some build system plugins add extra options to the rez-build command directly. For example, if you are in a CMake-based package, and you run rez-build -h, you will see cmake-specific options listed, such as --build-target.

Second, you can pass arguments directly to the build system - either using the rez-build --build-args option; or listing the build system arguments after --.

Custom Build Commands

As well as detecting the build system from build files, a package can explicitly specify its own build commands, using the build_command package attribute. If present, this takes precedence over other detected build systems.

For example, consider the following package.py snippet:

name = "nuke_utils"

version = "1.2.3"

build_command = "bash {root}/build.sh"

When rez-build is run on this package, the given build.sh script will be executed with bash. The {root} string expands to the root path of the package (the same directory containing package.py).

The current working directory during a build is set to the build path, not to the package root directory. For this reason, you will typically use the {root} string to refer to a build script in the package's root directory.