Skip to content

Conversation

@trofi
Copy link
Contributor

@trofi trofi commented Oct 15, 2024

Without the change dmenu fails to build on staging-next as:

$ nix build --no-link -f. dmenu -L
...
dmenu> build flags: SHELL=/nix/store/mm0pa3z7kk6jh1i9rkxqxjqmd8h1qpxf-bash-5.2p37/bin/bash CC:=\$\(CC\)
dmenu> cp config.def.h config.h
dmenu> gcc -c -std=c99 -pedantic -Wall -Os -I/usr/X11R6/include -I/usr/include/freetype2 -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"5.3\" -DXINERAMA dmenu.c
dmenu> In file included from dmenu.c:17:
dmenu> /nix/store/2rxphcg0qabc3a8c4lvy610sm03bh72y-libXft-2.3.8-dev/include/X11/Xft/Xft.h:40:10: fatal error: ft2build.h: No such file or directory
dmenu>    40 | #include <ft2build.h>
dmenu>       |          ^~~~~~~~~~~~
dmenu> compilation terminated.
dmenu> make: *** [Makefile:12: dmenu.o] Error 1

The change uses pkg-config to discover library dependencies and lib paths.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Without the change `dmenu` fails to build on `staging-next` as:

    $ nix build --no-link -f. dmenu -L
    ...
    dmenu> build flags: SHELL=/nix/store/mm0pa3z7kk6jh1i9rkxqxjqmd8h1qpxf-bash-5.2p37/bin/bash CC:=\$\(CC\)
    dmenu> cp config.def.h config.h
    dmenu> gcc -c -std=c99 -pedantic -Wall -Os -I/usr/X11R6/include -I/usr/include/freetype2 -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"5.3\" -DXINERAMA dmenu.c
    dmenu> In file included from dmenu.c:17:
    dmenu> /nix/store/2rxphcg0qabc3a8c4lvy610sm03bh72y-libXft-2.3.8-dev/include/X11/Xft/Xft.h:40:10: fatal error: ft2build.h: No such file or directory
    dmenu>    40 | #include <ft2build.h>
    dmenu>       |          ^~~~~~~~~~~~
    dmenu> compilation terminated.
    dmenu> make: *** [Makefile:12: dmenu.o] Error 1

The change uses `pkg-config` to discover library dependencies and lib paths.
@trofi
Copy link
Contributor Author

trofi commented Oct 15, 2024

The build on staging-next depends on the prerequisite:

@trofi trofi mentioned this pull request Oct 15, 2024
13 tasks
Comment on lines 31 to 39
preConfigure = ''
sed -i "s@PREFIX = /usr/local@PREFIX = $out@g" config.mk
makeFlagsArray+=(
PREFIX="$out"
CC="$CC"
# default config.mk hardcodes dependent libraries and include paths
INCS="`$PKG_CONFIG --cflags fontconfig x11 xft xinerama`"
LIBS="`$PKG_CONFIG --libs fontconfig x11 xft xinerama`"
)
'';
Copy link
Member

@emilazy emilazy Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be possible to use a Nix makeFlags variable here with PREFIX=$(out), INCS=$(shell $PKG_CONFIG …), etc., though it’s possible that would require __structuredAttrs because of the spaces.

Copy link
Member

@Shados Shados Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change also breaks dmenu patches that introduce additional dependent libraries, as they usually just patch the libs into the config.mk directly. A better approach might be to just pass X11INC, X11LIB, and FREETYPEINC as buildFlags, no modification of config.mk required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's not perfect. Are any of these patches in nixpkgs so we could test them? Or they are all external? (I would like to stare at the example modifications as well)

The X11INC and X11LIBS are not passed as is but are prefixed with -I/-L. That makes it awkward to just pass pkg-config resolution there:

$ cat config.mk
...
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
XINERAMALIBS  = -lXinerama
XINERAMAFLAGS = -DXINERAMA
FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = /usr/include/freetype2
INCS = -I$(X11INC) -I$(FREETYPEINC)
LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)

CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
CFLAGS   = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS)
LDFLAGS  = $(LIBS)

We need a place to inject the include paths to freetype, xinerama and xft somewhere. Unfortunately none of the config.mk variables are great for that. I would expect that adding extra libraries in patches would still require you to pass header files explicitly via makeFlags or via NIX_CFLAGS_COMPILE. But nixpkgs clobber makes it even worse.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of these patches in nixpkgs so we could test them? Or they are all external? (I would like to stare at the example modifications as well)

I don't think any are in nixpkgs directly, but plenty are listed on dmenu's page.

@ofborg ofborg bot requested review from 0david0mp, Qusic, globin and pSub October 15, 2024 22:58
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Oct 15, 2024
@K900 K900 merged commit 3e2fe0e into NixOS:staging-next Oct 16, 2024
38 of 39 checks passed
@trofi trofi deleted the dmenu-build-fix branch October 16, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants