Skip to content

Commit

Permalink
Add stub implementations to make buildkitd build for Darwin
Browse files Browse the repository at this point in the history
Signed-off-by: Marat Radchenko <[email protected]>
  • Loading branch information
slonopotamus committed Sep 2, 2024
1 parent b9a3e7b commit 02bc795
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 5 deletions.
3 changes: 0 additions & 3 deletions cmd/buildkitd/main_containerd_worker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build linux || windows || freebsd
// +build linux windows freebsd

package main

import (
Expand Down
64 changes: 64 additions & 0 deletions executor/oci/spec_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package oci

import (
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/oci"
"github.com/containerd/continuity/fs"
"github.com/docker/docker/pkg/idtools"
"github.com/moby/buildkit/solver/pb"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)

func withProcessArgs(args ...string) oci.SpecOpts {
return oci.WithProcessArgs(args...)
}

func generateMountOpts(_, _ string) []oci.SpecOpts {
return nil
}

func generateSecurityOpts(mode pb.SecurityMode, _ string, _ bool) ([]oci.SpecOpts, error) {
return nil, nil
}

func generateProcessModeOpts(mode ProcessMode) ([]oci.SpecOpts, error) {
return nil, nil
}

func generateIDmapOpts(idmap *idtools.IdentityMapping) ([]oci.SpecOpts, error) {
if idmap == nil {
return nil, nil
}
return nil, errors.New("no support for IdentityMapping on Darwin")
}

func generateRlimitOpts(ulimits []*pb.Ulimit) ([]oci.SpecOpts, error) {
if len(ulimits) == 0 {
return nil, nil
}
return nil, errors.New("no support for POSIXRlimit on Darwin")
}

// tracing is not implemented on Darwin
func getTracingSocketMount(_ string) *specs.Mount {
return nil
}

// tracing is not implemented on Darwin
func getTracingSocket() string {
return ""
}

func cgroupV2NamespaceSupported() bool {
return false
}

func sub(m mount.Mount, subPath string) (mount.Mount, func() error, error) {
src, err := fs.RootPath(m.Source, subPath)
if err != nil {
return mount.Mount{}, nil, err
}
m.Source = src
return m, func() error { return nil }, nil
}
67 changes: 67 additions & 0 deletions snapshot/localmounter_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package snapshot

import (
"os"

"github.com/containerd/containerd/mount"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

func (lm *localMounter) Mount() (string, error) {
lm.mu.Lock()
defer lm.mu.Unlock()

if lm.mounts == nil && lm.mountable != nil {
mounts, release, err := lm.mountable.Mount()
if err != nil {
return "", err
}
lm.mounts = mounts
lm.release = release
}

if len(lm.mounts) == 1 && lm.mounts[0].Type == "bind" {
ro := false
for _, opt := range lm.mounts[0].Options {
if opt == "ro" {
ro = true
break
}
}
if !ro {
return lm.mounts[0].Source, nil
}
}

dir, err := os.MkdirTemp("", "buildkit-mount")
if err != nil {
return "", errors.Wrap(err, "failed to create temp dir")
}

if err := mount.All(lm.mounts, dir); err != nil {
os.RemoveAll(dir)
return "", errors.Wrapf(err, "failed to mount %s: %+v", dir, lm.mounts)
}
lm.target = dir
return dir, nil
}

func (lm *localMounter) Unmount() error {
lm.mu.Lock()
defer lm.mu.Unlock()

if lm.target != "" {
if err := mount.UnmountRecursive(lm.target, unix.MNT_FORCE); err != nil {
return err
}
os.RemoveAll(lm.target)
lm.target = ""
}

if lm.release != nil {
return lm.release()
}

return nil
}
12 changes: 12 additions & 0 deletions source/git/source_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package git

import (
"context"
"errors"
"os/exec"
"runtime"
)

func runWithStandardUmask(_ context.Context, _ *exec.Cmd) error {
return errors.New("runWithStandardUmask not supported on " + runtime.GOOS)
}
4 changes: 2 additions & 2 deletions util/network/netproviders/network_nobridge.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build freebsd || windows
// +build freebsd windows
//go:build !linux
// +build !linux

package netproviders

Expand Down

0 comments on commit 02bc795

Please sign in to comment.