Rajaram-Regupathy / libtypec

“libtypec” is aimed to provide a generic interface abstracting all platform complexity for user space to develop tools for efficient USB-C port management. The library can also enable development of diagnostic and debug tools to debug system issues around USB-C/USB PD topology.
34 stars 4 forks source link

cmake: make slightly easier to package #27

Open colemickens opened 9 months ago

colemickens commented 9 months ago

Hi,

I'm trying to package this for NixOS and having some issues around the utils executables.

  1. The cmake build by default doesn't include them, and they don't have cmake INSTALL support.
  2. They link directly against a relative path, which breaks them in Nix packaging.
Rajaram-Regupathy commented 8 months ago

resolved. Kindly confirm

colemickens commented 8 months ago

So far... with a naive-ish cmake build:

╭ zeph  ~/code/nixpkgs/libtypec  6sec 625ms ✘1
╰🡒  nix build .#legacyPackages.x86_64-linux.libtypec -L
warning: Git tree '/home/cole/code/nixpkgs/libtypec' is dirty
libtypec> unpacking sources
libtypec> unpacking source archive /nix/store/wzii1zxxmi5nh86gg7f3gaswxiyvqlzf-source
libtypec> source root is source
libtypec> patching sources
libtypec> updateAutotoolsGnuConfigScriptsPhase
libtypec> configuring
libtypec> fixing cmake files...
libtypec> cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/share/doc/libtypec -DCMAKE_INSTALL_INFODIR=/nix/store/id5wagkfm70fq20lhhmnbhkysq8qi8kd-libtypec-0.5.0-bin/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/id5wagkfm70fq20lhhmnbhkysq8qi8kd-libtypec-0.5.0-bin/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/include -DCMAKE_INSTALL_SBINDIR=/nix/store/id5wagkfm70fq20lhhmnbhkysq8qi8kd-libtypec-0.5.0-bin/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/id5wagkfm70fq20lhhmnbhkysq8qi8kd-libtypec-0.5.0-bin/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/90h6k8ylkgn81k10190v5c9ldyjpzgl9-gcc-wrapper-12.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/90h6k8ylkgn81k10190v5c9ldyjpzgl9-gcc-wrapper-12.3.0/bin/ranlib -DCMAKE_AR=/nix/store/90h6k8ylkgn81k10190v5c9ldyjpzgl9-gcc-wrapper-12.3.0/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/a2fwypvjib677yvccsfgj2gdq79lmapv-libtypec-0.5.0
libtypec> -- The C compiler identification is GNU 12.3.0
libtypec> -- The CXX compiler identification is GNU 12.3.0
libtypec> -- Detecting C compiler ABI info
libtypec> -- Detecting C compiler ABI info - done
libtypec> -- Check for working C compiler: /nix/store/90h6k8ylkgn81k10190v5c9ldyjpzgl9-gcc-wrapper-12.3.0/bin/gcc - skipped
libtypec> -- Detecting C compile features
libtypec> -- Detecting C compile features - done
libtypec> -- Detecting CXX compiler ABI info
libtypec> -- Detecting CXX compiler ABI info - done
libtypec> -- Check for working CXX compiler: /nix/store/90h6k8ylkgn81k10190v5c9ldyjpzgl9-gcc-wrapper-12.3.0/bin/g++ - skipped
libtypec> -- Detecting CXX compile features
libtypec> -- Detecting CXX compile features - done
libtypec> -- Configuring done (0.4s)
libtypec> -- Generating done (0.0s)
libtypec> CMake Warning:
libtypec>   Manually-specified variables were not used by the project:
libtypec>     BUILD_TESTING
libtypec>     CMAKE_EXPORT_NO_PACKAGE_REGISTRY
libtypec>     CMAKE_FIND_USE_PACKAGE_REGISTRY
libtypec>     CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY
libtypec>     CMAKE_POLICY_DEFAULT_CMP0025
libtypec>
libtypec> -- Build files have been written to: /build/source/build
libtypec> cmake: enabled parallel building
libtypec> cmake: enabled parallel installing
libtypec> building
libtypec> build flags: -j16 SHELL=/nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash
libtypec> [ 30%] Building C object CMakeFiles/libtypec.dir/libtypec.c.o
libtypec> [ 30%] Building C object CMakeFiles/libtypec.dir/libtypec_dbgfs_ops.c.o
libtypec> [ 30%] Building C object CMakeFiles/libtypec.dir/libtypec_sysfs_ops.c.o
libtypec> In file included from /build/source/libtypec_ops.h:36,
libtypec>                  from /build/source/libtypec_sysfs_ops.c:32:
libtypec> /build/source/libtypec.h:38:10: fatal error: libtypec_config.h: No such file or directory
libtypec>    38 | #include "libtypec_config.h"
libtypec>       |          ^~~~~~~~~~~~~~~~~~~
libtypec> In file included from /build/source/libtypec_ops.h:36,
libtypec>                  from /build/source/libtypec_dbgfs_ops.c:33:
libtypec> /build/source/libtypec.h:38:10: fatal error: libtypec_config.h: No such file or directory
libtypec>    38 | #include "libtypec_config.h"
libtypec>       |          ^~~~~~~~~~~~~~~~~~~
libtypec> compilation terminated.
libtypec> compilation terminated.
libtypec> make[2]: *** [CMakeFiles/libtypec.dir/build.make:104: CMakeFiles/libtypec.dir/libtypec_dbgfs_ops.c.o] Error 1
libtypec> make[2]: *** Waiting for unfinished jobs....
libtypec> make[2]: *** [CMakeFiles/libtypec.dir/build.make:90: CMakeFiles/libtypec.dir/libtypec_sysfs_ops.c.o] Error 1
libtypec> In file included from /build/source/libtypec.c:34:
libtypec> /build/source/libtypec.h:38:10: fatal error: libtypec_config.h: No such file or directory
libtypec>    38 | #include "libtypec_config.h"
libtypec>       |          ^~~~~~~~~~~~~~~~~~~
libtypec> compilation terminated.
libtypec> make[2]: *** [CMakeFiles/libtypec.dir/build.make:76: CMakeFiles/libtypec.dir/libtypec.c.o] Error 1
libtypec> make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/libtypec.dir/all] Error 2
libtypec> make: *** [Makefile:156: all] Error 2
Rajaram-Regupathy commented 8 months ago

