Skip to content

Commit d618c3a

Browse files
authored
V3 refactor/pgo split (crazywhalecc#1234)
2 parents 5279203 + 554128d commit d618c3a

6 files changed

Lines changed: 60 additions & 9 deletions

File tree

‎src/Package/Library/libaom.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function buildUnix(ToolchainInterface $toolchain): void
4545
if (str_starts_with($targetCpu, 'aarch')) {
4646
$targetCpu = str_replace('aarch', 'arm', $targetCpu);
4747
}
48+
// On ARM, features like crc (used by av1/encoder/arm/hash_arm_crc32.c) are only
49+
// enabled when the compiler receives them via -march/-mcpu; zig-cc.sh rewrites
50+
// -march=armv8-a+crc to -mcpu=generic+v8a+crc so the flag survives the wrapper.
4851
if (
4952
in_array($targetCpu, ['x86', 'x86_64'], true)
5053
&& !UnixUtil::findCommand('nasm')

‎src/StaticPHP/Artifact/Artifact.php‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,19 @@ public function getDownloadConfig(string $type): mixed
285285
* Get source extraction directory.
286286
*
287287
* Rules:
288-
* 1. If extract is not specified: SOURCE_PATH/{artifact_name}
289-
* 2. If extract is relative path: SOURCE_PATH/{value}
290-
* 3. If extract is absolute path: {value}
291-
* 4. If extract is array (dict): handled by extractor (selective extraction)
288+
* 1. If cache_type is 'local': use the absolute dirname recorded at download time (no symlink/copy).
289+
* 2. If extract is not specified: SOURCE_PATH/{artifact_name}
290+
* 3. If extract is relative path: SOURCE_PATH/{value}
291+
* 4. If extract is absolute path: {value}
292+
* 5. If extract is array (dict): handled by extractor (selective extraction)
292293
*/
293294
public function getSourceDir(): string
294295
{
295296
// Prefer cache extract path, fall back to config
296297
$cache_info = ApplicationContext::get(ArtifactCache::class)->getSourceInfo($this->name);
298+
if (($cache_info['cache_type'] ?? null) === 'local' && isset($cache_info['dirname'])) {
299+
return FileSystem::convertPath($cache_info['dirname']);
300+
}
297301
$extract = is_string($cache_info['extract'] ?? null)
298302
? $cache_info['extract']
299303
: ($this->config['source']['extract'] ?? null);

‎src/StaticPHP/Artifact/ArtifactExtractor.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ protected function extractSource(Artifact $artifact): int
136136
throw new WrongUsageException("Artifact source [{$name}] not downloaded, please download it first!");
137137
}
138138

139+
if (($cache_info['cache_type'] ?? null) === 'local') {
140+
$artifact->emitAfterSourceExtract($artifact->getSourceDir());
141+
return SPC_STATUS_ALREADY_EXTRACTED;
142+
}
143+
139144
$source_file = $this->cache->getCacheFullPath($cache_info);
140145
$target_path = $artifact->getSourceDir();
141146

‎src/StaticPHP/Artifact/Downloader/Type/GitHubRelease.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public function getLatestGitHubRelease(string $name, string $repo, bool $prefer_
5757
if (!is_array($data)) {
5858
throw new DownloaderException("Failed to get GitHub release API info for {$repo} from {$url}");
5959
}
60+
// GitHub's /releases list is ordered by publish date, so a newer-tagged prerelease
61+
// (e.g. 2.2.x-alpha) can precede the latest stable (2.1.x-stable). /releases/latest
62+
// returns the semantically latest stable release regardless of order; check it first.
63+
if ($prefer_stable) {
64+
$latest_url = str_replace('{repo}', $repo, self::API_URL) . '/latest';
65+
$latest = json_decode(default_shell()->executeCurl($latest_url, headers: $headers, retries: $retries) ?: '', true);
66+
if (is_array($latest) && isset($latest['assets'])) {
67+
array_unshift($data, $latest);
68+
}
69+
}
6070
foreach ($data as $release) {
6171
if ($prefer_stable && $release['prerelease'] === true) {
6272
continue;

‎src/globals/scripts/zig-cc.sh‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ while [[ $# -gt 0 ]]; do
2222
-march=*|-mcpu=*)
2323
OPT_NAME="${1%%=*}"
2424
OPT_VALUE="${1#*=}"
25-
# Skip armv8- flags entirely as Zig doesn't support them
26-
if [[ "$OPT_VALUE" == armv8-* ]]; then
27-
shift
28-
continue
25+
# zig rejects -march=armv8-a but accepts -mcpu=generic+v8a; rewrite
26+
# armv<X>[.<Y>]-a[+feat] -> generic+v<X>[_<Y>]a[+feat] so it goes through.
27+
if [[ "$OPT_VALUE" =~ ^armv([89])(\.([0-9]+))?-a(\+.*)?$ ]]; then
28+
arch_feat="v${BASH_REMATCH[1]}"
29+
[[ -n "${BASH_REMATCH[3]}" ]] && arch_feat="${arch_feat}_${BASH_REMATCH[3]}"
30+
OPT_VALUE="generic+${arch_feat}a${BASH_REMATCH[4]}"
2931
fi
30-
# replace -march=x86-64 with -march=x86_64
32+
# zig uses snake_case in CPU/feature names (x86-64 -> x86_64).
3133
OPT_VALUE="${OPT_VALUE//-/_}"
3234
PARSED_ARGS+=("${OPT_NAME}=${OPT_VALUE}")
3335
shift

‎tests/StaticPHP/Artifact/ArtifactExtractorTest.php‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,33 @@ public function testExtractWithStringNameLooksUpFromArtifactLoader(): void
182182
$this->assertSame(SPC_STATUS_ALREADY_EXTRACTED, $result);
183183
}
184184

185+
public function testExtractLocalSourceUsesLocalDirnameInPlace(): void
186+
{
187+
ApplicationContext::initialize();
188+
189+
// A real directory standing in for the user's local source tree.
190+
$localDir = $this->tempDir . '/user-local-src';
191+
mkdir($localDir, 0755, true);
192+
file_put_contents($localDir . '/marker.txt', 'keep me');
193+
194+
$artifact = new Artifact('local-pkg', ['source' => ['type' => 'local']]);
195+
196+
$cache = $this->createMock(ArtifactCache::class);
197+
$cache->method('getSourceInfo')->willReturn(['cache_type' => 'local', 'dirname' => $localDir]);
198+
$cache->method('getBinaryInfo')->willReturn(null);
199+
$cache->method('isBinaryDownloaded')->willReturn(false);
200+
ApplicationContext::set(ArtifactCache::class, $cache);
201+
202+
$extractor = new ArtifactExtractor($cache, false);
203+
$result = $extractor->extract($artifact, true); // force_source: never pick a binary
204+
205+
// Local sources are not extracted: the tree lives in place at $cache_info['dirname'].
206+
$this->assertSame(SPC_STATUS_ALREADY_EXTRACTED, $result);
207+
$this->assertFileExists($localDir . '/marker.txt');
208+
$this->assertFalse(is_link($localDir));
209+
$this->assertSame(\StaticPHP\Util\FileSystem::convertPath($localDir), $artifact->getSourceDir());
210+
}
211+
185212
// ==================== Helpers ====================
186213

187214
/**

0 commit comments

Comments
 (0)