GithubHelp home page GithubHelp logo

Problems Cross Compiling [Mac + BSD] about serial HOT 2 OPEN

tarm avatar tarm commented on August 21, 2024 1
Problems Cross Compiling [Mac + BSD]

from serial.

Comments (2)

dantheman213 avatar dantheman213 commented on August 21, 2024 1

Hi, I have enjoyed using your serial library so far. But unfortunately I'm having this exact same issue on my own project. It's most unfortunate I can't easily create a pipeline to compile for all platforms using a single make command.

dan@DAN-DESKTOP:/mnt/c/Users/danie/repos/gps-atlas$ make build-macos
export GOOS=darwin && \
export GOARCH=amd64 && \
export GPSATLAS_BIN_PATH=bin/macos/gps-atlas && \
make build
make[1]: Entering directory '/mnt/c/Users/danie/repos/gps-atlas'
CGO_ENABLED=0 \
GO111MODULE=on \
go build \
-installsuffix "static" \
-ldflags="-X 'main.Version=$(cat version)'" \
-o bin/macos/gps-atlas \
$(find cmd/app/*.go)
# github.com/tarm/serial
/home/dan/go/pkg/mod/github.com/tarm/[email protected]/serial.go:128:28: undefined: Port
/home/dan/go/pkg/mod/github.com/tarm/[email protected]/serial.go:139:9: undefined: openPort
Makefile:8: recipe for target 'build' failed
make[1]: *** [build] Error 2
make[1]: Leaving directory '/mnt/c/Users/danie/repos/gps-atlas'
Makefile:29: recipe for target 'build-macos' failed
make: *** [build-macos] Error 2
dan@DAN-DESKTOP:/mnt/c/Users/danie/repos/gps-atlas$

from serial.

tarm avatar tarm commented on August 21, 2024

Hi @tsteinholz

This package does aim to be cross platform, but cross-compiling (with gox or manually) is tricky right now. I think native compilation should work on all of the *bsd platforms. For windows in particular, both native and cross compiling should work like this:

$ GOOS=windows go install github.com/tarm/serial
$ ls -l $GOPATH/pkg/windows_amd64/github.com/tarm
total 72
-rw-r--r--. 1 tarm tarm 72410 Jan 30 20:22 serial.a

Specifically the issue with cross-compiling for posix platforms is that tarm/serial uses cgo+termios.h to keep things portable. The termios.h interface abstracts some of the syscall and ioctl differences in serial handling between different platforms. Take a look at the "build constraints" and cgo code here:
https://github.com/tarm/serial/blob/master/serial_posix.go#L1-L9

You might be able to make it work by passing the -cgo option to gox, but cross-compiling cgo code may be tricky and I have not tried it myself.

I would be interested/open to syscall+ioctl based solutions. Those would likely allow cross compiling more easily, but also would be much more closely tied to each architecture/platform.

Patches welcome!

from serial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.