Skip to content

Commit 796889b

Browse files
author
Tinywan
committed
fix(docker): restore v0.8 platform compatibility
1 parent 7884dfb commit 796889b

6 files changed

Lines changed: 64 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ php webman typephp:package --force
6262
php webman typephp:package --refresh-main
6363
```
6464

65-
默认 builder 为 `tinywan/typephp-webman-builder:v0.1.2`。编译在 Docker 中完成,宿主机不需要 C++、Clang 或 TypePHP 编译器。
65+
默认 builder 为 `tinywan/typephp-webman-builder:v0.1.3`。编译在 Docker 中完成,宿主机不需要 C++、Clang 或 TypePHP 编译器。
6666

6767
### 4. 启动产物
6868

@@ -130,7 +130,7 @@ return [
130130
'enable' => true,
131131
'docker' => [
132132
'enabled' => true,
133-
'image' => 'tinywan/typephp-webman-builder:v0.1.2',
133+
'image' => 'tinywan/typephp-webman-builder:v0.1.3',
134134
],
135135
'build' => [
136136
'output_name' => 'webman-server',
@@ -140,7 +140,7 @@ return [
140140
];
141141
```
142142

143-
`--image` 的优先级最高;未指定时使用上述 `docker.image`,配置缺失时才回退至 `tinywan/typephp-webman-builder:v0.1.2`。
143+
`--image` 的优先级最高;未指定时使用上述 `docker.image`,配置缺失时才回退至 `tinywan/typephp-webman-builder:v0.1.3`。
144144

145145
## 🎯 可信 MVP 边界
146146

‎docker/CompilerBase.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
use TypePhp\Parser\UniversalMethodCall;
6868
use TypePhp\Optimizer\FuncCallOptimizer;
6969
use TypePhp\Platform\Linux;
70+
use TypePhp\Platform\Ios;
71+
use TypePhp\Platform\Android;
7072
use TypePhp\Platform\Macos;
7173
use TypePhp\Platform\PlatformBase;
7274
use TypePhp\Platform\PlatformFactory;
@@ -678,6 +680,16 @@ public function isMacos(): bool
678680
return $this->getPlatform() instanceof Macos;
679681
}
680682

683+
public function isIosTarget(): bool
684+
{
685+
return $this->getPlatform() instanceof Ios;
686+
}
687+
688+
public function isAndroidTarget(): bool
689+
{
690+
return $this->getPlatform() instanceof Android;
691+
}
692+
681693
public function isWasiTarget(): bool
682694
{
683695
$target = strtolower($this->targetPlatform);
@@ -723,6 +735,15 @@ public function isBuildModeEmbed(): bool
723735

724736
public function getPhpDir(): string
725737
{
738+
if ($this->isIosTarget()) {
739+
// iPhoneOS is a cross target. Its PHP headers and archive are part
740+
// of the integrated PHPX SDK, never the host PHP installation.
741+
return $this->getIosSdkDir();
742+
}
743+
if ($this->isAndroidTarget()) {
744+
return $this->getAndroidSdkDir();
745+
}
746+
726747
try {
727748
return $this->getPlatform()->getPhpDir();
728749
} catch (\RuntimeException $e) {

‎src/Commands/PackageCommand.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// @mago-ignore lint:cyclomatic-complexity -- The command deliberately coordinates validation, manifest generation, and Docker invocation.
2020
class PackageCommand extends Command
2121
{
22-
private const DEFAULT_BUILDER_IMAGE = 'tinywan/typephp-webman-builder:v0.1.2';
22+
private const DEFAULT_BUILDER_IMAGE = 'tinywan/typephp-webman-builder:v0.1.3';
2323

2424
protected static $defaultName = 'typephp:package';
2525
protected static $defaultDescription = 'Build Webman project into a Linux x86_64 portable-dir using TypePHP Docker builder.';

‎src/config/plugin/tinywan/typephp/app.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Docker 编译环境配置
1313
'docker' => [
1414
'enabled' => true,
15-
'image' => 'tinywan/typephp-webman-builder:v0.1.2',
15+
'image' => 'tinywan/typephp-webman-builder:v0.1.3',
1616
],
1717
// 默认输出配置
1818
'build' => [
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
it('keeps the CompilerBase override compatible with the v0.8 native build platform contract', function (): void {
6+
$repositoryRoot = dirname(__DIR__, 2);
7+
$dockerfile = file_get_contents($repositoryRoot . '/docker/Dockerfile');
8+
$compilerBase = file_get_contents($repositoryRoot . '/docker/CompilerBase.php');
9+
if ($dockerfile === false || $compilerBase === false) {
10+
throw new RuntimeException('Unable to load CompilerBase Docker override files.');
11+
}
12+
13+
expect($dockerfile)->toContain('COPY CompilerBase.php /opt/typephp/vendor/swoole/typephp/src/CompilerBase.php');
14+
15+
foreach ([
16+
'use TypePhp\\Platform\\Ios;',
17+
'use TypePhp\\Platform\\Android;',
18+
'public function isIosTarget(): bool',
19+
'return $this->getPlatform() instanceof Ios;',
20+
'public function isAndroidTarget(): bool',
21+
'return $this->getPlatform() instanceof Android;',
22+
'if ($this->isIosTarget()) {',
23+
'return $this->getIosSdkDir();',
24+
'if ($this->isAndroidTarget()) {',
25+
'return $this->getAndroidSdkDir();',
26+
] as $required) {
27+
expect($compilerBase)->toContain($required);
28+
}
29+
30+
expect($compilerBase)->toMatch(
31+
'/public function getPhpDir\(\): string\s*\{\s*if \(\$this->isIosTarget\(\)\) \{.*?'
32+
. 'return \$this->getIosSdkDir\(\);\s*}\s*if \(\$this->isAndroidTarget\(\)\) \{.*?'
33+
. 'return \$this->getAndroidSdkDir\(\);\s*}\s*try/s',
34+
);
35+
});

‎tests/Unit/PackageCommandTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
expect($command->getDefinition()->getOption('image')->getDefault())->toBeNull();
1919
});
2020

21-
it('ships the v0.1.2 builder image in the plugin configuration', function (): void {
21+
it('ships the v0.1.3 builder image in the plugin configuration', function (): void {
2222
$pluginConfig = require dirname(__DIR__, 2) . '/src/config/plugin/tinywan/typephp/app.php';
2323
if (!is_array($pluginConfig)) {
2424
throw new RuntimeException('Plugin configuration must be an array.');
@@ -29,7 +29,7 @@
2929
throw new RuntimeException('Plugin Docker configuration must be an array.');
3030
}
3131

32-
expect($dockerConfig['image'] ?? null)->toBe('tinywan/typephp-webman-builder:v0.1.2');
32+
expect($dockerConfig['image'] ?? null)->toBe('tinywan/typephp-webman-builder:v0.1.3');
3333
});
3434

3535
it('resolves the builder image from the option, configuration, then fallback', function (): void {
@@ -44,5 +44,5 @@
4444
'docker' => ['image' => 'registry.example/configured:v1'],
4545
]))->toBe('registry.example/configured:v1');
4646

47-
expect($method->invoke($command, null, []))->toBe('tinywan/typephp-webman-builder:v0.1.2');
47+
expect($method->invoke($command, null, []))->toBe('tinywan/typephp-webman-builder:v0.1.3');
4848
});

0 commit comments

Comments
 (0)