-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild_common.php
75 lines (71 loc) · 1.51 KB
/
build_common.php
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
<?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 if (PHP_OS_FAMILY != "Darwin")
{
$clang .= " -fPIC";
}
$clanglink = $clang;
if (!defined("PHP_WINDOWS_VERSION_MAJOR"))
{
$clanglink .= " -lstdc++ -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
$procs = [];
function run_command_async($cmd)
{
global $procs;
echo ".";
$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($cmd, $descriptorspec, $pipes);
array_push($procs, [ $proc, $file ]);
if (count($procs) >= (getenv("ANDROID_ROOT") ? 16 : 32))
{
await_commands();
}
}
function await_commands()
{
global $procs;
echo "\r";
$output = "";
while (count($procs) != 0)
{
foreach ($procs as $i => $proc)
{
if (!proc_get_status($proc[0])["running"])
{
echo "█";
$output .= stream_get_contents($proc[1]);
fclose($proc[1]);
proc_close($proc[0]);
unset($procs[$i]);
}
}
usleep(50000);
}
echo "\n";
echo $output;
}