[Git][ghc/ghc][master] Windows: Always define _UCRT when compiling C code
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Mon Sep 12 17:29:55 UTC 2022
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
3a815f30 by Ryan Scott at 2022-09-12T13:29:41-04:00
Windows: Always define _UCRT when compiling C code
As seen in #22159, this is required to ensure correct behavior when MinGW-w64
headers are in the `C_INCLUDE_PATH`.
Fixes #22159.
- - - - -
6 changed files:
- m4/fp_setup_windows_toolchain.m4
- testsuite/tests/ffi/should_run/Makefile
- + testsuite/tests/ffi/should_run/T22159.hs
- + testsuite/tests/ffi/should_run/T22159.stdout
- + testsuite/tests/ffi/should_run/T22159_c.c
- testsuite/tests/ffi/should_run/all.T
Changes:
=====================================
m4/fp_setup_windows_toolchain.m4
=====================================
@@ -82,7 +82,11 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
CC="${mingwbin}clang.exe"
CXX="${mingwbin}clang++.exe"
- cflags="--rtlib=compiler-rt"
+
+ # Signal that we are linking against UCRT with the _UCRT macro. This is
+ # necessary to ensure correct behavior when MinGW-w64 headers are in the
+ # header include path (#22159).
+ cflags="--rtlib=compiler-rt -D_UCRT"
CFLAGS="$cflags"
CONF_CC_OPTS_STAGE1="$cflags"
CONF_CC_OPTS_STAGE2="$cflags"
=====================================
testsuite/tests/ffi/should_run/Makefile
=====================================
@@ -49,3 +49,10 @@ T15933:
'$(TEST_HC)' $(TEST_HC_OPTS) -c T15933.hs
'$(TEST_HC)' $(TEST_HC_OPTS) T15933_c.o T15933.o -o T15933
./T15933
+
+.PHONY: T22159
+T22159:
+ C_INCLUDE_PATH=/mingw64/include '$(TEST_HC)' $(TEST_HC_OPTS) -c T22159.hs
+ C_INCLUDE_PATH=/mingw64/include '$(TEST_HC)' $(TEST_HC_OPTS) -c T22159_c.c
+ C_INCLUDE_PATH=/mingw64/include '$(TEST_HC)' $(TEST_HC_OPTS) T22159.o T22159_c.o -o T22159
+ ./T22159
=====================================
testsuite/tests/ffi/should_run/T22159.hs
=====================================
@@ -0,0 +1,23 @@
+{-# LANGUAGE CPP #-}
+module Main (main) where
+
+#if defined(i386_HOST_ARCH)
+# define WINDOWS_CCONV stdcall
+#elif defined(x86_64_HOST_ARCH)
+# define WINDOWS_CCONV ccall
+#else
+# error Unknown mingw32 arch
+#endif
+
+import Foreign.C.String (peekCWString)
+import Foreign.C.Types (CWchar)
+import Foreign.Marshal.Alloc (allocaBytes)
+import Foreign.Ptr (Ptr)
+
+foreign import WINDOWS_CCONV "hello" c_hello :: Ptr CWchar -> IO ()
+
+main :: IO ()
+main = allocaBytes 12 $ \buf -> do
+ c_hello buf
+ str <- peekCWString buf
+ putStrLn str
=====================================
testsuite/tests/ffi/should_run/T22159.stdout
=====================================
@@ -0,0 +1 @@
+hello
=====================================
testsuite/tests/ffi/should_run/T22159_c.c
=====================================
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include <wchar.h>
+
+void hello(wchar_t *buf) {
+ swprintf_s(buf, 12, L"hello");
+}
=====================================
testsuite/tests/ffi/should_run/all.T
=====================================
@@ -229,3 +229,8 @@ test('T19237', normal, compile_and_run, ['T19237_c.c'])
test('T21305', omit_ways(['ghci']), multi_compile_and_run,
['T21305', [('T21305_cmm.cmm', '')], ''])
+
+test('T22159',
+ [unless(opsys('mingw32'), skip),
+ extra_files(['T22159_c.c'])],
+ makefile_test, ['T22159'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3a815f30bcba5672085e823aeef90863253b0b1a
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3a815f30bcba5672085e823aeef90863253b0b1a
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220912/41be6937/attachment-0001.html>
More information about the ghc-commits
mailing list