The Boost.Build System

The Boost.Build System

The Boost.Build System Vladimir Prus Computer Systems Laboratory Moscow State University, CS department Moscow, Russia [email protected] Abstract—Boost.Build is a new build system with unique build properties without full rebuild. Such change may approach to portability. This paper discusses the underlying happen at three levels: requirements, the key design decisions, and the lessons learned during several years of development. We also review other a) Between different parts of the project. The simplest contemporary build systems, and why they fail to meet the same example is compiling a specific source file with an requirements. additional compiler option. More complex example is building a specific module as a static library, and I. INTRODUCTION another as a shared library. It should be possible to For software projects using compiled languages (primarily change every aspect of the build process — even C and C++), build system is the key element of infrastructure. including the used compiler. Mature tools such as GNU Make[?] or GNU Automake[?] b) Between different builds. For example, one may exist. However, those tools are relatively low level, and hard originally build a project in release mode for test- to master. They also have limited portability. For that reason, ing and, after discovering a bug, wish to initiate many software project do custom work on build system level. a build in debug mode. It would be wasteful to One such project is C++ Boost [?]. remove the previously built object files, so the C++ Boost is a popular collection of C++ libraries, many build system must arrange for debug and release of which are either included in the next revision of the C++ products to be placed in different directories. The Standard or planned for inclusion[?], [?]. This unique position mechanism should not be restricted to just debug attracts a lot of users, who, in turn, use a wide variety of and release builds, but apply to any build proper- operating systems and differently-configured environments. ties. This differs from most commercial projects — which target c) Within one build. This means that one invocation a few platforms that are important from business perspective, of the build system may produce several variants and are built in a well-controlled environment. This is also of a build product — for example, static and shared different from most open-source projects — which tend to versions of the same library. focus on GNU/Linux environment. Developers’ background This paper describes Boost.Build[?] — a build system devel- also considerably differs — a person who is expert in C++ is oped to meet the above requirements. Section 2 will describe not necessary an expert in different operating systems. key concepts and mechanisms of Boost.Build. In section 3 we This diversity in user and developer base lead to the review the lessons learned during development as well as some following requirements for a build system: unexpected drawbacks. Section 4 discusses other contempo- 1) “Write once, build everywhere”. If a library builds on arXiv:1208.6264v1 [cs.SE] 30 Aug 2012 rary build tools, and why they could not be used. Section one platform, it should be very likely that it builds on all 5 summarizes the article and suggests future development other platforms supported by the build system. It follows directions. that build description should be relatively high-level, and avoid any system- or compiler- specific details, such as II. DESIGN CONCEPTS file extensions, compiler options or command-line shell The best way to explain the key design elements of syntax details. Boost.Build is by following a few steps of gradual refinements, 2) Extensibility. Adding support for a new compiler or a starting from a classic tool — GNU Make. In GNU Make, a platform should not require changing build system core user directly defines a set of targets, where a target is an object or build descriptions for individual libraries. Ideally, user that has: would have to write a new module and provide it to the • a name build system. • a set of dependency targets 3) Multiple variants. The build system may not require that • a command to build the target the build properties for the entire project are specified Consider this example: up-front, during special “configure” step, and then re- quire that all build products be removed before changing a.o: a.c build properties. Instead, it should be possible to change g++ -o a.o -g a.c Here, the name of the target is a.o, the only dependency For example, every generator in Boost.Build accepts a pa- is a target named a.c, and the command invokes the gcc rameter named optimization, with none, speed and compiler. Given the set of targets defined in a build description space as possible values. Consequently, the example might file (“buildfile” for short), GNU Make identifies targets that are be modified as follows: out of date with respect to their dependencies, and invokes the library(helper, helper.c, commands specified for such targets. The description shown optimization=space) above has two problems. First, the names of the targets and This change addresses requirement 1 (“write once, build the exact commands typically may vary depending on environ- everywhere”). ment, and should not be hardcoded. This problem is typically The second key observation is that differences between solved using variables — in the example below, the OBJEXT platforms are so significant that creating a single generic gen- and CFLAGS variables may be defined as appropriate for erator such as library is hard. Obviously, small behaviour platform. differences can be handled in an ad-hoc way — for example a.$(OBJEXT): a.c by introducing a global variable set by platform-specific code g++ -o a.o $(CFLAGS) a.c and checked by the generator. However, in existing tools there While this makes build description more flexible, it also makes are dozens of such variables, with the generator still containing it rather verbose, and hard to write. Second, depending on significant platform specific logic. More systematic approach build variant and platform, even the set of targets may vary. For is needed. To that end, Boost.Build allows several generators example, depending on platform and desired linking method, to exist, and uses a dispatching function to select the generator building a library might produce from 1 to 4 files. Obviously, to use. In example below: conditionally defining 4 targets for every library is extremely library(helper, helper.c, cumbersome. link=shared) Modern build systems do not require that user describes the description written by the user looks the same as before. concrete targets, but provide a set of generator functions, or However, the library function is no longer responsible for generators for short. A generator is called with the name of constructing targets. Instead, it merely selects and invokes a primary target, a list of sources, and other parameters, and platform-specific generator. This generator need only deal with produces a set of concrete targets. Sometimes, these concrete a single platform, and can be easily implemented. The specific targets are GNU Make targets. Sometimes, a different low- generator selection algorithm (that will be described below) al- level build engine is used. For example, a library might be lows new generators to be defined in platform-specific modules 1 defined like this : and automatically participate in generator selection, thereby library(helper, helper.c) addressing requirement 2 (“extensibility”). It should be noted This statement calls a function library that constructs the that recursive calls are common — for example, the library set of concrete targets that is suitable for the target platform — generator might use the object generator. In Boost.Build, which may include the library file proper, import library, and the dispatching function is also used for such recursive calls, various manifest files. The compiler and linker options are also allowing for fine-grained customization. derived from both the platform and the way the build system The third key observation is that if a build description is was configured. Thus, the user-written build description does allowed to call a dispatching function when the build descrip- not include any platform-specific details. Instead, such details tion is parsed, it severely limits the possibilities to further are handled by the build system, which is separately main- build the same part of a project with different properties. To tained. Boost.Build also uses a similar description mechanism, address this issue Boost.Build introduces metatargets — which but advances it further. are essentially closure objects. Consider an example using the First key observation is that using generators is not sufficient actual Boost.Build syntax: to achieve portability. Requirements listed in section 1 include lib helper : helper.cpp ; using different build properties for different parts of the This statement defines a closure of the dispatching function, project. This can be achieved using additional parameters binding the name and the sources list. If we invoke Boost.Build to generators. But if the set of those parameters, or their from the command line using the following command: values, is either incomplete, or depends on platform, the build $ b2 toolset=gcc variant=debug description is not portable. To achieve the portability goals, link=shared Boost.Build defines a large set of build parameters with the following characteristics: then the closure object will be called with the specified build parameters. The toolset=gcc and link=shared • Every generator accepts the same set of build parameters parameters uniquely specify a generator — gcc.link.dll • The names of build parameters and their values are the — that is called to produce the concrete targets. In the example same everywhere below, we request a two-variant build: 1For presentation purposes, we have abstracted away the syntax of modern $ b2 toolset=gcc link=shared -- build systems.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us