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 nixpkgs/pkgs/applications/science/biology/dcm2niix/dont-fetch-external-libs.patch at e5f1b02bd52e64494c61c0948fb61f70e8cfaa34 · NixOS/nixpkgs · GitHub

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)
    URL               https://github.com/Tencent/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz
    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: