forked from uNetworking/uWebSockets.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.h
More file actions
134 lines (119 loc) · 4.14 KB
/
build.h
File metadata and controls
134 lines (119 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <signal.h>
static volatile char CaughtSIGINT = 0;
void SIGINTHandler(int dummy) { CaughtSIGINT = 1; }
/* List of platform features */
#if defined(_WIN32)
#define OS "win32"
#define IS_WINDOWS
#define STATIC_LIB(path, name) " ./" path "/" name ".lib "
#define C_COMPILER "clang -fms-runtime-lib=static"
#define CXX_COMPILER "clang++ -fms-runtime-lib=static"
#define WIN32_LEAN_AND_MEAN
// suppress Windows "secure" deprecations
// #define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
int get_cpu_count(void) {
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return (int)sysinfo.dwNumberOfProcessors;
}
static DWORD WINAPI _thread_fn(LPVOID _arg);
#define _THREAD_BODY_START /* defined per-use below */
#define START_FOREACH_NODEJS(i) \
HANDLE _handles[versionsQuantity]; \
struct { unsigned int idx; } _args[versionsQuantity]; \
DWORD WINAPI _thread_fn(LPVOID _arg) { \
unsigned int i = ((typeof(_args[0])*)_arg)->idx; \
#define END_FOREACH_NODEJS \
return 0; \
} \
for (unsigned int _i = 0; _i < versionsQuantity; _i++) { \
_args[_i].idx = _i; \
_handles[_i] = CreateThread(NULL, 0, _thread_fn, &_args[_i], 0, NULL);\
} \
WaitForMultipleObjects(versionsQuantity, _handles, TRUE, INFINITE); \
for (unsigned int _i = 0; _i < versionsQuantity; _i++) CloseHandle(_handles[_i]);
#else // POSIX systems
#define STATIC_LIB(path, name) " " path "/lib" name ".a "
#define START_FOREACH_NODEJS(i) \
pid_t pids[versionsQuantity]; \
for (unsigned int i = 0; i < versionsQuantity; i++) { \
pids[i] = fork(); \
if (pids[i] != 0) continue;
#define END_FOREACH_NODEJS \
exit(0); \
} \
for (unsigned int i = 0; i < versionsQuantity; i++) waitpid(pids[i], 0, 0);
#include <unistd.h>
#include <sys/wait.h>
int get_cpu_count(void) {
long n = sysconf(_SC_NPROCESSORS_ONLN);
return (n > 0) ? (int)n : 1;
}
#if defined(__linux)
#define OS "linux"
#define IS_LINUX
#define C_COMPILER "clang"
#define CXX_COMPILER "clang++"
#elif defined(__APPLE__)
#define OS "darwin"
#define IS_MACOS
#if defined(CROSS_COMPILE_MACOS)
#define C_COMPILER "clang -target x86_64-apple-macos12"
#define CXX_COMPILER "clang++ -target x86_64-apple-macos12"
#else
#define C_COMPILER "clang -target arm64-apple-macos12"
#define CXX_COMPILER "clang++ -target arm64-apple-macos12"
#endif
#endif
#endif
/* ASAN vs. optimized build flags (used via C string literal concatenation). */
#ifdef WITH_ASAN
#define OPT_FLAGS " -fsanitize=address -fno-omit-frame-pointer -g -O1"
#define LINUX_LINK_EXTRAS " -fsanitize=address"
#define MACOS_LINK_EXTRAS " -fsanitize=address"
#define PER_TARGET_ARTIFACTS_FOLDER "artifacts-asan"
#else
#define OPT_FLAGS " -flto -O3"
#define LINUX_LINK_EXTRAS " -static-libstdc++ -static-libgcc -s"
#define MACOS_LINK_EXTRAS ""
#define PER_TARGET_ARTIFACTS_FOLDER "artifacts"
#endif
const char *ARM = "arm";
const char *ARM64 = "arm64";
const char *X64 = "x64";
#if defined(CROSS_COMPILE_MACOS)
#define ARCH X64
#elif defined(__arm__)
#define ARCH ARM
#elif defined(__aarch64__)
#define ARCH ARM64
#else
#define ARCH X64
#endif
/* System, but with string replace */
int run(const char *cmd, ...) {
char buf[2048];
va_list args;
va_start(args, cmd);
vsprintf(buf, cmd, args);
va_end(args);
printf("--> %s\n\n", buf);
if(CaughtSIGINT){ printf("\nCaught SIGINT!!! Exiting now\n"); exit(0); };
return system(buf);
}
/* List of Node.js versions */
struct node_version {
const char *name;
const char *abi;
} versions[] = {
{"v22.0.0", "127"},
{"v24.0.0", "137"},
{"v26.0.0", "147"}
};
const int versionsQuantity = sizeof(versions) / sizeof(struct node_version);
int threads_quantity;