forked from calamity-inc/Soup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_common.php
More file actions
107 lines (95 loc) · 2.13 KB
/
build_common.php
File metadata and controls
107 lines (95 loc) · 2.13 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
<?php
// Config
$clang = $argv[1] ?? "clang";
$clang .= " -std=c++17 -fno-rtti -O3 -ffunction-sections -fdata-sections";
if (defined("PHP_WINDOWS_VERSION_MAJOR"))
{
$clang .= " -D_CRT_SECURE_NO_WARNINGS";
}
else
{
$clang .= " -fPIC";
}
$clanglink = $clang;
if (PHP_OS_FAMILY != "Darwin")
{
$clanglink .= " -fuse-ld=lld";
}
if (!defined("PHP_WINDOWS_VERSION_MAJOR"))
{
if (PHP_OS_FAMILY == "Darwin")
{
$clanglink .= " -lc++ -framework IOKit -framework CoreFoundation";
}
else
{
$clanglink .= " -lstdc++";
}
$clanglink .= " -pthread -lm -ldl";
if (!getenv("ANDROID_ROOT"))
{
$clanglink .= " -lresolv";
}
if (PHP_OS_FAMILY != "Darwin")
{
$clanglink .= " -fuse-ld=lld -Wl,--gc-sections,--icf=safe";
if (!getenv("ANDROID_ROOT"))
{
$clanglink .= " -lstdc++fs";
}
}
}
// Utilities
$queued_commands = [];
function run_command_async($cmd)
{
global $queued_commands;
array_push($queued_commands, $cmd);
}
function await_commands()
{
global $queued_commands;
$nthreads = 8;
if (defined("PHP_WINDOWS_VERSION_MAJOR"))
{
$nthreads = (int)getenv("NUMBER_OF_PROCESSORS");
}
else if (is_file("/proc/cpuinfo"))
{
$nthreads = (int)substr_count(file_get_contents("/proc/cpuinfo"), "processor");
}
$done = 0;
$todo = count($queued_commands);
echo "$done/$todo";
$procs = [];
$output = "";
while ($done != $todo)
{
while (count($procs) < $nthreads && count($queued_commands) != 0)
{
$file = tmpfile();
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", stream_get_meta_data($file)["uri"], "a"),
2 => array("file", stream_get_meta_data($file)["uri"], "a"),
);
$proc = proc_open(array_shift($queued_commands), $descriptorspec, $pipes);
array_push($procs, [ $proc, $file ]);
}
foreach ($procs as $i => $proc)
{
if (!proc_get_status($proc[0])["running"])
{
$output .= stream_get_contents($proc[1]);
fclose($proc[1]);
proc_close($proc[0]);
unset($procs[$i]);
$done += 1;
echo "\r$done/$todo";
}
}
usleep(10000);
}
echo "\n";
echo $output;
}