1. Your first project

To get a feel for the basics, we’ll start with the most basic BuildStream project we could think of.

Note

This example is distributed with BuildStream in the doc/examples/first-project subdirectory.

1.1. Creating the project

First, lets create the project itself using the convenience bst init command to create a little project structure:

user@host:~/first-project$ bst init --project-name first-project

Created project.conf at: /home/user/first-project/project.conf

This will give you a project.conf which will look like this:

1.1.1. project.conf

# Unique project name
name: first-project

# Required BuildStream format version
format-version: 21

# Subdirectory where elements are stored
element-path: elements

The project.conf is a central point of configuration for your BuildStream project.

1.2. Add some content

BuildStream processes directory trees as input and output, so let’s just create a hello.world file for the project to have.

user@host:~/first-project$ touch hello.world

1.3. Declare the element

Here we’re going to declare a simple import element which will import the hello.world file we’ve created in the previous step.

Create elements/hello.bst with the following content:

1.3.1. elements/hello.bst

kind: import

# Use a local source to stage our file
sources:
- kind: local
  path: hello.world

# Configure the import element
config:

  # Place the content staged by sources at the
  # root of the output artifact
  target: /

1.3.2. The source

The local source used by the hello.bst element, can be used to access files or directories which are stored in the same repository as your BuildStream project. The hello.bst element uses the local source to stage our local hello.world file.

1.3.3. The element

The import element can be used to simply add content directly to the output artifacts. In this case, it simply takes the hello.world file provided by its source and stages it directly to the artifact output root.

Tip

In this example so far we’ve used two plugins, the local source and the import element.

You can always browse the documentation for all plugins in the plugins section of the manual.

1.4. Build the element

In order to carry out the activities of the import element we’ve declared, we’re going to have to ask BuildStream to build.

This process will collect all of the sources required for the specified hello.bst and get the backing import element to generate an artifact for us.

user@host:~/first-project$ bst build hello.bst

[--:--:--][        ][ main:core activity                 ] START   Build
[--:--:--][        ][ main:core activity                 ] START   Loading elements
[00:00:00][        ][ main:core activity                 ] SUCCESS Loading elements
[--:--:--][        ][ main:core activity                 ] START   Resolving elements
[00:00:00][        ][ main:core activity                 ] SUCCESS Resolving elements
[--:--:--][        ][ main:core activity                 ] START   Resolving cached state
[00:00:00][        ][ main:core activity                 ] SUCCESS Resolving cached state
[--:--:--][        ][ main:core activity                 ] START   Checking sources
[00:00:00][        ][ main:core activity                 ] SUCCESS Checking sources

BuildStream Version 1.3.0+1587.g36a60abe.dirty
  Session Start: Tuesday, 19-02-2019 at 18:55:24
  Project:       first-project (/home/user/first-project)
  Targets:       hello.bst
  Cache Usage:   12K / None (0%)

User Configuration
  Configuration File:      /home/user/.config/buildstream.conf
  Cache Directory:         /home/user/.cache/buildstream
  Log Files:               /home/user/.cache/buildstream/logs
  Source Mirrors:          /home/user/.cache/buildstream/sources
  Build Area:              /home/user/.cache/buildstream/build
  Strict Build Plan:       Yes
  Maximum Fetch Tasks:     10
  Maximum Build Tasks:     4
  Maximum Push Tasks:      4
  Maximum Network Retries: 2

Pipeline
   buildable 375bcfe0caf81309afc635a4e370f398e90f2d7ef8a27da2ad1f7a7911b5c7f5 hello.bst 
===============================================================================
[--:--:--][375bcfe0][build:hello.bst                     ] START   first-project/hello/375bcfe0-build.836.log
[--:--:--][375bcfe0][build:hello.bst                     ] START   Staging sources
[00:00:00][375bcfe0][build:hello.bst                     ] SUCCESS Staging sources
[--:--:--][375bcfe0][build:hello.bst                     ] START   Caching artifact
[00:00:00][375bcfe0][build:hello.bst                     ] SUCCESS Caching artifact
[00:00:00][375bcfe0][build:hello.bst                     ] SUCCESS first-project/hello/375bcfe0-build.836.log
[00:00:00][        ][ main:core activity                 ] SUCCESS Build

Pipeline Summary
  Total:       1
  Session:     1
  Fetch Queue: processed 0, skipped 1, failed 0 
  Build Queue: processed 1, skipped 0, failed 0

Now the artifact is ready.

Using bst show, we can observe that the artifact’s state, which was reported as buildable in the bst build command above, has now changed to cached:

user@host:~/first-project$ bst show hello.bst

[--:--:--][        ][ main:core activity                 ] START   Loading elements
[00:00:00][        ][ main:core activity                 ] SUCCESS Loading elements
[--:--:--][        ][ main:core activity                 ] START   Resolving elements
[00:00:00][        ][ main:core activity                 ] SUCCESS Resolving elements
[--:--:--][        ][ main:core activity                 ] START   Resolving cached state
[00:00:00][        ][ main:core activity                 ] SUCCESS Resolving cached state
      cached 375bcfe0caf81309afc635a4e370f398e90f2d7ef8a27da2ad1f7a7911b5c7f5 hello.bst 

1.5. Observe the output

Now that we’ve finished building, we can checkout the output of the artifact we’ve created using bst artifact checkout

user@host:~/first-project$ bst checkout hello.bst here

This command is now obsolete. Use `bst artifact checkout` instead and use the --directory option to specify LOCATION

And observe that the file we expect is there:

user@host:~/first-project$ ls ./here

hello.world

1.6. Summary

In this section we’ve created our first BuildStream project from scratch, but it doesnt do much.

We’ve observed the general structure of a BuildStream project, and we’ve run our first build.