facebook / watchman

Watches files and records, or triggers actions, when they change.
https://facebook.github.io/watchman/
MIT License
12.57k stars 986 forks source link

Pass DYLD_LIBRARY_PATH environment variable to plist when launching watchman via launchctl #1059

Closed leoasis closed 1 year ago

leoasis commented 1 year ago

Hi!

We want to use watchman in an environment that prefers to keep commands and its resources colocated in their folders, which led us to have to execute watchman with a wrapper script that uses DYLD_LIBRARY_PATH with the value set to the path where the /lib folder is located.

This works great whenever we run the command with --no-site-spawner, but when using launchctl we see that the plist that's generated doesn't pass that environment variable through so the server cannot start properly as it can't find the library files.

Would it be possible to consider writing this variable in the plist file whenever it's set?

junoatwork commented 1 year ago

Specifically, in main.cpp where the launchctl plist is generated: https://github.com/facebook/watchman/blob/827332086f7bb13b63bf7456527bf443c233d019/watchman/main.cpp#L543-L549

Currently it passes through the PATH env var. Additionally, it could pass through the DYLD_LIBRARY_PATH if present.

carlocab commented 1 year ago

Instead of relying on DYLD_LIBRARY_PATH, consider passing

-DCMAKE_INSTALL_RPATH=/path/to/your/lib

or

-DCMAKE_INSTALL_NAME_DIR=/path/to/your/lib

to your CMake invocation when building Watchman from source instead.

DYLD_LIBRARY_PATH is definitely not something you want to rely on: Apple clears it from the environment when running executables protected by SIP, and it could cause processes spawned by watchman to misbehave. If you really must use an environment variable, try DYLD_FALLBACK_LIBRARY_PATH instead.

junoatwork commented 1 year ago

Thanks for commenting - @leoasis I think we can close this issue.