I'm trying to add ddtrace python package to nixpkgs which depends on cmake code and need some help

So I’m trying to add ddtrace package to nixpkgs package.

Generally this process is straight forward, but the package depends on libddwaf library. That library uses cmake to build, and that cmake also downloads other dependencies.

My problem is that I’m new to cmake, and I see that nixpkgs have some routines for handling it, but it is hard to find them when I don’t know what I’m looking for. Don’t know if that’s the case with cmake, but there are also packages that were created a while ago and might be do things wrong way etc.

I guess my question is, is there a good package that might be using cmake in similar way so I could use it as a guide?

Generally the steps are the following:

  • add cmake to nativeBuildInputs
  • patch or configure out the downloading from the internet

Thank you, but the 2nd point is what I’m struggling with. What is the recommended way of doing it?
I saw different approaches in nixpkgs.

and there likely are others

The problem is that almost every package does things differently.

I think of trying the last one, since it seems clearest what’s going on, but I don’t know if that’s the best way.

thats probably because every package is a little bit different but I think if just removing the vendoring parts is not working and you are not firm enough in cmake to add the right system commands I would recommend to use https://github.com/NixOS/nixpkgs/blob/e5f1b02bd52e64494c61c0948fb61f70e8cfaa34/pkgs/applications/science/biology/dcm2niix/dont-fetch-external-libs.patch

I’m still struggling.

How would you recommend replacing rapidjson with the one in nixpkgs (hopefully I can use that one):

set(RAPIDJSON_COMMIT 22a62fcc2c2fa2418f5d358cdf65c1df73b418ae)
ExternalProject_Add(proj_rapidjson
    URL               https://github.com/Tencent/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz
    INSTALL_DIR       ${INSTALL_DIR}
    CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
               -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
               -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
               -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
               -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
               -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
               -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
               -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
    BUILD_COMMAND     ""
    INSTALL_COMMAND   ${CMAKE_COMMAND} -E copy_directory "<SOURCE_DIR>/include/" "<INSTALL_DIR>/include/"
)
add_library(lib_rapidjson INTERFACE IMPORTED GLOBAL)
target_include_directories(lib_rapidjson INTERFACE ${INSTALL_DIR}/include)
add_dependencies(lib_rapidjson proj_rapidjson)
target_compile_definitions(lib_rapidjson INTERFACE RAPIDJSON_HAS_STDSTRING=1)
set_target_properties(proj_rapidjson PROPERTIES EXCLUDE_FROM_ALL TRUE)

the entire file

Disclaimer: I’m not an expert in cmake, just packaged a couple of cmake-based packages.

Hello. I see two ways of dealing with this particular cmake build. If custom build of rapidjson with ExternalProject_Add is essential, you can patch this call to supply SOURCE_DIR with predownloaded sources thus skipping download step.
If custom build is not necessary, you can completely remove ExternalProject_Add call, and rewrite add_library(lib_rapidjson INTERFACE IMPORTED GLOBAL) so that it uses shared library instead. This shared library will come from nixpkgs using buildInputs attribute.
Relevant docs:
https://cmake.org/cmake/help/latest/command/add_library.html#imported-libraries
https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add