Try compiling watchman

Raphael Thomazella
FotonTech
Published in
3 min readDec 3, 2018

If you use Jest or react-native, you’ve probably heard of Facebook’s watchman https://facebook.github.io/watchman/

It’s a file watcher and a dependency of many popular open source projects.So odds are, if you’re reading this, you’ve heard of it before.

Does it work for you?

Watchman’s logo

When I first tried using watchman on my Mac, it just didn’t work very well. 🤔 and my developer friends all had problems. Turns out I found a nice way to fix it for me, and maybe for you too! 🌈 🎇😊

Building watchman

We normally download a default binary for watchman, that is configured for us. We’ll be making our own, and changing one key configuration.

- Official instructions, In case you want to take a look.

Are here: https://facebook.github.io/watchman/docs/install.html#installing-from-source

- Homebrew

We’ll need homebrew, head over to https://brew.sh and install it, if you haven’t already.

- Uninstall watchman

Remove your current version of watchman, if you have one. With brew you’d do:

brew rm watchman

- Install xcode command line tools

Not needed if you have xcode installed.

xcode-select — install

Accept the popup.

- Install build tools

brew install autoconf automake libtool

Also install git if you don’t have it

brew install git

- Get the files

`cd` to some temporary location, like your desktop.

git clone https://github.com/facebook/watchman.git

cd watchman

git checkout v4.9.0

👆🏻 use a newer release if there is one. Check here: https://github.com/facebook/watchman/releases

Now I’ve had problems with `BASH_ENV` to run this next step, so we’ll unset it. It’ll only affect the current terminal tab, and if you don’t have it set, it’ll do nothing.

unset BASH_ENV

Now let’s run the first script. In the repo folder:

./autogen.sh

Now do a `ls` and look for a `configure` file.

If it’s not there something didn’t work with autogen 😕 You can ask for help in the official issues: https://github.com/facebook/watchman/issues

For the next step we’ll configure watchman using the options:

- no python (if you need python support don’t use this flag)

- no pcre (if you need pcre support don’t use this flag)

- state file in our home under `~/.watchman`. This is the big change.

- don’t stop compilation on errors. This is required to compile on some systems, like Mojave and Ubuntu 18.04.

Now run the command below. It’ll print a lot of output.

./configure — without-python — without-pcre — enable-statedir=”$HOME/.watchman” — enable-lenient

If you see output like this in the end, you’re good! 🙌🏻 Your output will be different but it should look similar.

Your build configuration:

CC = gcc

CPPFLAGS = -D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE

CFLAGS = -g -O2 -Wall -Wextra -Wdeclaration-after-statement -g -gdwarf-2 -fno-omit-frame-pointer

CXX = g++ -std=c++11

CXXFLAGS = -g -O2 -Wall -Wextra -g -gdwarf-2 -fno-omit-frame-pointer

LDFLAGS =

prefix: /usr/local

version: 4.9.0

state directory: /Users/Mary/.watchman

Let’s compile. Run:

gmake

This will make your fan spin. Success end of output looks like this:

CXX tests_wildmatch_t-hash.o

CXX tests_wildmatch_t-log.o

CXXLD tests/wildmatch.t

gmake[1]: Leaving directory ‘/Users/Mary/Desktop/watchman’

If you get a fail here, copy the output and open and issue in the repo: https://github.com/facebook/watchman/issues

To install, run and type your password.

sudo gmake install

Try using the stuff that depends on watchman normally now and let me know if it’s better! 👾👾

--

--