-
Notifications
You must be signed in to change notification settings - Fork 240
207 lines (180 loc) · 8.6 KB
/
build-native-nuget.yml
File metadata and controls
207 lines (180 loc) · 8.6 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
name: build-native-nuget
on:
push:
branches:
- master
paths:
- .github/workflows/build-native-nuget.yml
workflow_dispatch:
permissions:
packages: write
env:
PADDLE_VERSION: "3.3.0"
jobs:
build-all:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- { title: win64.mkl, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_mkldnn }
- { title: win64.openblas, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_openblas }
- { title: win64.openblas-noavx, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_openblas_noavx }
- { title: win64.cu129_cudnn910_sm61, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_cu129_cudnn910_sm61 }
- { title: win64.cu129_cudnn910_sm75, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_cu129_cudnn910_sm75 }
- { title: win64.cu129_cudnn910_sm86, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_cu129_cudnn910_sm86 }
- { title: win64.cu129_cudnn910_sm89, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_cu129_cudnn910_sm89 }
- { title: win64.cu129_cudnn910_sm120, rid: win-x64, action: paddle-build.yml, artifact: windows-2022_c_cu129_cudnn910_sm120 }
- { title: linux-x64.openblas, rid: linux-x64, action: paddle-build.yml, artifact: ubuntu-22.04_c_openblas }
- { title: linux-x64.mkl, rid: linux-x64, action: paddle-build.yml, artifact: ubuntu-22.04_c_mkldnn }
- { title: linux-x64, rid: linux-x64, action: paddle-build.yml, artifact: ubuntu-22.04_c_openvino }
- { title: linux-arm64, rid: linux-arm64, action: paddle-build.yml, artifact: ubuntu-22.04-arm_c_openblas }
- { title: osx-arm64, rid: osx-arm64, action: paddle-build.yml, artifact: macos-15_c_openblas }
steps:
- name: Download Artifacts
env:
# NOTE: downloading artifacts from a different repo may require a PAT.
# If `github.token` can't access the upstream repo artifacts, create a secret `PADDLE_GH_TOKEN`.
GH_TOKEN: ${{ github.token }}
run: |
UPSTREAM_REPO="sdcb/Paddle"
UPSTREAM_WORKFLOW="build.yml"
echo "arch=$(echo '${{ matrix.rid }}' | awk -F'-' '{print $NF}')" >> $GITHUB_ENV
echo "Fetching latest successful $UPSTREAM_WORKFLOW run of repo $UPSTREAM_REPO (all branches)"
RUN_ID=$(gh run list -R "$UPSTREAM_REPO" \
--workflow="$UPSTREAM_WORKFLOW" \
--status=success --limit=1 \
--json databaseId | jq -r '.[0].databaseId')
echo "Run id = $RUN_ID"
echo "Download artifact ${{ matrix.artifact }}"
gh run download -R "$UPSTREAM_REPO" "$RUN_ID" --name "${{ matrix.artifact }}" --dir paddle_inference_c
echo "::group::Artifact tree"
ls -lR paddle_inference_c
echo "::endgroup::"
- name: Show Downloaded
run: |
ls -lR paddle_inference_c
- name: Copy Native Dynamic Libs(.so/.dll/.dylib) to nuget
run: |
mkdir -p nuget
if [[ "${{ matrix.rid }}" == win* ]]; then
find paddle_inference_c -type f \( -iname "*.dll" \) -exec cp {} nuget/ \;
elif [[ "${{ matrix.rid }}" == linux* ]]; then
find paddle_inference_c -type f \( -iname "*.so*" \) -exec cp {} nuget/ \;
elif [[ "${{ matrix.rid }}" == osx* ]]; then
find paddle_inference_c -type f \( -iname "*.dylib" \) -exec cp {} nuget/ \;
fi
ls -l nuget
- name: Build NuGet package
run: |
set -euo pipefail
# ---------- 基本元数据 ----------
PKG_ID="Sdcb.PaddleInference.runtime.${{ matrix.title }}"
AUTHOR="sdcb"
LICENSE="Apache-2.0"
GIT_URL="https://github.com/sdcb/PaddleSharp"
TAGS="Sdcb PaddleSharp AI Paddle OCR PaddleOCR linqpad-samples"
YEAR=$(date +%Y)
# ---------- 找到所有动态库 ----------
NUGET_LIB_DIR="${{ github.workspace }}/nuget"
LIB_PATHS=()
mapfile -t LIB_PATHS < <(find "$NUGET_LIB_DIR" -type f -print)
if [ ${#LIB_PATHS[@]} -eq 0 ]; then
echo "Error: no native libs found in $NUGET_LIB_DIR"
exit 1
fi
# ---------- 准备临时工作目录 ----------
WORK="$RUNNER_TEMP/pkg"
rm -rf "$WORK"
mkdir -p \
"$WORK/runtimes/${{ matrix.rid }}/native" \
"$WORK/lib/netstandard2.0" \
"$WORK/lib/net45" \
"$WORK/build/net45"
# ---------- 复制所有动态库 ----------
for libpath in "${LIB_PATHS[@]}"; do
cp "$libpath" "$WORK/runtimes/${{ matrix.rid }}/native/"
done
# 放两个占位文件
touch "$WORK/lib/netstandard2.0/_._"
cp "$WORK/lib/netstandard2.0/_._" "$WORK/lib/net45/_._"
# ---------- 生成 .props ----------
NORMALIZED_NAME="$(echo "${PKG_ID}" | tr '.-' '_' )_Dlls"
PROPS_FILE="$WORK/build/net45/${PKG_ID}.props"
{
cat <<EOF
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<${NORMALIZED_NAME}>\$(MSBuildThisFileDirectory)..\\..\\runtimes</${NORMALIZED_NAME}>
</PropertyGroup>
EOF
# 每个库都插一段 ItemGroup
for libpath in "${LIB_PATHS[@]}"; do
libname="$(basename "$libpath")"
cat <<EOF
<ItemGroup Condition="\$(TargetFrameworkVersion.StartsWith('v4')) Or \$(TargetFramework.StartsWith('net4'))">
<Content Include="\$(${NORMALIZED_NAME})\\${{ matrix.rid }}\\native\\${libname}">
<Link>dll\\${{ env.arch }}\\${libname}</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
EOF
done
echo "</Project>"
} > "$PROPS_FILE"
# ---------- 生成 .nuspec ----------
NUSPEC_FILE="$WORK/${PKG_ID}.nuspec"
{
cat <<EOF
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>${PKG_ID}</id>
<version>${{ env.PADDLE_VERSION }}.${{ github.run_number }}</version>
<title>${PKG_ID} native bindings</title>
<authors>${AUTHOR}</authors>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>${{ matrix.rid }} native libs for PaddleInference.</description>
<summary>${{ matrix.rid }} native libs for PaddleInference.</summary>
<copyright>Copyright ${YEAR}</copyright>
<license type="expression">${LICENSE}</license>
<projectUrl>${GIT_URL}</projectUrl>
<repository type="git" url="${GIT_URL}.git" />
<tags>${TAGS}</tags>
<dependencies />
<frameworkAssemblies />
</metadata>
<files>
<file src="lib\\netstandard2.0\\_._" target="lib\\netstandard2.0" />
<file src="lib\\net45\\_._" target="lib\\net45" />
EOF
# 每个库都加一行 file
for libpath in "${LIB_PATHS[@]}"; do
libname="$(basename "$libpath")"
cat <<EOF
<file src="runtimes\\${{ matrix.rid }}\\native\\${libname}" target="runtimes\\${{ matrix.rid }}\\native" />
EOF
done
# 最后再把 props 文件也加进来
cat <<EOF
<file src="build\\net45\\${PKG_ID}.props" target="build\\net45" />
</files>
</package>
EOF
} > "$NUSPEC_FILE"
# ---------- 打包 ----------
pushd "$WORK" >/dev/null
nuget pack "${NUSPEC_FILE}" -OutputDirectory "${{ github.workspace }}/nupkgs"
popd >/dev/null
echo "::group::生成的 nupkg"
ls -l "${{ github.workspace }}/nupkgs"
echo "::endgroup::"
echo NUPKG_PATH="${{ github.workspace }}/nupkgs/${PKG_ID}.${{ env.PADDLE_VERSION }}.${{ github.run_number }}.nupkg" >> $GITHUB_ENV
- name: Upload nupkg artifact
uses: actions/upload-artifact@v4
with:
name: nuget-${{ matrix.title }}
path: ${{ env.NUPKG_PATH }}
if-no-files-found: error
- name: Push nupkg to Github Packages
run: |
dotnet nuget push ${{ env.NUPKG_PATH }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}" --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate