Overriding the CMake build step

I am trying to snap an application that is built using cmake.

Unfortunately, building it using the default behaviour of the cmake plugin would not work. So, I have to use the override-build functionality for the build step.

But I was not able to find the best way to imitate the default behaviour. I let the pulled files at the location they were automatically pulled to by the default behaviour of the pull step and passed this path to the cmake command using the environment variables. Is this the recommended way, or should I copy the pulled repository to the install directory?

My next issue is that I do not know where I am supposed to put the compiled binary from the build step. Should I manually copy it to the CRAFT_PART_INSTALL directory? Or is it automatically put there?

Should I manually copy it to the CRAFT_PART_INSTALL directory?

Yes, this is probably the best path forward. Something cp <artifact> $CRAFT_PART_INSTALL/ will get the artifact in the part’s install directory, which will then get staged and primed.

If you share your snapcraft.yaml, we may be able to provide an alternative solution. For example, if you’re using override-build and not calling craftctl default, then you may be better off just using the nil plugin.

So, it is probably a bit too steep for a beginner but I tried to snap clangd, as the existing package is very outdated…

Anyways, my snapcraft.yaml part looks like this at the moment:

parts:
  my-part:
    plugin: cmake
    source: https://github.com/llvm/llvm-project.git
    source-depth: 1
    override-build: |
      cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" $CRAFT_PART_SRC/llvm/
      cmake --build . --target clangd

Building actually does not fail and using the --shell-after flag I could actually see that the built binary is in /parts/my-part/build/bin, and it is at least able to print its version.

But I am unsure how to proceed from here. I know I have to expose this binary eventually, but I guess I am not there yet. I still need to get my artifact through the stage and the prime phase, right?

Thanks. One option would be:

parts:
  my-part:
    plugin: dump
    source: https://github.com/llvm/llvm-project.git
    source-depth: 1
    override-build: |
      cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" $CRAFT_PART_SRC/llvm/
      cmake --build . --target clangd
      cp -r bin $CRAFT_PART_INSTALL/bin 

You still may be able to use the cmake plugin. The --target clangd part is the a problem. That wouldn’t work since craft-parts hardcodes the target to install. If --target install works, then you could experiment with something like:

parts:
  my-part:
    plugin: cmake
    source: https://github.com/llvm/llvm-project.git
    source-depth: 1
    cmake-parameters: 
      - -DCMAKE_BUILD_TYPE=Release
      - -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
      - $CRAFT_PART_SRC/llvm/