bfgroup / b2

B2 makes it easy to build C++ projects, everywhere.
https://www.bfgroup.xyz/b2/
Boost Software License 1.0
76 stars 228 forks source link

Bootstrap procedure writes to source directory #339

Closed iskunk closed 9 months ago

iskunk commented 11 months ago

This issue was originally reported against bootstorg/build, but at that project's request has been transferred here.

Environment and version details

Problem description

If the source tree (/tmp/boost_1_83_0/ in this example) is read-only, and we operate from a separate writable build directory (/tmp/boost-build/), then guessing the toolset fails as follows:

skunk@darkstar:/tmp/boost-build$ /tmp/boost_1_83_0/tools/build/src/engine/build.sh --verbose --guess-toolset
> g++ -x c++ -std=c++11  check_cxx11.cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status
> g++ -x c++ -std=c++11 -D_GNU_SOURCE  check_cxx11.cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status
> g++ -x c++ -std=c++11 -pthread  check_cxx11.cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status
> clang++ -x c++ -std=c++11  check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: clang++: not found
> xlC_r   check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: xlC_r: not found
> pgc++ -std=c++11  check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: pgc++: not found
> pathCC   check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: pathCC: not found
> como   check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: como: not found
> bc++ -tC -q  check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: bc++: not found
> aCC -AA  check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: aCC: not found
> /opt/SUNWspro/bin/CC -std=c++11  check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: /opt/SUNWspro/bin/CC: not found
> cxx   check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: cxx: not found
> cpp   check_cxx11.cpp
cc1plus: fatal error: opening output file check_cxx11.cpp: Permission denied
compilation terminated.
> CC   check_cxx11.cpp
/tmp/boost_1_83_0/tools/build/src/engine/build.sh: 120: CC: not found

Could not find a suitable toolset.

You can specify the toolset as the argument, i.e.:
    ./build.sh [options] gcc

Toolsets supported by this script are:
    acc, clang, como, gcc, intel-darwin, intel-linux, kcc, kylix, mipspro,
    pathscale, pgi, qcc, sun, sunpro, tru64cxx, vacpp

For any toolset you can override the path to the compiler with the '--cxx'
option. You can also use additional flags for the compiler with the
'--cxxflags' option.

A special toolset; cxx, is available which is used as a fallback when a more
specific toolset is not found and the cxx command is detected. The 'cxx'
toolset will use the '--cxx' and '--cxxflags' options, if present.

Options:
    --help                  Show this help message.
    --verbose               Show messages about what this script is doing.
    --debug                 Build b2 with debug information, and no
                            optimizations.
    --guess-toolset         Print the toolset we can detect for building.
    --cxx=CXX               The compiler exec to use instead of the detected
                            compiler exec.
    --cxxflags=CXXFLAGS     The compiler flags to use in addition to the
                            flags for the detected compiler.

If I make the source tree writable, then the same command succeeds:

skunk@darkstar:/tmp/boost-build$ /tmp/boost_1_83_0/tools/build/src/engine/build.sh --verbose --guess-toolset
> g++ -x c++ -std=c++11  check_cxx11.cpp
gcc

The configuration and build procedure must not write to the source tree in any way. Not only could the source tree be mounted read-only in one of various ways (NFS, Docker volume mount, ISO/SquashFS image, etc.), source tree timestamps are often used to set SOURCE_DATE_EPOCH in reproducible builds and writing to the source tree wrecks that.

Whatever scratch space is needed by these scripts should come from the build directory or $TMPDIR.

grafikrobot commented 9 months ago

It is really difficult to provide an out-of-source build of B2 that works across the various compilers and operating systems. Hence it has never been attempted. Nor is likely to be attempted. If your goal is to build Boost in an out-of-source manner my suggestion would be to build B2 separately, i.e. copy it to a writable location, then install it. And use that installed version for building Boost. Note that the current version of B2 should work to build any version of Boost from 1.66 onward.