From 4085a4893c427a2138e28fe4f16a646e7f571adb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 12 Dec 2023 12:53:32 -0500 Subject: net: move cgo-using darwin test to separate package It is a goal / requirement that nothing in the standard library on darwin require cgo, and this test-only file makes net use cgo on darwin. Move it elsewhere. Change-Id: I6c11a8391d3913f73ce0098ba63b29adf5864f93 Reviewed-on: https://go-review.googlesource.com/c/go/+/549255 Reviewed-by: Mauri de Souza Meneguzzo Reviewed-by: Bryan Mills LUCI-TryBot-Result: Go LUCI Auto-Submit: Russ Cox --- src/cmd/go/testdata/script/darwin_no_cgo.txt | 9 +++++++++ src/go/build/deps_test.go | 7 ++++++- src/net/cgo_unix_cgo_darwin.go | 21 --------------------- src/net/internal/cgotest/empty_test.go | 13 +++++++++++++ src/net/internal/cgotest/resstate.go | 21 +++++++++++++++++++++ 5 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 src/cmd/go/testdata/script/darwin_no_cgo.txt delete mode 100644 src/net/cgo_unix_cgo_darwin.go create mode 100644 src/net/internal/cgotest/empty_test.go create mode 100644 src/net/internal/cgotest/resstate.go diff --git a/src/cmd/go/testdata/script/darwin_no_cgo.txt b/src/cmd/go/testdata/script/darwin_no_cgo.txt new file mode 100644 index 0000000000..fa445925b7 --- /dev/null +++ b/src/cmd/go/testdata/script/darwin_no_cgo.txt @@ -0,0 +1,9 @@ +# For reproducibility and easier cross-compilation, +# nothing in std is supposed to use cgo on macOS. +# Check that cgo does not appear as a dependency +# of cmd/go, which imports approximately everything +# in std (certainly everything relevant). +[!GOOS:darwin] skip +go list -deps cmd/go +! stdout runtime/cgo + diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 7ce8d346b4..47a0f3a0b4 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -672,7 +672,7 @@ var depsRules = ` internal/coverage, crypto/sha256, FMT < cmd/internal/cov/covcmd; - encoding/json, + encoding/json, runtime/debug, internal/coverage/calloc, internal/coverage/cformat, @@ -680,6 +680,11 @@ var depsRules = ` internal/coverage/encodecounter, internal/coverage/encodemeta, internal/coverage/pods < runtime/coverage; + + # Test-only packages can have anything they want + CGO, internal/syscall/unix < net/internal/cgotest; + + ` // listStdPkgs returns the same list of packages as "go list std". diff --git a/src/net/cgo_unix_cgo_darwin.go b/src/net/cgo_unix_cgo_darwin.go deleted file mode 100644 index 40d5e426f2..0000000000 --- a/src/net/cgo_unix_cgo_darwin.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !netgo && cgo && darwin - -package net - -/* -#include -*/ -import "C" - -import ( - "internal/syscall/unix" - "unsafe" -) - -// This will cause a compile error when the size of -// unix.ResState is too small. -type _ [unsafe.Sizeof(unix.ResState{}) - unsafe.Sizeof(C.struct___res_state{})]byte diff --git a/src/net/internal/cgotest/empty_test.go b/src/net/internal/cgotest/empty_test.go new file mode 100644 index 0000000000..c4f601d571 --- /dev/null +++ b/src/net/internal/cgotest/empty_test.go @@ -0,0 +1,13 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cgotest + +import "testing" + +// Nothing to test here. +// The test is that the package compiles at all. +// See resstate.go. +func Test(t *testing.T) { +} diff --git a/src/net/internal/cgotest/resstate.go b/src/net/internal/cgotest/resstate.go new file mode 100644 index 0000000000..1b4871109e --- /dev/null +++ b/src/net/internal/cgotest/resstate.go @@ -0,0 +1,21 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build cgo && darwin + +package cgotest + +/* +#include +*/ +import "C" + +import ( + "internal/syscall/unix" + "unsafe" +) + +// This will cause a compile error when the size of +// unix.ResState is too small. +type _ [unsafe.Sizeof(unix.ResState{}) - unsafe.Sizeof(C.struct___res_state{})]byte -- cgit v1.3