]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: report a meaningful error message when using Cygwin
authorqmuntal <quimmuntal@gmail.com>
Thu, 14 Nov 2024 12:06:55 +0000 (13:06 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Thu, 14 Nov 2024 17:24:38 +0000 (17:24 +0000)
Go has never supported Cygwin as a C compiler, but users get the
following cryptic error message when they try to use it:

    implicit declaration of function '_beginthread'

This is because Cygwin doesn't implement _beginthread. Note that
this is not the only problem with Cygwin, but it's the one that
users are most likely to run into first.

This CL improves the error message to make it clear that Cygwin
is not supported, and suggests using MinGW instead.

Fixes #59490
Fixes #36691

Change-Id: Ifeec7a2cb38d7c5f50d6362c95504f72818c6a76
Reviewed-on: https://go-review.googlesource.com/c/go/+/627935
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/cgo/gcc_libinit_windows.c

index 9a8c65ea291ad8c342e448a52bc7e72c69549257..ddc0ad7010e5080fa31d012b775e3a3be03c6ae1 100644 (file)
@@ -2,6 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+# ifdef __CYGWIN__
+#error "don't use the cygwin compiler to build native Windows programs; use MinGW instead"
+#else
+// Exclude the following code from Cygwin builds.
+// Cygwin doesn't implement process.h nor does it support _beginthread.
+
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <process.h>
@@ -156,3 +162,5 @@ void _cgo_beginthread(void (*func)(void*), void* arg) {
        fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
        abort();
 }
+
+#endif // __CYGWIN__
\ No newline at end of file