Skip to content

Commit 5fc26dc

Browse files
committed
Fix ssize_t missing on windows when using MSVC
1 parent d52d831 commit 5fc26dc

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

c/codegen/to.odin

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ generate_bindings_from_runestone :: proc(
3434
io.Error,
3535
errors.Error,
3636
} {
37-
generate_includes(wd, rn) or_return
37+
generate_includes({rs.platform}, wd, rn) or_return
3838

3939
generate_bindings_for_constants(wd, rs, rn) or_return
4040
generate_forward_declarations_for_externs(wd, rs, rn) or_return
@@ -56,7 +56,9 @@ generate_bindings_from_runecross :: proc(
5656
errors.Error,
5757
},
5858
) {
59-
generate_includes(wd, rn) or_return
59+
all_plats := runic.all_platforms_of_runecross(rc)
60+
generate_includes(all_plats, wd, rn) or_return
61+
delete(all_plats)
6062

6163
// Generate macros for platforms
6264
oses: [dynamic]runic.OS
@@ -220,9 +222,32 @@ generate_bindings :: proc {
220222
generate_bindings_from_runecross,
221223
}
222224

223-
generate_includes :: proc(wd: io.Writer, rn: runic.To) -> io.Error {
225+
generate_includes :: proc(
226+
plats: []runic.Platform,
227+
wd: io.Writer,
228+
rn: runic.To,
229+
) -> io.Error {
224230
io.write_string(wd, "#pragma once\n\n") or_return
225-
io.write_string(wd, "#include <stddef.h>\n#include <stdint.h>\n\n") or_return
231+
232+
for plat in plats {
233+
if plat.os == .Any || plat.os == .Windows {
234+
io.write_string(
235+
wd,
236+
`#ifdef _MSC_VER
237+
#include <BaseTsd.h>
238+
typedef SSIZE_T ssize_t;
239+
#endif
240+
241+
`,
242+
) or_return
243+
break
244+
}
245+
}
246+
247+
io.write_string(
248+
wd,
249+
"#include <stddef.h>\n#include <stdint.h>\n\n",
250+
) or_return
226251

227252
include_paths: [dynamic]string
228253
defer delete(include_paths)

c/codegen/to_test.odin

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ var.macos_globals = Array
202202

203203
EXPECTED_HEADER :: `#pragma once
204204
205+
#ifdef _MSC_VER
206+
#include <BaseTsd.h>
207+
typedef SSIZE_T ssize_t;
208+
#endif
209+
205210
#include <stddef.h>
206211
#include <stdint.h>
207212

runic/runecross.odin

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,3 +749,18 @@ source_of_extern_type_from_runecross :: proc(
749749
return "", false
750750
}
751751

752+
all_platforms_of_runecross :: proc(
753+
rc: Runecross,
754+
allocator := context.allocator,
755+
) -> []Platform {
756+
plats := make(
757+
[dynamic]Platform,
758+
len = 0,
759+
cap = len(rc.cross),
760+
allocator = allocator,
761+
)
762+
763+
for c in rc.cross do append(&plats, ..c.plats)
764+
765+
return plats[:]
766+
}

test_data/foozy/foozy-windows.expected.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#pragma once
22

3+
#ifdef _MSC_VER
4+
#include <BaseTsd.h>
5+
typedef SSIZE_T ssize_t;
6+
#endif
7+
38
#include <stddef.h>
49
#include <stdint.h>
510

0 commit comments

Comments
 (0)