This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit dc620ad3017e77040f7093c2a9ba5e65c4a4d21f Author: Sebastian Rühl <[email protected]> AuthorDate: Mon Jul 6 14:05:03 2026 +0200 fix(plc4go): make spi/transports/pcap buildable without cgo gopacket/pcap is cgo-only on every platform except Windows (all versions, not a regression from the 1.7.0 bump), so CGO_ENABLED=0 builds — including all cross-compilation — failed on the pcap transport. Gate the real implementation behind `cgo || windows` and add a stub that returns a clear error from CreateTransportInstance in nocgo builds. --- plc4go/spi/transports/pcap/Transport.go | 2 ++ plc4go/spi/transports/pcap/TransportInstance.go | 2 ++ .../spi/transports/pcap/TransportInstance_test.go | 2 ++ .../pcap/{Transport.go => Transport_nocgo.go} | 38 +++++++--------------- plc4go/spi/transports/pcap/Transport_test.go | 2 ++ 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/plc4go/spi/transports/pcap/Transport.go b/plc4go/spi/transports/pcap/Transport.go index 9bf5102e4d..868c1f748e 100644 --- a/plc4go/spi/transports/pcap/Transport.go +++ b/plc4go/spi/transports/pcap/Transport.go @@ -1,3 +1,5 @@ +//go:build cgo || windows + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/plc4go/spi/transports/pcap/TransportInstance.go b/plc4go/spi/transports/pcap/TransportInstance.go index 8b6790b227..1334d67c80 100644 --- a/plc4go/spi/transports/pcap/TransportInstance.go +++ b/plc4go/spi/transports/pcap/TransportInstance.go @@ -1,3 +1,5 @@ +//go:build cgo || windows + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/plc4go/spi/transports/pcap/TransportInstance_test.go b/plc4go/spi/transports/pcap/TransportInstance_test.go index 425601b284..bbf7a75e94 100644 --- a/plc4go/spi/transports/pcap/TransportInstance_test.go +++ b/plc4go/spi/transports/pcap/TransportInstance_test.go @@ -1,3 +1,5 @@ +//go:build cgo || windows + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/plc4go/spi/transports/pcap/Transport.go b/plc4go/spi/transports/pcap/Transport_nocgo.go similarity index 63% copy from plc4go/spi/transports/pcap/Transport.go copy to plc4go/spi/transports/pcap/Transport_nocgo.go index 9bf5102e4d..e1318862c2 100644 --- a/plc4go/spi/transports/pcap/Transport.go +++ b/plc4go/spi/transports/pcap/Transport_nocgo.go @@ -1,3 +1,5 @@ +//go:build !cgo && !windows + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -21,7 +23,6 @@ package pcap import ( "net/url" - "strconv" "github.com/rs/zerolog" @@ -30,18 +31,18 @@ import ( "github.com/apache/plc4x/plc4go/spi/transports" ) -type TransportType string - -const ( - UDP TransportType = "udp" - TCP TransportType = "tcp" - PCAP TransportType = "pcap" -) +// The real pcap transport binds to libpcap through gopacket/pcap, which is +// cgo-only on every platform except Windows. This stub keeps the package +// (and everything importing it) compilable with CGO_ENABLED=0 — e.g. when +// cross-compiling — and reports a clear error if the transport is actually +// used in such a build. type Transport struct { log zerolog.Logger } +var _ transports.Transport = (*Transport)(nil) + func NewTransport(_options ...options.WithOption) *Transport { customLogger := options.ExtractCustomLoggerOrDefaultToGlobal(_options...) return &Transport{ @@ -57,25 +58,8 @@ func (m *Transport) GetTransportName() string { return "PCAP(NG) Playback Transport" } -func (m *Transport) CreateTransportInstance(transportUrl url.URL, options map[string][]string, _options ...options.WithOption) (transports.TransportInstance, error) { - var transportType = PCAP - if val, ok := options["transport-type"]; ok { - transportType = TransportType(val[0]) - } - var portRange = "" - if val, ok := options["transport-port-range"]; ok { - portRange = val[0] - } - var speedFactor float32 = 1.0 - if val, ok := options["speed-factor"]; ok { - if parsedSpeedFactory, err := strconv.ParseFloat(val[0], 32); err != nil { - return nil, errors.Wrap(err, "error parsing speed-factor") - } else { - speedFactor = float32(parsedSpeedFactory) - } - } - - return NewPcapTransportInstance(transportUrl.Path, transportType, portRange, speedFactor, m, _options...), nil +func (m *Transport) CreateTransportInstance(_ url.URL, _ map[string][]string, _ ...options.WithOption) (transports.TransportInstance, error) { + return nil, errors.New("the pcap transport requires cgo (libpcap); rebuild with CGO_ENABLED=1") } func (m *Transport) Close() error { diff --git a/plc4go/spi/transports/pcap/Transport_test.go b/plc4go/spi/transports/pcap/Transport_test.go index 9a6b426210..8519c801d0 100644 --- a/plc4go/spi/transports/pcap/Transport_test.go +++ b/plc4go/spi/transports/pcap/Transport_test.go @@ -1,3 +1,5 @@ +//go:build cgo || windows + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file
