-
Notifications
You must be signed in to change notification settings - Fork 821
362 lines (326 loc) · 15.3 KB
/
build_nuget.yml
File metadata and controls
362 lines (326 loc) · 15.3 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
name: nuget build & publish
on:
push:
paths:
- unity/upms/**
- unity/test/**
- unity/native/**
- unity/cli/**
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h
- unreal/Puerts/Source/JsEnv/Private/WebSocketImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/PromiseRejectCallback.hpp
- .github/workflows/build_nuget.yml
pull_request:
paths:
- unity/upms/**
- unity/test/**
- unity/native/**
- unity/cli/**
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h
- unreal/Puerts/Source/JsEnv/Private/WebSocketImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/PromiseRejectCallback.hpp
- .github/workflows/build_nuget.yml
workflow_dispatch:
inputs:
publish:
description: 'Publish package?'
required: true
default: false
type: boolean
jobs:
build:
runs-on: ${{ matrix.os }}
env:
NATIVE_BACKENDS: puerts papi-lua papi-quickjs papi-v8 papi-nodejs papi-python
strategy:
matrix:
include:
- os: ubuntu-22.04
platform: linux
arch: x64
- os: windows-2022
platform: win
arch: x64
- os: macos-15
platform: osx
arch: arm64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Install libc++-dev (Linux only)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y clang libc++-dev libc++abi-dev
- name: Build all native backends (Linux)
if: runner.os == 'Linux'
run: |
set -ex
backends="${NATIVE_BACKENDS}"
repo_root=$(pwd)
for backend in $backends; do
echo "Building $backend for ${{ matrix.platform }}-${{ matrix.arch }}"
cd "$repo_root/unity/native/$backend"
node ../../cli make --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} --expose_gc
cd "$repo_root"
done
# Copy system Python's lib-dynload directory
python_version=$(python3 --version | awk '{print $2}' | cut -d. -f1,2)
echo "Python version: $python_version"
# Find lib-dynload directory using sysconfig
lib_dynload_path=$(python3 -c "import sysconfig; import os; stdlib = sysconfig.get_path('stdlib'); print(os.path.join(stdlib, 'lib-dynload'))")
echo "lib-dynload path: $lib_dynload_path"
if [ -d "$lib_dynload_path" ]; then
dest_path="$repo_root/unity/native/papi-python/build_linux_x64_papi-python/lib-dynload"
mkdir -p "$dest_path"
cp -r "$lib_dynload_path"/* "$dest_path/"
echo "Copied lib-dynload to $dest_path"
ls -la "$dest_path"
else
echo "Warning: lib-dynload directory not found at $lib_dynload_path"
fi
- name: Build all native backends (macOS)
if: runner.os == 'macOS'
run: |
set -ex
backends="${NATIVE_BACKENDS}"
repo_root=$(pwd)
for backend in $backends; do
echo "Building $backend for ${{ matrix.platform }}"
cd "$repo_root/unity/native/$backend"
node ../../cli make --platform ${{ matrix.platform }} --arch arm64 --expose_gc
cd "$repo_root"
done
- name: Build all native backends (Windows)
if: runner.os == 'Windows'
run: |
$ErrorActionPreference = "Stop"
$backends = $env:NATIVE_BACKENDS.Split(" ")
$repoRoot = (Get-Location)
foreach ($backend in $backends) {
Write-Host "Building $backend for ${{ matrix.platform }}-${{ matrix.arch }}"
Set-Location "$repoRoot/unity/native/$backend"
node ../../cli make --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} --expose_gc
Set-Location $repoRoot
}
shell: pwsh
# See: https://github.com/Tencent/puerts/blob/e230b37c313c62185ceb5207c37e79e53e1afada/unity/cli/make.mjs#L173
# mv(`${CMAKE_BUILD_PATH}/${options.config}/lib${cmakeAddedLibraryName}.dylib`, `${CMAKE_BUILD_PATH}/${options.config}/${cmakeAddedLibraryName}.bundle`);
# generated builds unity/upms/*/Plugins/macOS/*.bundle
# Rename macOS bundle format to dylib files to ensure upload-artifact works correctly
- name: Process macOS native artifacts
if: runner.os == 'macOS'
run: |
set -ex
for dir in unity/upms/*/Plugins/macOS; do
if [ -d "$dir" ]; then
for file in "$dir"/*.bundle; do
[ -f "$file" ] && mv -n "$file" "${file%.bundle}.dylib"
echo "Renamed $file to ${file%.bundle}.dylib"
done
fi
done
# puerts\unity\native\papi-nodejs\.backends\papi-nodejs\lib\Linux\libnode.so.93
# puerts\unity\native\papi-nodejs\.backends\papi-nodejs\lib\Win64\libnode.dll
# puerts\unity\native\papi-nodejs\.backends\papi-nodejs\lib\macOS\libnode.93.dylib
- name: Process libraries dependencies
run: |
# Move libnode libraries to build directories
if ("${{ matrix.platform }}" -eq "linux") {
if (Test-Path "unity/native/papi-nodejs/build_linux_x64_papi-nodejs") {
Move-Item -Path "unity/native/papi-nodejs/.backends/papi-nodejs/lib/Linux/libnode.so.93" -Destination "unity/native/papi-nodejs/build_linux_x64_papi-nodejs/libnode.so.93" -Force
}
if (Test-Path "unity/native/papi-python/build_linux_x64_papi-python") {
# Remove python's libPuertsCore.so on Linux
Remove-Item "unity/native/papi-python/build_linux_x64_papi-python/libPuertsCore.so" -Force
}
}
if ("${{ matrix.platform }}" -eq "win" -and (Test-Path "unity/native/papi-nodejs/build_win_x64_papi-nodejs/Release")) {
Move-Item -Path "unity/native/papi-nodejs/.backends/papi-nodejs/lib/Win64/libnode.dll" -Destination "unity/native/papi-nodejs/build_win_x64_papi-nodejs/Release/libnode.dll" -Force
}
if ("${{ matrix.platform }}" -eq "osx" -and (Test-Path "unity/upms/nodejs/Plugins/macOS")) {
Move-Item -Path "unity/native/papi-nodejs/.backends/papi-nodejs/lib/macOS/libnode.93.dylib" -Destination "unity/upms/nodejs/Plugins/macOS/libnode.93.dylib" -Force
$oldPath = "/Library/Frameworks/Python.framework/Versions/3.14/Python"
$newPath = "@loader_path/libpython3.14.dylib"
$plugin = "unity/upms/python/Plugins/macOS/arm64/libPapiPython.dylib"
install_name_tool -change $oldPath $newPath $plugin
}
if ("${{ matrix.platform }}" -eq "win") {
# Remove python's PuertsCore.dll on Windows
$puertsCorePath = "unity/native/papi-python/build_win_x64_papi-python/Release/PuertsCore.dll"
if (Test-Path $puertsCorePath) {
Remove-Item $puertsCorePath -Force
Write-Host "Removed $puertsCorePath to avoid duplicate PuertsCore.dll."
}
}
shell: pwsh
- name: Upload all native artifacts
uses: actions/upload-artifact@v4
with:
name: natives-${{ matrix.platform }}-${{ matrix.arch }}
path: |
unity/upms/core/Plugins/**/*.dylib
unity/upms/v8/Plugins/**/*.dylib
unity/upms/nodejs/Plugins/**/*.dylib
unity/upms/lua/Plugins/**/*.dylib
unity/upms/python/Plugins/**/*.dylib
unity/upms/quickjs/Plugins/**/*.dylib
unity/native/papi-lua/build_${{ matrix.platform }}_${{ matrix.arch }}_*/Release/*.dll
unity/native/papi-lua/build_${{ matrix.platform }}_${{ matrix.arch }}_*/lib*.so
unity/native/papi-nodejs/build_${{ matrix.platform }}_${{ matrix.arch }}_*/Release/*.dll
unity/native/papi-nodejs/build_${{ matrix.platform }}_${{ matrix.arch }}_*/lib*.so
unity/native/papi-nodejs/build_linux_x64_papi-nodejs/libnode.so.93
unity/native/papi-quickjs/build_${{ matrix.platform }}_${{ matrix.arch }}_*/Release/*.dll
unity/native/papi-quickjs/build_${{ matrix.platform }}_${{ matrix.arch }}_*/lib*.so
unity/native/papi-v8/build_${{ matrix.platform }}_${{ matrix.arch }}_*/Release/*.dll
unity/native/papi-v8/build_${{ matrix.platform }}_${{ matrix.arch }}_*/lib*.so
unity/native/papi-python/build_${{ matrix.platform }}_${{ matrix.arch }}_*/Release/*.dll
unity/native/papi-python/build_${{ matrix.platform }}_${{ matrix.arch }}_*/lib*.so
unity/native/papi-python/build_linux_x64_papi-python/lib-dynload/**
unity/native/puerts/build_${{ matrix.platform }}_${{ matrix.arch }}_*/Release/*.dll
unity/native/puerts/build_${{ matrix.platform }}_${{ matrix.arch }}_*/lib*.so
pack_nuget:
name: Pack NuGet
needs: build
runs-on: windows-2022
steps:
- uses: actions/checkout@v4
- name: Download all native artifacts
uses: actions/download-artifact@v4
with:
path: unity/nuget/downloaded_natives
- name: List downloaded artifacts
run: |
ls unity/nuget/downloaded_natives
tree unity/nuget/downloaded_natives /F
shell: pwsh
- name: Download Python (Windows)
run: |
$destPath = "unity/nuget/downloaded_natives/natives-win-x64/native/papi-python/build_win_x64_papi-python/Release"
$downloadedEmbedZip = "$env:TEMP/python-3.14.2-embed-amd64.zip"
$downloadUrl = "https://www.python.org/ftp/python/3.14.2/python-3.14.2-embed-amd64.zip"
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadedEmbedZip
Expand-Archive -Path $downloadedEmbedZip -DestinationPath $destPath -Force
shell: pwsh
- name: Download Python (Linux)
run: |
$destPath = "unity/nuget/downloaded_natives/natives-linux-x64/native/papi-python/build_linux_x64_papi-python"
$downloadedEmbedZip = "unity/nuget/cpython-3.14.2+20251217-x86_64_v2-unknown-linux-gnu-install_only_stripped.tar.gz"
$downloadUrl = "https://github.com/astral-sh/python-build-standalone/releases/download/20251217/cpython-3.14.2+20251217-x86_64_v2-unknown-linux-gnu-install_only_stripped.tar.gz"
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadedEmbedZip
tar -xzf $downloadedEmbedZip -C $destPath
# Move $destPath/python3.14 to $destPath/lib
Move-Item -Path "$destPath/python/lib/*" -Destination $destPath -Force
mkdir "$destPath/lib"
Move-Item -Path "$destPath/python3.14" -Destination "$destPath/lib" -Force
Remove-Item -Path "$destPath/python" -Recurse -Force
# Copy system lib-dynload files to extracted Python directory
$systemLibDynloadPath = "$destPath/lib-dynload"
$targetLibDynloadPath = "$destPath/lib/python3.14/lib-dynload"
if (Test-Path $systemLibDynloadPath) {
Write-Host "Copying system lib-dynload files to $targetLibDynloadPath"
if (-not (Test-Path $targetLibDynloadPath)) {
New-Item -ItemType Directory -Path $targetLibDynloadPath -Force | Out-Null
}
Get-ChildItem -Path $systemLibDynloadPath -File | ForEach-Object {
$targetFile = Join-Path $targetLibDynloadPath $_.Name
if (-not (Test-Path $targetFile)) {
Copy-Item -Path $_.FullName -Destination $targetFile -Force
Write-Host "Copied $($_.Name)"
} else {
Write-Host "Skipped $($_.Name) (already exists)"
}
}
# Remove the temporary lib-dynload directory
Remove-Item -Path $systemLibDynloadPath -Recurse -Force
Write-Host "Removed temporary lib-dynload directory"
} else {
Write-Host "Warning: System lib-dynload directory not found at $systemLibDynloadPath"
}
shell: pwsh
- name: Download Python (macOS)
run: |
$destPath = "unity/nuget/downloaded_natives/natives-osx-arm64/upms/python/Plugins/macOS/arm64"
$downloadedEmbedZip = "$env:TEMP/cpython-3.14.2+20260127-aarch64-apple-darwin-install_only.tar.gz"
$downloadUrl = "https://github.com/astral-sh/python-build-standalone/releases/download/20260127/cpython-3.14.2+20260127-aarch64-apple-darwin-install_only.tar.gz"
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadedEmbedZip
tree unity/nuget/downloaded_natives
tar -xzf $downloadedEmbedZip -C $destPath
# Move $destPath/python3.14 to $destPath/lib
Move-Item -Path "$destPath/python/lib/*" -Destination $destPath -Force
mkdir "$destPath/lib"
Move-Item -Path "$destPath/python3.14" -Destination "$destPath/lib" -Force
Remove-Item -Path "$destPath/python" -Recurse -Force
shell: pwsh
- name: Run NuGet Packaging and Publishing
if: ${{ github.event.inputs.publish == 'true' }}
run: |
cd unity/nuget
.\build.ps1 --NativeAssetsDirectory "$pwd\downloaded_natives" --ProjectsRoot "$pwd" --Source "https://api.nuget.org/v3/index.json" --ApiKey "${{ secrets.NUGET_API_KEY }}"
shell: pwsh
- name: Run NuGet Packaging
if: ${{ github.event.inputs.publish != 'true' }}
run: |
cd unity/nuget
.\build.ps1 --NativeAssetsDirectory "$pwd\downloaded_natives" --ProjectsRoot "$pwd"
shell: pwsh
- name: Upload NuGet Packages
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: |
unity/nuget/packageOutput/*.nupkg
unity/nuget/packageOutput/*.snupkg
windows_test:
name: window unit test
needs: pack_nuget
runs-on: windows-2022
if: ${{ github.event.inputs.publish != 'true' }}
steps:
- uses: actions/checkout@v4
- name: Download nuget-packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: unity/test/nuget/nuget-packages
- name: Run dotnet test
run: |
cd unity/test/nuget/projects
dotnet test
shell: pwsh
linux_test:
name: linux unit test
needs: pack_nuget
runs-on: ubuntu-22.04
if: ${{ github.event.inputs.publish != 'true' }}
steps:
- uses: actions/checkout@v4
- name: Download nuget-packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: unity/test/nuget/nuget-packages
- name: Run dotnet test
run: |
cd unity/test/nuget/projects
dotnet test
osx_test:
name: macOS unit test
needs: pack_nuget
runs-on: macos-15
if: ${{ github.event.inputs.publish != 'true' }}
steps:
- uses: actions/checkout@v4
- name: Download nuget-packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: unity/test/nuget/nuget-packages
- name: Run dotnet test
run: |
cd unity/test/nuget/projects
dotnet test