moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
7.89k stars 1.09k forks source link

Fails to build on mips64 #5129

Open siretart opened 2 weeks ago

siretart commented 2 weeks ago

I'm trying to build the package in Debian on mips64, and am getting this compilation failure:

github.com/docker/docker/vendor/github.com/moby/buildkit/snapshot
# github.com/docker/docker/vendor/github.com/moby/buildkit/snapshot
src/github.com/docker/docker/vendor/github.com/moby/buildkit/snapshot/diffapply_unix.go:131:8: cannot use stat.Dev (variable of type uint32) as uint64 value in struct literal
src/github.com/docker/docker/vendor/github.com/moby/buildkit/snapshot/diffapply_unix.go:300:12: cannot use unix.Mkdev(0, 0) (value of type uint64) as uint32 value in struct literal

It appears to me that the issue lies around here:

https://github.com/moby/buildkit/blob/1aee151f6c6a63002b228936d6e76215a8fb8ece/snapshot/diffapply_unix.go#L120-L133

As it turns out, on mips the dev member is an uint32 for some reason: https://cs.opensource.google/go/go/+/refs/tags/go1.22.5:src/syscall/ztypes_linux_mips64.go;l=100

(unlike amd64: https://cs.opensource.google/go/go/+/refs/tags/go1.22.5:src/syscall/ztypes_linux_amd64.go;l=102)

A similar cast appears to be required here as well:

https://github.com/moby/buildkit/blob/1aee151f6c6a63002b228936d6e76215a8fb8ece/snapshot/diffapply_unix.go#L297-L302

In Debian, Docker used to build fine on mips64 in the past. It'd be a shame to remove it because of these missing casts.

tianon commented 2 weeks ago

I think this is technically a stdlib bug since unix.Mkdev's return type should be appropriately platform-specific (just like the types it's intended to be used with are), but I don't know if there's much upstream appetite in fixing it. :disappointed:

Here's the patch I've been using for a while, but I'm not 100% sure whether it's correct:

diff --git a/snapshot/diffapply_unix.go b/snapshot/diffapply_unix.go
index c4875000e..1d9d09d8f 100644
--- a/snapshot/diffapply_unix.go
+++ b/snapshot/diffapply_unix.go
@@ -128,7 +128,7 @@ func statInode(stat *syscall.Stat_t) inode {
    }
    return inode{
        ino: stat.Ino,
-       dev: stat.Dev,
+       dev: uint64(stat.Dev), // TODO figure out the "correct" solution for mips64le (where "stat.Dev" is a uint32)
    }
 }

@@ -297,7 +297,7 @@ func (a *applier) applyDelete(ctx context.Context, ca *changeApply) (bool, error
            if ca.srcStat == nil {
                ca.srcStat = &syscall.Stat_t{
                    Mode: syscall.S_IFCHR,
-                   Rdev: unix.Mkdev(0, 0),
+                   Rdev: 0, // TODO figure out the "correct" solution for mips64le (where "stat.Dev" is a uint32, but "unix.Mkdev" always returns uint64...); https://cs.opensource.google/go/x/sys/+/refs/tags/v0.10.0:unix/dev_linux.go;l=36
                }
                ca.srcPath = ""
            }