Skip to content

Commit 7a42ba7

Browse files
committed
use CGO to enable fsevent on OSX
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 5b043c4 commit 7a42ba7

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.go\|\.hcl\|\.sh\)"
2727
# xx is a helper for cross-compilation
2828
FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx
2929

30+
# osxcross contains the MacOSX cross toolchain for xx
31+
FROM crazymax/osxcross:11.3-alpine AS osxcross
32+
3033
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
3134
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
3235

3336
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS base
3437
COPY --from=xx / /
3538
RUN apk add --no-cache \
39+
clang \
3640
docker \
3741
file \
3842
findutils \
@@ -73,10 +77,12 @@ EOT
7377
FROM build-base AS build
7478
ARG BUILD_TAGS
7579
ARG TARGETPLATFORM
76-
RUN xx-go --wrap
7780
RUN --mount=type=bind,target=. \
7881
--mount=type=cache,target=/root/.cache \
7982
--mount=type=cache,target=/go/pkg/mod \
83+
--mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
84+
xx-go --wrap && \
85+
if [ "$(xx-info os)" == "darwin" ]; then export CGO_ENABLED=1; fi && \
8086
make build GO_BUILDTAGS="$BUILD_TAGS" DESTDIR=/usr/bin && \
8187
xx-verify --static /usr/bin/docker-compose
8288

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ all: build
5353

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

5858
.PHONY: binary
5959
binary:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ require (
5959
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect
6060
github.com/docker/go-metrics v0.0.1 // indirect
6161
github.com/felixge/httpsnoop v1.0.2 // indirect
62+
github.com/fsnotify/fsevents v0.1.1
6263
github.com/fvbommel/sortorder v1.0.2 // indirect
6364
github.com/go-logr/logr v1.2.3 // indirect
6465
github.com/go-logr/stdr v1.2.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
254254
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
255255
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
256256
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
257+
github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=
258+
github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc=
257259
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
258260
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
259261
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=

pkg/watch/notify_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func TestWatchNonexistentDirectory(t *testing.T) {
435435
t.Fatal(err)
436436
}
437437

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

441441
f.events = nil

pkg/watch/watcher_fsevent.go renamed to pkg/watch/watcher_darwin.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package watch
2121

22-
/**
23-
FIXME this implementation requires CGO
24-
2522
import (
2623
"path/filepath"
2724
"time"
@@ -130,7 +127,7 @@ func (d *fseventNotify) Errors() chan error {
130127
return d.errors
131128
}
132129

133-
func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, error) {
130+
func newWatcher(paths []string, ignore PathMatcher) (Notify, error) {
134131
dw := &fseventNotify{
135132
ignore: ignore,
136133
stream: &fsevents.EventStream{
@@ -158,4 +155,3 @@ func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, erro
158155
}
159156

160157
var _ Notify = &fseventNotify{}
161-
**/

pkg/watch/watcher_naive.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build !darwin
2+
// +build !darwin
3+
14
/*
25
Copyright 2020 Docker Compose CLI authors
36
@@ -294,7 +297,7 @@ func (d *naiveNotify) add(path string) error {
294297
return nil
295298
}
296299

297-
func newWatcher(paths []string, ignore PathMatcher) (*naiveNotify, error) {
300+
func newWatcher(paths []string, ignore PathMatcher) (Notify, error) {
298301
if ignore == nil {
299302
return nil, fmt.Errorf("newWatcher: ignore is nil")
300303
}

0 commit comments

Comments
 (0)