Can we pls disable parallel build and confirm ?

colemickens commented 8 months ago

I explicitly disabled parallel building for the nix build, same error.

error: builder for '/nix/store/0wgiraav9pjcbgbkd5mzzv3r8wmdrrwl-libtypec-0.5.0.drv' failed with exit code 2;
       last 10 log lines:
       > build flags: SHELL=/nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash
       > [ 10%] Building C object CMakeFiles/libtypec.dir/libtypec.c.o
       > In file included from /build/source/libtypec.c:34:
       > /build/source/libtypec.h:38:10: fatal error: libtypec_config.h: No such file or directory
       >    38 | #include "libtypec_config.h"
       >       |          ^~~~~~~~~~~~~~~~~~~
       > compilation terminated.
       > make[2]: *** [CMakeFiles/libtypec.dir/build.make:76: CMakeFiles/libtypec.dir/libtypec.c.o] Error 1
       > make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/libtypec.dir/all] Error 2
       > make: *** [Makefile:156: all] Error 2
       For full logs, run 'nix log /nix/store/0wgiraav9pjcbgbkd5mzzv3r8wmdrrwl-libtypec-0.5.0.drv'.
Rajaram-Regupathy commented 8 months ago

Thanks. This looks a known cmake issue : https://cmake.org/pipermail/cmake/2018-July/067899.html. Is there steps you could pls share so that i could debug and fix it ? or Could you pls try a clean build single threaded and share the complete logs ?

colemickens commented 4 months ago

Hi. I really can't deal with cmake any more in my life, and don't know what's wrong. I've updated the package derivation attempt here: https://github.com/NixOS/nixpkgs/pull/270763

colemickens commented 4 months ago

If you checkout that PR and run this, you'll see the build failure I'm encountering. (This is the branch that nixpkgs PR is sent from):

nix build github:colemickens/nixpkgs?ref=libtypec#legacyPackages.x86_64-linux.libtypec

Rajaram-Regupathy commented 4 months ago

Added meson build method. hope that helps

colemickens commented 4 months ago

Initial feedback:

  1. The library is not configured to be installed, and I don't see meson's pkg-config support being utilized. Presumably you want to install the lib and/or configure pkg-config so other prospsective projects can find this via pkg-config.

  2. Similarly, the utils/meson.build is not set to "install" the executables.

From some discussion in our Matrix room:

  1. I think there should be a shared_executable invocation somewhere, and,
  2. the executable(s) should be using that....

(The net result with latest main revision is that when I build this with nixpkgs's meson, the derivation fails because nothing is in the output.)

I super appreciate you taking a crack at this. I'll try some ideas in my fork I opened, especially since you put all this effort in already.

10ne1 commented 1 month ago

Hello @colemickens

I think I fixed most of these issues with my latest contributions to the meson.builds if you want to try it again! Cheers!

10ne1 commented 1 month ago

Also the project now has a dedicated organization (it is still under Rajaram's maintainership): https://github.com/libtypec/libtypec

colemickens commented 2 weeks ago

afaict the meson isn't configured to output the pkg-config file, and neither build method declare a dep on udev, so it doesn't link correctly even if udev sources are discovered.