Skip to content

Instantly share code, notes, and snippets.

@jbott
Last active March 11, 2024 08:28
Show Gist options
  • Save jbott/2030c133509e7c1db4f41941b5367475 to your computer and use it in GitHub Desktop.
Save jbott/2030c133509e7c1db4f41941b5367475 to your computer and use it in GitHub Desktop.
Building falood/file_system mac_listener in a nix environment

Building the Elixir package falood/file_system mac_listener binary in a nix environment

This confused me, so I'm documenting my workaround, which is probably not the correct workaround, but it seemed to work (leaving non-persistent state, lol).

When in a shell with mix and clang provided via nix, the file_system package fails to build the mac_listener binary via clang, with the error (reproduced in a shell):

$ clang -framework CoreFoundation -framework CoreServices -Wno-deprecated-declarations c_src/mac/*.c -o priv/mac_listener
In file included from c_src/mac/cli.c:2:
In file included from c_src/mac/cli.h:4:
c_src/mac/common.h:5:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from c_src/mac/compat.c:1:
c_src/mac/compat.h:16:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from c_src/mac/main.c:1:
c_src/mac/common.h:5:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

This binary only needs to be built once, and can be created in the priv directory of the compiled dep via:

$ nix-shell -p darwin.apple_sdk.frameworks.CoreServices --run "clang -framework CoreFoundation -framework CoreServices -Wno-deprecated-declarations c_src/mac/*.c -o priv/mac_listener

This constructs a shell env with the necessary CoreServices framework in the sandbox so the build can succeed. If there's a better way to do this (or have this work automatically via mix deps.get, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment