Skip to content

Commit f179c1d

Browse files
committed
尝试加入mac和linux库的打包
1 parent 7c85e20 commit f179c1d

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

.github/workflows/build_nuget.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,45 @@ jobs:
174174
ls unity/nuget/downloaded_natives
175175
tree unity/nuget/downloaded_natives /F
176176
shell: pwsh
177-
- name: Download Python
177+
- name: Download Python (Windows)
178178
run: |
179179
$destPath = "unity\nuget\downloaded_natives\natives-win-x64\native\papi-python\build_win_x64_papi-python\Release"
180+
New-Item -ItemType Directory -Force -Path $destPath
180181
$downloadedEmbedZip = "$env:TEMP\python-3.14.2-embed-amd64.zip"
181182
$downloadUrl = "https://www.python.org/ftp/python/3.14.2/python-3.14.2-embed-amd64.zip"
182183
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadedEmbedZip
183184
Expand-Archive -Path $downloadedEmbedZip -DestinationPath $destPath -Force
184185
shell: pwsh
186+
187+
- name: Download Python Standalone (Linux)
188+
run: |
189+
$destPath = "unity/nuget/downloaded_natives/natives-linux-x64/native/papi-python/build_linux_x64_papi-python"
190+
New-Item -ItemType Directory -Force -Path $destPath
191+
192+
# Download from python-build-standalone
193+
$pythonUrl = "https://github.com/astral-sh/python-build-standalone/releases/download/20251217/cpython-3.14.2+20251217-x86_64-unknown-linux-gnu-install_only.tar.gz"
194+
$downloadedTar = "$env:TEMP/python-linux.tar.gz"
195+
Invoke-WebRequest -Uri $pythonUrl -OutFile $downloadedTar
196+
197+
# Extract (requires tar command available on Windows)
198+
tar -xzf $downloadedTar -C $destPath --strip-components=1
199+
shell: pwsh
200+
201+
- name: Download Python Standalone (macOS)
202+
run: |
203+
# For macOS, we need to put files in the upms structure first
204+
# The TransformNativeAssetsTask will handle moving them to the correct location
205+
$destPath = "unity/nuget/downloaded_natives/natives-osx-auto/upms/python/Plugins/macOS/arm64"
206+
New-Item -ItemType Directory -Force -Path $destPath
207+
208+
# Download macOS arm64 version from python-build-standalone
209+
$pythonUrl = "https://github.com/astral-sh/python-build-standalone/releases/download/20251217/cpython-3.14.2+20251217-aarch64-apple-darwin-install_only.tar.gz"
210+
$downloadedTar = "$env:TEMP/python-macos.tar.gz"
211+
Invoke-WebRequest -Uri $pythonUrl -OutFile $downloadedTar
212+
213+
# Extract
214+
tar -xzf $downloadedTar -C $destPath --strip-components=1
215+
shell: pwsh
185216
- name: Run NuGet Packaging and Publishing
186217
if: ${{ github.event.inputs.publish == 'true' }}
187218
run: |

unity/nuget/build/Program.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ public override void Run(BuildContext context)
163163

164164
context.CopyFiles(dylibFiles, targetBuildDir.FullPath);
165165

166+
// for Python, also copy the entire Python runtime (lib, include, etc.)
167+
if (projectItem.DotNetNativeName == "Python")
168+
{
169+
// Copy all Python runtime files and directories
170+
var pythonRuntimePattern = $"{backendPluginsRoot.FullPath}/**/*";
171+
var allPythonFiles = context.GetFiles(
172+
new GlobPattern(pythonRuntimePattern),
173+
new GlobberSettings { IsCaseSensitive = false });
174+
175+
foreach (var file in allPythonFiles)
176+
{
177+
var relativePath = file.FullPath.Substring(backendPluginsRoot.FullPath.Length + 1);
178+
var targetFile = System.IO.Path.Combine(targetBuildDir.FullPath, relativePath);
179+
var targetFileDir = System.IO.Path.GetDirectoryName(targetFile);
180+
Directory.CreateDirectory(targetFileDir);
181+
context.CopyFile(file, targetFile);
182+
}
183+
184+
context.Log.Information($"Copied Python runtime files from '{backendPluginsRoot.FullPath}' to '{targetBuildDir.FullPath}'");
185+
}
186+
166187
// for NodeJS, also copy libnode*.dylib
167188
if (projectItem.DotNetNativeName == "NodeJS")
168189
{
@@ -251,7 +272,24 @@ public override void Run(BuildContext context)
251272
Directory.CreateDirectory(targetDirectory.FullPath);
252273

253274
var files = context.GetFiles(new GlobPattern($"{nativeAssetsPath.FullPath}/**/*"));
254-
context.CopyFiles(files, targetDirectory.FullPath);
275+
276+
// For Python, we need to preserve directory structure
277+
if (projectItem.DotNetNativeName == "Python")
278+
{
279+
foreach (var file in files)
280+
{
281+
var relativePath = file.FullPath.Substring(nativeAssetsPath.FullPath.Length + 1);
282+
var targetFile = System.IO.Path.Combine(targetDirectory.FullPath, relativePath);
283+
var targetFileDir = System.IO.Path.GetDirectoryName(targetFile);
284+
Directory.CreateDirectory(targetFileDir);
285+
context.CopyFile(file, targetFile);
286+
}
287+
context.Log.Information($"Copied Python runtime with directory structure preserved to '{targetDirectory.FullPath}'");
288+
}
289+
else
290+
{
291+
context.CopyFiles(files, targetDirectory.FullPath);
292+
}
255293
}
256294
}
257295
}

0 commit comments

Comments
 (0)