Skip to content

Commit

Permalink
use CGO to enable fsevent on OSX
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Feb 9, 2023
1 parent e6e2f78 commit bcbaece
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.go\|\.hcl\|\.sh\)"
# xx is a helper for cross-compilation
FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx

# osxcross contains the MacOSX cross toolchain for xx
FROM crazymax/osxcross:11.3-alpine AS osxcross

FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense

FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS base
COPY --from=xx / /
RUN apk add --no-cache \
clang \
docker \
file \
findutils \
Expand Down Expand Up @@ -73,10 +77,12 @@ EOT
FROM build-base AS build
ARG BUILD_TAGS
ARG TARGETPLATFORM
RUN xx-go --wrap
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
xx-go --wrap && \
if [ "$(xx-info os)" == "darwin" ]; then export CGO_ENABLED=1; fi && \
make build GO_BUILDTAGS="$BUILD_TAGS" DESTDIR=/usr/bin && \
xx-verify --static /usr/bin/docker-compose

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ all: build

.PHONY: build ## Build the compose cli-plugin
build:
CGO_ENABLED=0 GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd
GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd

.PHONY: binary
binary:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ require (
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsevents v0.1.1
github.com/fvbommel/sortorder v1.0.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=
github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/watch/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestWatchNonexistentDirectory(t *testing.T) {
t.Fatal(err)
}

// for directories that were the root of an Add, we don't report creation, cf. watcher_fsevent.go
// for directories that were the root of an Add, we don't report creation, cf. watcher_darwin.go
f.assertEvents()

f.events = nil
Expand Down
6 changes: 1 addition & 5 deletions pkg/watch/watcher_fsevent.go → pkg/watch/watcher_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package watch

/**
FIXME this implementation requires CGO
import (
"path/filepath"
"time"
Expand Down Expand Up @@ -130,7 +127,7 @@ func (d *fseventNotify) Errors() chan error {
return d.errors
}

func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, error) {
func newWatcher(paths []string, ignore PathMatcher) (Notify, error) {
dw := &fseventNotify{
ignore: ignore,
stream: &fsevents.EventStream{
Expand Down Expand Up @@ -158,4 +155,3 @@ func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, erro
}

var _ Notify = &fseventNotify{}
**/
5 changes: 4 additions & 1 deletion pkg/watch/watcher_naive.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !darwin
// +build !darwin

/*
Copyright 2020 Docker Compose CLI authors
Expand Down Expand Up @@ -294,7 +297,7 @@ func (d *naiveNotify) add(path string) error {
return nil
}

func newWatcher(paths []string, ignore PathMatcher) (*naiveNotify, error) {
func newWatcher(paths []string, ignore PathMatcher) (Notify, error) {
if ignore == nil {
return nil, fmt.Errorf("newWatcher: ignore is nil")
}
Expand Down

0 comments on commit bcbaece

Please sign in to comment.