Skip to content

Commit 73c56e4

Browse files
Support MSVC compiler (#126)
1 parent e103e73 commit 73c56e4

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

src/c/dune

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@ let () = Jbuild_plugin.V1.send @@ {|
122122
(targets generate_types_step_2.exe)
123123
(deps (:c generate_types_step_2.c) helpers.h shims.h)
124124
(action (bash "\
125-
%{cc} %{c} \
126-
-I '%{lib:ctypes:.}' \
127-
-I %{ocaml_where} \
128-
|}^ i_option ^{| -o %{targets}")))
125+
if [ '%{ocaml-config:ccomp_type}' = 'msvc' ]; then \
126+
%{cc} %{c} \
127+
-I '%{lib:ctypes:.}' \
128+
-I %{ocaml_where} \
129+
|}^ i_option ^{| /Fe\"%{targets}\"; \
130+
else \
131+
%{cc} %{c} \
132+
-I '%{lib:ctypes:.}' \
133+
-I %{ocaml_where} \
134+
|}^ i_option ^{| -o %{targets}; \
135+
fi")))
129136

130137
(rule
131138
(with-stdout-to luv_c_generated_types.ml

src/c/windows_version.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,55 @@
1616
#include <ws2tcpip.h>
1717
#endif
1818

19+
#if defined(_MSC_VER)
20+
# include <sys/stat.h>
21+
# if defined(_S_IFIFO)
22+
# define S_IFIFO _S_IFIFO
23+
# endif
24+
# ifndef S_IXUSR
25+
# define S_IXUSR _S_IEXEC
26+
# endif
27+
# ifndef S_IWUSR
28+
# define S_IWUSR _S_IWRITE
29+
# endif
30+
# ifndef S_IRUSR
31+
# define S_IRUSR _S_IREAD
32+
# endif
33+
# ifndef S_IRWXU
34+
# define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
35+
# endif
36+
/* Windows has no block devices. Defining S_IFBLK was a mistake in MinGW: https://sourceforge.net/p/mingw/bugs/1146/
37+
For parity with the MinGW luv port we re-use MinGW's constant. Libuv 1.42.0 does not use S_IFBLK anyway.
38+
*/
39+
# define S_IFBLK 0x3000
40+
/* Windows does not support POSIX "others" and "groups". Use same settings as src.c/vendor/configure/ltmain.sh */
41+
# ifndef S_IXOTH
42+
# define S_IXOTH 0
43+
# endif
44+
# ifndef S_IXGRP
45+
# define S_IXGRP 0
46+
# endif
47+
/* Libuv 1.42 uses `| S_IRGRP | S_IROTH` and `| S_IWGRP | S_IWOTH` etc. to add POSIX permissions for "others" and "groups"
48+
like in src/c/vendor/libuv/src/unix/pipe.c. That means we can use zero (0) just like ltmain.sh did for
49+
S_IXOTH and S_IXGRP. */
50+
# ifndef S_IROTH
51+
# define S_IROTH 0
52+
# endif
53+
# ifndef S_IRGRP
54+
# define S_IRGRP 0
55+
# endif
56+
# ifndef S_IWOTH
57+
# define S_IWOTH 0
58+
# endif
59+
# ifndef S_IWGRP
60+
# define S_IWGRP 0
61+
# endif
62+
# ifndef S_IRWXO
63+
# define S_IRWXO 0
64+
# endif
65+
# ifndef S_IRWXG
66+
# define S_IRWXG 0
67+
# endif
68+
#endif
69+
1970
#endif // #ifndef LUV_WINDOWS_VERSION_H_

0 commit comments

Comments
 (0)