0

I'm trying to speed up build process using ramdisk for build directory.

I've created ramdisk:

sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk

On ramdisk I've created build dir:

mkdir -p /mnt/ramdisk/rust/hello3/build/

Then I've symlinked ramdisk build dir to project in which I want to use this directory:

cd /home/wakatana/rust/hello3
ln -s /mnt/ramdisk/rust/hello3/build/ build

After this I did classic combo for building project:

cd /home/wakatana/rust/hello3/build
cmake ..
make

But above command does not worked because relative path (cmake ..) is translated to /mnt/ramdisk/rust/hello3 and not to /home/wakatana/rust/hello3/ (I suspect that this is whole problem)

So instead of classic combo I did a little bit modified combo (when build dir is not symlinked this works):

cd /home/wakatana/rust/hello3/build
cmake /home/wakatana/rust/hello3
make

But this ends up with errors during make phase:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/wakatana/rust/hello3/build
make[2]: *** No rule to make target '../src/lib.rs', needed by 'src/x86_64-unknown-linux-gnu/debug/libtest_lib.a'.  Stop.
CMakeFiles/Makefile2:122: recipe for target 'src/CMakeFiles/test-lib_target.dir/all' failed
make[1]: *** [src/CMakeFiles/test-lib_target.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Is it possible to somehow tell to cmake/make to deal symlinks correctly?

Wakan Tanka
  • 7,542
  • 16
  • 69
  • 122
  • So why not `cd /home/wakatana/rust/hello3 && cmake -S. -B/mnt/ramdisk/rust/hello3/build/ && cmake --build /mnt/ramdisk/rust/hello3/build/`? – KamilCuk Oct 09 '20 at 07:41
  • This worked as expected. Thank you very much. Please post it as answer co I can accept it. One little node instead of `cmake -S.` I have to use `cmake -S .` – Wakan Tanka Oct 09 '20 at 08:44
  • Ugh, that cmake option parsing. – KamilCuk Oct 09 '20 at 08:48

2 Answers2

0

Just save yourself the trouble of creating symlinks and work on the ram disc:

cmake -S /home/wakatana/rust/hello3 -B /mnt/ramdisk/rust/hello3/build/
cmake --build /mnt/ramdisk/rust/hello3/build/

You could create the symlink, and then work from parent dir:

ln -s /mnt/ramdisk/rust/hello3/build/
cd /home/wakatana/rust/hello3 
cmake -S .  -B build
cmake --build build
# or expand the symlink before cmake has to:
cmake -S .  -B "$(readlink -f "./build")"
cmake --build "$(readlink -f "./build")"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
0

The other way is to rebind your RAM disk into your project tree instead of symlinking:

$ cd /home/wakatana/rust/hello3
$ mkdir -p build
$ mount --bind /mnt/ramdisk/rust/hello3/build build
zaufi
  • 6,811
  • 26
  • 34