bugst / go-serial

A cross-platform serial library for go-lang.
BSD 3-Clause "New" or "Revised" License
620 stars 189 forks source link

No longer compiles under macOS due to dependency problem #86

Closed maddie closed 3 years ago

maddie commented 3 years ago

Since golang.org/x/sys/unix was being updated regularly, the following error occurs when compiling under macOS:

zsyscall_darwin.go:16:27: undefined: unix.SYS_IOCTL

This is due to golang/sys@6fcdbc0 removing all the SYS_* constants, the reason being that direct syscalls under Darwin are no longer supported.

Is there a fix for this?

EDIT: The temporary workaround for this problem is adding this line to the project's go.mod to use an older version of golang.org/x/sys/unix:

replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6

But this is not a long-term solution.

maddie commented 3 years ago

The golang.org/x/sys/unix package provides the following ioctl syscall methods for various platforms since a long time ago (earliest commits found circa 2017):

func IoctlSetInt(fd int, req uint, value int) error
func IoctlSetPointerInt(fd int, req uint, value int) error
func IoctlSetWinsize(fd int, req uint, value *Winsize) error
func IoctlSetTermios(fd int, req uint, value *Termios) error
func IoctlGetInt(fd int, req uint) (int, error)
func IoctlGetWinsize(fd int, req uint) (*Winsize, error)
func IoctlGetTermios(fd int, req uint) (*Termios, error)

Are they sufficient to replace the ioctl wrapper functions for different platforms in this package?

rnicolas commented 3 years ago

I compiled yesterday night in a Mac for a Mac without problems.

maddie commented 3 years ago

@rnicolas the project I'm working on depends on a newer version of golang/x/sys/unix, which already has the direct syscalls removed, so it fails. It does compile fine if the project doesn't depend on it.

And the problem here is that direct syscalls are not recommended in Darwin and the supports are being dropped in the later commits in golang/x/sys/unix, so I think it's a good move to migrate to a supported way of doing this.

rnicolas commented 3 years ago

@maddie I understand now the problem because at the beginning I understood it didn't compile at all.