fsnotify icon indicating copy to clipboard operation
fsnotify copied to clipboard

FSEvents on macOS

Open nathany opened this issue 10 years ago • 16 comments

Requested by @robfig at https://github.com/howeyc/fsnotify/issues/54 in order to watch large trees.

To be implemented as a stand-alone repository for experimentation (#23) before determining how to incorporate it into fsnotify.

System requirements:

  • OS X 10.6 or better (matching the system requirements of Go 1.3). Though some features require 10.7, or perhaps even higher.
  • Likely require cgo with Xcode installed.

Prior work:

  • @samjacobson https://github.com/samjacobson/go.fsevents
  • @ronbu https://github.com/ronbu/fsevents

Reference:

nathany avatar Jun 29 '14 01:06 nathany

Work has begun on this as an external project that can eventually be used from fsnotify. https://github.com/go-fsnotify/fsevents

TODO:

  • [ ] Integration tests
  • [ ] Refine API
  • [ ] EventFlags.String()

nathany avatar Dec 13 '14 02:12 nathany

Would it make sense to work in a monorepo for fsnotify? Bring the fsevents library into a subfolder and work on it here, even before it's integrated and used by fsnotify.

nathany avatar Apr 20 '16 19:04 nathany

Yes, I agree that would make sense.

samjacobson avatar Apr 21 '16 02:04 samjacobson

Some people are using fsnotify/fsevents so we'd probably leave it there and just move maintenance here. We could put a message up over there -- or not.

I'm still undecided whether it should be internal/ here initially.

nathany avatar Apr 21 '16 05:04 nathany

I'm also not sure if we should try to move fsnotify towards this new driver system (#104), or build out something entirely new. Perhaps coming back later to retrofit fsnotify on top of an intermediary API.

nathany avatar Apr 21 '16 14:04 nathany

Can someone explain what FSEvents is? I don't understand; afaict fsnotify already supports macOS and doesn't require cgo. Is that correct?

abuchanan-nr avatar Jan 11 '19 22:01 abuchanan-nr

Hello, what's the status?

PeterBocan avatar Jan 21 '19 19:01 PeterBocan

Can someone explain what FSEvents is?

According to this page there are two mechanisms for monitoring files/directories on Mac: kernel queues (kqueues), or file system events (FSEvents).

File system events are intended to provide notification of changes with directory-level granularity. For most purposes, this is sufficient. In some cases, however, you may need to receive notifications with finer granularity. For example, you might need to monitor only changes made to a single file. For that purpose, the kernel queue (kqueue) notification system is more appropriate.

If you are monitoring a large hierarchy of content, you should use file system events instead, however, because kernel queues are somewhat more complex than kernel* events, and can be more resource intensive because of the additional user-kernel communication involved.

*I assume they meant file system events here.

Timmmm avatar Jan 23 '19 15:01 Timmmm

Ah! Makes sense. Thanks @Timmmm

I hope they will be (or currently are?) an optional part of fsnotify, so that we don't need to include cgo.

abuchanan-nr avatar Jan 23 '19 16:01 abuchanan-nr

To be implemented as a stand-alone repository for experimentation (#23) before determining how to incorporate it into fsnotify.

Any timeline to use https://github.com/fsnotify/fsevents in this repo?

ysweid avatar May 21 '19 03:05 ysweid

No timeline.

This would resolve #129 as well as issues like https://github.com/gohugoio/hugo/issues/6109. Would be really nice.

We may want to do it at the same time as #114 and #21 to have recursive watching across systems.

nathany avatar Oct 05 '19 16:10 nathany

Any idea on what the plan would be for incorporating FSEvents? Were issues found in the experimentation?

What can the community do at this point to help move this cause?

joeljeske avatar Jun 05 '20 12:06 joeljeske

github.com/fsnotify/fsevents uses CGO, and I'd really like to avoid using CGO. The main reason for this is that it just makes building applications that depend on fsnotify harder: you will need a C compiler, and cross-compiling from e.g. Linux to macOS – which is easy now – will be very hard as well. We can use some shims and build tags to allow people to use CGO_ENABLED=0 and -tags fsnotify_no_events, but then FSEvents won't be available in that build which would be confusing.

So the path forward on this is that support for FSEvents will have to be added to x/sys/unix first, similar to how illumos/Solaris FEN support was added there before we added support here.

I don't have a macOS machine; just a (slow) QEMU VM. It's kind of hard for me to work on this, and I'm unlikely to work on it in the near future, but this is the path forward to get it properly added to fsnotify. In the meanwhile, people can use github.com/fsnotify/fsevents protected with some build tags if they want, but it's a bit awkward.

arp242 avatar Oct 14 '22 15:10 arp242

github.com/ebitengine/purego could be used to skirt the usage of cgo.

srlehn avatar Nov 04 '22 19:11 srlehn

The go command now disables cgo by default on systems without a C toolchain. https://go.dev/blog/go1.20

Falling back from FSEvents to kqueue on macOS would be confusing, that's true. It may work, but it would be confusing to the programmer or end-user compiling the software, and could make bug reports confusing too.

macOS doesn't have the C compiler installed by default, though a developer may not get very far without installing the Xcode Command Line Tools. It's been a while since I've done a fresh install, but I feel like it didn't take long after installing the Homebrew package manager before I had to get a C compiler installed too.

Cross-compiling seems like a more significant issue. Zig has been innovating in that space by bundling libc and a C/C++ compiler, but that could be a difficult proposal to sell for Go.

@arp242 Are you still without a dedicated Mac?

nathany avatar Dec 03 '23 21:12 nathany

Are you still without a dedicated Mac?

I don't expect that'll change any time soon, if ever, and even if it did, I wouldn't be hugely interested to pick this up either to be honest. It's a comparatively big project: we're talking about a full week, maybe even two weeks of of full-time work? Even going with the existing cgo solution would need quite a bit of attention to get it up to spec.

But spending so much of my free time on something I'll never personally see the benefits of is kind of where I draw the line. That doesn't mean I wouldn't like to see support for it, or don't want to spend any time on it, but it'll have to be like the illumos/FEN stuff, where nshalman did the bulk of the work and I just helped out where I could, or something like that.

arp242 avatar Dec 03 '23 21:12 arp242