Skip to content

Commit 6bbe7c5

Browse files
committed
Improve SimplePInvoke native build flow
1 parent 82c72e8 commit 6bbe7c5

6 files changed

Lines changed: 26 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ jobs:
5050
run: sudo ./eng/common/native/install-dependencies.sh linux
5151

5252
- name: Build hostlibs for Linux x64
53-
run: python ./scripts/build-hostlibs.py --os linux --arch x64
53+
run: python ./scripts/build-hostlibs.py -v --os linux --arch x64
5454

5555
- name: Run SimplePInvoke sample
56-
run: ./repo/runtime/.dotnet/dotnet run --project samples/simple-pinvoke/SimplePInvoke.csproj
56+
run: ./repo/runtime/.dotnet/dotnet run --project samples/simple-pinvoke/SimplePInvoke.csproj -v:normal
5757

5858
- name: Publish SimplePInvoke sample trimmed
59-
run: ./repo/runtime/.dotnet/dotnet publish samples/simple-pinvoke/SimplePInvoke.csproj -p:"PublishTrimmed=true"
59+
run: ./repo/runtime/.dotnet/dotnet publish samples/simple-pinvoke/SimplePInvoke.csproj -v:normal -p:"PublishTrimmed=true"

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
4-
<DefaultRid>win-x64</DefaultRid>
54
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
65

76
<AvaloniaAppHostPackageVersion>11.0.0-preview.2</AvaloniaAppHostPackageVersion>

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ python .\scripts\pipeline.py matrix
8686
- 构建 SkiaSharp:
8787

8888
```powershell
89-
python .\scripts\pipeline.py skia
89+
python .\scripts\pipeline.py skia -v
9090
```
9191
9292
```powershell
@@ -97,15 +97,15 @@ python .\scripts\build-skia-harfbuzz.py -v -a arm64
9797
- 打包 Avalonia Host 包:
9898

9999
```powershell
100-
python .\scripts\pipeline.py pack-avalonia
100+
python .\scripts\pipeline.py pack-avalonia -v
101101
```
102102

103103
## 实验性 Linux 生成
104104

105105
- 构建 HostLib:
106106

107107
```bash
108-
python scripts/build-hostlibs.py --os linux --arch x64
108+
python scripts/build-hostlibs.py -v --os linux --arch x64
109109
```
110110

111111
- 运行构建集成矩阵测试:

samples/simple-pinvoke/NativeLib/build.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,27 @@ def execv(cmd: str, cwd: Path | None = None, env=None):
3030
return proc
3131

3232

33+
def run_in_vs_env(cmd: str, cwd: Path, arch: str, env=None):
34+
full_cmd = f"call {INIT_VS_ENV_CMD} {arch} && cd /d {cwd} && {cmd}"
35+
execv(full_cmd)
36+
37+
3338
SCRIPT_ROOT = Path(__file__).resolve().parent
39+
INIT_VS_ENV_CMD = SCRIPT_ROOT / ".." / ".." / ".." / "scripts" / "init-vs-env.cmd"
3440

3541

3642
def main():
3743
if is_windows:
38-
execv("cl.exe /nologo /c dll.cpp")
39-
execv("lib.exe /nologo dll.obj")
44+
if not Path(SCRIPT_ROOT, "dll.lib").exists():
45+
run_in_vs_env(
46+
"cl.exe /nologo /c dll.cpp && lib.exe /nologo dll.obj",
47+
cwd=SCRIPT_ROOT,
48+
arch="x64",
49+
)
4050
else:
41-
execv("clang++ -c dll.cpp")
42-
execv("llvm-ar rcs dll.a dll.o")
51+
if not Path(SCRIPT_ROOT, "dll.a").exists():
52+
execv("clang++ -c dll.cpp")
53+
execv("llvm-ar rcs dll.a dll.o")
4354

4455

4556
if __name__ == "__main__":

samples/simple-pinvoke/SimplePInvoke.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@
3030
</NativeLibrary>
3131
</ItemGroup>
3232

33+
<Target Name="BuildNativeLib" BeforeTargets="CoreCompile">
34+
<Exec Command="python build.py"
35+
WorkingDirectory="$(ProjectDir)NativeLib" />
36+
</Target>
37+
3338
</Project>

0 commit comments

Comments
 (0)