Skip to content

Commit aa10c6e

Browse files
committed
swift-reflection-test: preprocess for windows build
Windows does not support fork/exec, so preprocess away the calls to those APIs on Windows. This allows for building more of the test binaries.
1 parent 4b037e2 commit aa10c6e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tools/swift-reflection-test/overrides.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "overrides.h"
22

3+
#if !defined(_WIN32)
34
extern pid_t fork(void);
45
extern int execv(const char *path, char * const *argv);
56

@@ -10,4 +11,5 @@ pid_t _fork(void) {
1011
int _execv(const char *path, char * const *argv) {
1112
return execv(path, argv);
1213
}
14+
#endif
1315

tools/swift-reflection-test/overrides.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
#include <sys/types.h>
44

5+
#if !defined(_WIN32)
56
pid_t _fork(void);
67
int _execv(const char *path, char * const *argv);
8+
#endif
9+

tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
#include <stdio.h>
2828
#include <stdlib.h>
2929
#include <string.h>
30+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
3031
#include <unistd.h>
32+
#elif defined(_WIN32)
33+
#include <io.h>
34+
#include <fcntl.h>
35+
#endif
3136

3237
typedef struct PipeMemoryReader {
3338
int to_child[2];
@@ -265,10 +270,17 @@ void PipeMemoryReader_sendDoneMessage(const PipeMemoryReader *Reader) {
265270
static
266271
PipeMemoryReader createPipeMemoryReader() {
267272
PipeMemoryReader Reader;
273+
#if defined(_WIN32)
274+
if (pipe(Reader.to_child, 256, _O_BINARY))
275+
errnoAndExit("Couldn't create pipes to child process");
276+
if (pipe(Reader.from_child, 256, _O_BINARY))
277+
errnoAndExit("Couldn't create pipes from child process");
278+
#else
268279
if (pipe(Reader.to_child))
269280
errnoAndExit("Couldn't create pipes to child process");
270281
if (pipe(Reader.from_child))
271282
errnoAndExit("Couldn't create pipes from child process");
283+
#endif
272284
return Reader;
273285
}
274286

@@ -441,6 +453,8 @@ int reflectExistential(SwiftReflectionContextRef RC,
441453
int doDumpHeapInstance(const char *BinaryFilename) {
442454
PipeMemoryReader Pipe = createPipeMemoryReader();
443455

456+
#if defined(_WIN32)
457+
#else
444458
pid_t pid = _fork();
445459
switch (pid) {
446460
case -1:
@@ -515,6 +529,7 @@ int doDumpHeapInstance(const char *BinaryFilename) {
515529
}
516530
}
517531
}
532+
#endif
518533
return EXIT_SUCCESS;
519534
}
520535

0 commit comments

Comments
 (0)