From e19a1829b2cbea5d872119ef762f27858390282c Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 25 Nov 2026 11:08:31 -0500 Subject: [PATCH 1/2] purego: use runtime/cgo instead of fakecgo on Go 1.28 and later Go 1.28 has a pure assembly and Go implementation of runtime/cgo that can build with CGO_ENABLED=0 (GOEXPERIMENT=noruntimecgopurego can be set to disable it). Use that instead of fakecgo. Once purego supports a minimum version of Go 1.28 in its go.mod file we should be able to delete fakecgo entirely. For #565 --- internal/fakecgo/threadentry_test.go | 2 +- nocgo.go | 2 +- nocgo_go128.go | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 nocgo_go128.go diff --git a/internal/fakecgo/threadentry_test.go b/internal/fakecgo/threadentry_test.go index 9314e095..36f52f69 100644 --- a/internal/fakecgo/threadentry_test.go +++ b/internal/fakecgo/threadentry_test.go @@ -3,7 +3,7 @@ // 386/arm are excluded: the standalone fakecgo test binary resolves pthread // from libpthread.so.0, which fails the dynamic symbol lookup on 32-bit linux. -//go:build !cgo && (linux || darwin || freebsd || illumos || netbsd) && !386 && !arm +//go:build !cgo && !go1.28 && (linux || darwin || freebsd || illumos || netbsd) && !386 && !arm package fakecgo diff --git a/nocgo.go b/nocgo.go index a98ecb6f..ef41b6e1 100644 --- a/nocgo.go +++ b/nocgo.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build !cgo && (darwin || freebsd || illumos || linux || netbsd) +//go:build !cgo && !go1.28 && (darwin || freebsd || illumos || linux || netbsd) package purego diff --git a/nocgo_go128.go b/nocgo_go128.go new file mode 100644 index 00000000..2fcb1822 --- /dev/null +++ b/nocgo_go128.go @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2026 The Ebitengine Authors + +//go:build !cgo && go1.28 && (darwin || freebsd || illumos || linux || netbsd) + +package purego + +// Go 1.28 introduces a pure-Go and assembly implementation of runtime/cgo, +// so there's no longer a need for fakecgo and we can implement the true +// runtime/cgo. +import _ "runtime/cgo" From 252ffdff3c73ce38c76bc557f5357da7407190ad Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 25 Nov 2026 15:47:49 -0500 Subject: [PATCH 2/2] add build tags for go1.28 --- internal/fakecgo/threadentry_test.go | 2 +- nocgo.go | 2 +- nocgo_go128.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/fakecgo/threadentry_test.go b/internal/fakecgo/threadentry_test.go index 36f52f69..4595d5be 100644 --- a/internal/fakecgo/threadentry_test.go +++ b/internal/fakecgo/threadentry_test.go @@ -3,7 +3,7 @@ // 386/arm are excluded: the standalone fakecgo test binary resolves pthread // from libpthread.so.0, which fails the dynamic symbol lookup on 32-bit linux. -//go:build !cgo && !go1.28 && (linux || darwin || freebsd || illumos || netbsd) && !386 && !arm +//go:build !cgo && !(go1.28 && goexperiment.runtimecgopurego) && !go1.29 && (linux || darwin || freebsd || illumos || netbsd) && !386 && !arm package fakecgo diff --git a/nocgo.go b/nocgo.go index ef41b6e1..6858dd38 100644 --- a/nocgo.go +++ b/nocgo.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build !cgo && !go1.28 && (darwin || freebsd || illumos || linux || netbsd) +//go:build !cgo && !(go1.28 && goexperiment.runtimecgopurego) && !go1.29 && (darwin || freebsd || illumos || linux || netbsd) package purego diff --git a/nocgo_go128.go b/nocgo_go128.go index 2fcb1822..967271c0 100644 --- a/nocgo_go128.go +++ b/nocgo_go128.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2026 The Ebitengine Authors -//go:build !cgo && go1.28 && (darwin || freebsd || illumos || linux || netbsd) +//go:build !cgo && ((go1.28 && goexperiment.runtimecgopurego) || go1.29) && (darwin || freebsd || illumos || linux || netbsd) package purego