tools: add build-tag stubs for Windows and CGO_ENABLED=0 builds

Enables clean builds under GOOS=windows CGO_ENABLED=0 and under
CGO_ENABLED=0 on Linux. The three tools that can't be built in those
configurations now substitute a stub that prints a clear message
and exits 1, so go build ./... succeeds across all target platforms.

- tools/sniff: tagged !windows && cgo (needs libpcap via cgo).
  Stub (main_stub.go) covers windows || !cgo.
- tools/split: same tags as sniff (also pcap).
- tools/sniffer: tagged !windows (uses Unix raw sockets directly via
  syscall, not cgo). Stub (main_windows.go) covers Windows.

Verified:
- go build ./... clean (default, cgo=1 Linux)
- CGO_ENABLED=0 go build ./... clean (portable Linux)
- GOOS=windows CGO_ENABLED=0 go build ./... clean (Windows)
- go vet clean across all three configurations
- All 13 pkg/transport tests pass under CGO_ENABLED=0, confirming
  direct_portable.go's directDial path is correct.
This commit is contained in:
psycep
2026-04-22 10:46:38 -05:00
parent 4890b97162
commit c3173c535a
6 changed files with 87 additions and 0 deletions
+2
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows && cgo
package main
import (
+27
View File
@@ -0,0 +1,27 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows || !cgo
package main
import (
"fmt"
"os"
)
func main() {
fmt.Fprintln(os.Stderr, "sniff: not built. This tool needs libpcap via cgo; rebuild with CGO_ENABLED=1 on Linux or macOS.")
os.Exit(1)
}
+2
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
package main
import (
+27
View File
@@ -0,0 +1,27 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package main
import (
"fmt"
"os"
)
func main() {
fmt.Fprintln(os.Stderr, "sniffer: not supported on Windows. This tool depends on Unix raw sockets; rebuild on Linux or macOS.")
os.Exit(1)
}
+2
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows && cgo
package main
import (
+27
View File
@@ -0,0 +1,27 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows || !cgo
package main
import (
"fmt"
"os"
)
func main() {
fmt.Fprintln(os.Stderr, "split: not built. This tool needs libpcap via cgo; rebuild with CGO_ENABLED=1 on Linux or macOS.")
os.Exit(1)
}