bugst / go-serial

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

Build for darwin/amd64 failes #114

Closed niondir closed 3 years ago

niondir commented 3 years ago

nativeGetDetailedPortsList seems not to be supported. Do I miss something? How can I build the library for mac?

$ env GOOS=darwin GOARCH=amd64 go build ./...
# go.bug.st/serial/enumerator
enumerator\enumerator.go:31:9: undefined: nativeGetDetailedPortsList

Update:

Maybe it's due to some CGO / GCC issue. I'm getting

$ env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -x -v ./...
WORK=C:\Users\tobia\AppData\Local\Temp\go-build4142346371
runtime/cgo
mkdir -p $WORK\b046\
cd C:\Program Files\Go\src\runtime\cgo
TERM='dumb' CGO_LDFLAGS='"-g" "-O2" "-lpthread"' "C:\\Program Files\\Go\\pkg\\tool\\windows_amd64\\cgo.exe" -objdir "$WORK\\b046\\" -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -- -I "$WORK\\b046\\" -g -O2
 -Wno-nullability-completeness -Wall -Werror "C:\\Program Files\\Go\\src\\runtime\\cgo\\cgo.go"
# runtime/cgo
gcc: error: x86_64: No such file or directory
gcc: error: unrecognized command line option '-arch'; did you mean '-march='?

I'm Working on Windows.

$ gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
cmaglie commented 3 years ago

Maybe it's due to some CGO / GCC issue

Yes, if you want the USB enumerator compiling for Mac requires CGO: you need a cross-compiler and the Apple SDK installed on your PC.

I suggest using the docker image we use in the arduino-cli that already has everything needed -> https://github.com/arduino/arduino-cli/blob/471358634cd6680dbe2be4ca652db46fb759deda/DistTasks.yml#L219-L228

The command line that the Taskfile run (without the ldflags that you don't need) is:

$ task dist:macOS_64bit

docker run -v `pwd`/..:/home/build -w /home/build \
  -e CGO_ENABLED=1 \
  docker.elastic.co/beats-dev/golang-crossbuild:1.16.4-darwin-debian10 \
  --build-cmd "go build -o dist/arduino-cli_osx_darwin_amd64/arduino-cli" \
  -p "darwin/amd64"

TBH I don't really know how this works exactly (someone else did it for me), but I'm sure you can tinker it to make it work on your project :-).

Alternatively, the easiest way is to build natively on OSX...

cmaglie commented 3 years ago

Since it's not a bug, I'm closing the issue.