-
Notifications
You must be signed in to change notification settings - Fork 19
332 lines (282 loc) · 13.9 KB
/
build-native.yml
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
name: Build Native
on:
workflow_call:
jobs:
preflight:
name: Preflight
runs-on: ubuntu-20.04
outputs:
project-version: ${{ steps.get-version.outputs.project-version }}
package-version: ${{ steps.get-version.outputs.package-version }}
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Get version
id: get-version
shell: pwsh
run: |
$CsprojXml = [Xml] (Get-Content .\ffi\dotnet\Devolutions.Sspi\Devolutions.Sspi.csproj)
$ProjectVersion = $CsprojXml.Project.PropertyGroup.Version | Select-Object -First 1
$PackageVersion = $ProjectVersion -Replace "^(\d+)\.(\d+)\.(\d+).(\d+)$", "`$1.`$2.`$3"
echo "project-version=$ProjectVersion" >> $Env:GITHUB_OUTPUT
echo "package-version=$PackageVersion" >> $Env:GITHUB_OUTPUT
build-native:
name: Native build
runs-on: ${{ matrix.runner }}
needs: preflight
strategy:
fail-fast: false
matrix:
os: [ win, osx, linux, ios, android ]
arch: [ x86, x64, arm, arm64 ]
build: [ debug, release ]
include:
- os: win
runner: windows-2022
- os: osx
runner: macos-14
- os: linux
runner: ubuntu-20.04
- os: ios
runner: macos-14
- os: android
runner: ubuntu-20.04
exclude:
- arch: arm
os: win
- arch: arm
os: osx
- arch: arm
os: linux
- arch: arm
os: ios
- arch: x86
os: win
- arch: x86
os: osx
- arch: x86
os: linux
- arch: x86
os: ios
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Configure Android NDK
if: matrix.os == 'android'
shell: pwsh
run: |
$CargoConfigFile = "~/.cargo/config.toml"
$AndroidToolchain="${Env:ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64"
Get-ChildItem -Path $AndroidToolchain "libunwind.a" -Recurse | ForEach-Object {
$libunwind = $_.FullName
$libgcc = Join-Path $_.DirectoryName "libgcc.a"
if (-Not (Test-Path $libgcc)) {
Write-Host $libgcc
Copy-Item $libunwind $libgcc
}
}
Get-ChildItem -Path "$AndroidToolchain/bin/"
echo "[target.i686-linux-android]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/i686-linux-android21-clang`"" >> $CargoConfigFile
echo "rustflags = [`"-C`", `"link-args=-z max-page-size=16384`"]" >> $CargoConfigFile
echo "CC_i686-linux-android=$AndroidToolchain/bin/i686-linux-android21-clang" >> $Env:GITHUB_ENV
echo "AR_i686-linux-android=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
echo "[target.x86_64-linux-android]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/x86_64-linux-android21-clang`"" >> $CargoConfigFile
echo "rustflags = [`"-C`", `"link-args=-z max-page-size=16384`"]" >> $CargoConfigFile
echo "CC_x86_64-linux-android=$AndroidToolchain/bin/x86_64-linux-android21-clang" >> $Env:GITHUB_ENV
echo "AR_x86_64-linux-android=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
echo "[target.armv7-linux-androideabi]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/armv7a-linux-androideabi21-clang`"" >> $CargoConfigFile
echo "rustflags = [`"-C`", `"link-args=-z max-page-size=16384`"]" >> $CargoConfigFile
echo "CC_armv7-linux-androideabi=$AndroidToolchain/bin/armv7a-linux-androideabi21-clang" >> $Env:GITHUB_ENV
echo "AR_armv7-linux-androideabi=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
echo "[target.aarch64-linux-android]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/aarch64-linux-android21-clang`"" >> $CargoConfigFile
echo "rustflags = [`"-C`", `"link-args=-z max-page-size=16384`"]" >> $CargoConfigFile
echo "CC_aarch64-linux-android=$AndroidToolchain/bin/aarch64-linux-android21-clang" >> $Env:GITHUB_ENV
echo "AR_aarch64-linux-android=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
- name: Install dependencies for rustls
if: runner.os == 'Windows'
shell: pwsh
run: |
choco install ninja nasm
# We need to add the NASM binary folder to the PATH manually.
# We don’t need to do that for ninja.
Write-Output "PATH=$Env:PATH;$Env:ProgramFiles\NASM" >> $Env:GITHUB_ENV
# libclang / LLVM is a requirement for AWS LC.
# https://aws.github.io/aws-lc-rs/requirements/windows.html#libclang--llvm
$VSINSTALLDIR = $(vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath)
Write-Output "LIBCLANG_PATH=$VSINSTALLDIR\VC\Tools\Llvm\x64\bin" >> $Env:GITHUB_ENV
# Install Visual Studio Developer PowerShell Module for cmdlets such as Enter-VsDevShell
Install-Module VsDevShell -Force
- name: Install dependencies
if: matrix.os == 'ios'
run: cargo install --force --locked bindgen-cli
- name: Setup build environment
shell: pwsh
run: |
if ('${{ matrix.os }}' -Eq 'osx') {
echo "MACOSX_DEPLOYMENT_TARGET=10.10" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
} elseif ('${{ matrix.os }}' -Eq 'ios') {
echo "IPHONEOS_DEPLOYMENT_TARGET=12.1" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
- name: Update runner
if: ${{ matrix.os == 'linux' }}
run: sudo apt-get update
# We need a newer version of GCC because aws-lc-rs rejects versions affected
# by this bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189
# These lines can be safely removed once we switch to ubuntu-22.04 runner.
- name: Install GCC 10.x
if: ${{ matrix.os == 'linux' }}
run: |
sudo apt-get install gcc-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60
- name: Build sspi (${{matrix.os}}-${{matrix.arch}}) (${{matrix.build}})
shell: pwsh
run: |
Set-PSDebug -Trace 1
$BuildType = '${{matrix.build}}'
$DotNetOs = '${{matrix.os}}'
$DotNetArch = '${{matrix.arch}}'
$DotNetRid = '${{matrix.os}}-${{matrix.arch}}'
$RustArch = @{'x64'='x86_64';'arm64'='aarch64';
'x86'='i686';'arm'='armv7'}[$DotNetArch]
$AppleArch = @{'x64'='x86_64';'arm64'='arm64';
'x86'='i386';'arm'='arm'}[$DotNetArch]
$MsvcArch = @{'x64'='x64';'arm64'='arm64'}[$DotNetArch]
$RustPlatform = @{'win'='pc-windows-msvc';
'osx'='apple-darwin';'ios'='apple-ios';
'linux'='unknown-linux-gnu';'android'='linux-android'}[$DotNetOs]
$LibPrefix = @{'win'='';'osx'='lib';'ios'='lib';
'linux'='lib';'android'='lib'}[$DotNetOs]
$LibSuffix = @{'win'='.dll';'osx'='.dylib';'ios'='.dylib';
'linux'='.so';'android'='.so'}[$DotNetOs]
$RustTarget = "$RustArch-$RustPlatform"
if (($DotNetOs -eq 'android') -and ($DotNetArch -eq 'arm')) {
$RustTarget = "armv7-linux-androideabi"
}
if ($DotNetOs -eq 'osx') {
Set-Item "Env:CFLAGS_${RustArch}-apple-darwin" "-arch $AppleArch"
}
rustup target add $RustTarget
if ($DotNetOs -eq 'win') {
Enter-VsDevShell $MsvcArch
$Env:RUSTFLAGS="-C target-feature=+crt-static"
}
if ($RustTarget -eq 'aarch64-unknown-linux-gnu') {
sudo apt-get install gcc-aarch64-linux-gnu
$Env:RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc"
}
$ProjectVersion = '${{ needs.preflight.outputs.project-version }}'
$PackageVersion = '${{ needs.preflight.outputs.package-version }}'
$CargoToml = Get-Content .\ffi\Cargo.toml
$CargoToml = $CargoToml | ForEach-Object {
if ($_.StartsWith("version =")) { "version = `"$PackageVersion`"" } else { $_ }
}
Set-Content -Path .\ffi\Cargo.toml -Value $CargoToml
$CargoArgs = @('build', '-vvv', '-p', 'sspi-ffi', '--target', $RustTarget)
if (-Not ($BuildType -Eq 'debug')) {
$CargoArgs += @('--release')
}
if ($DotNetOs -Eq 'win') {
$CargoArgs += @('--features', 'tsssp')
}
# No pregenerated Android bindings are provided for aws-lc-sys at this time.
# See: https://github.com/aws/aws-lc-rs/tree/main/aws-lc-sys#pregenerated-bindings-availability
# For simplicity, we’re using the ring crypto backend.
if ($DotNetOs -Eq 'android') {
$CargoArgs += @('--no-default-features', '--features', 'scard,ring')
}
$CargoCmd = $(@('cargo') + $CargoArgs) -Join ' '
Write-Host $CargoCmd
& cargo $CargoArgs | Out-Host
$OutputLibraryName = "${LibPrefix}sspi$LibSuffix"
$RenamedLibraryName = "${LibPrefix}DevolutionsSspi$LibSuffix"
$OutputLibrary = Join-Path "target" $RustTarget $BuildType $OutputLibraryName
$OutputPath = Join-Path "dependencies" "runtimes" $DotNetRid "native"
New-Item -ItemType Directory -Path $OutputPath | Out-Null
Copy-Item $OutputLibrary $(Join-Path $OutputPath $RenamedLibraryName)
- name: Upload native components
uses: actions/upload-artifact@v4
with:
name: sspi-${{matrix.os}}-${{matrix.arch}}-${{matrix.build}}
path: dependencies/runtimes/${{matrix.os}}-${{matrix.arch}}
build-universal:
name: Universal Build
runs-on: ubuntu-20.04
needs: [preflight, build-native]
strategy:
fail-fast: false
matrix:
os: [ osx, ios ]
build: [ debug, release ]
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Configure runner
run: |
wget -q https://github.com/awakecoding/llvm-prebuilt/releases/download/v2022.2.0/cctools-x86_64-ubuntu-20.04.tar.xz
tar -xf cctools-x86_64-ubuntu-20.04.tar.xz -C /tmp
sudo mv /tmp/cctools-x86_64-ubuntu-20.04/bin/lipo /usr/local/bin
sudo mv /tmp/cctools-x86_64-ubuntu-20.04/bin/install_name_tool /usr/local/bin
- name: Download native components
uses: actions/download-artifact@v4
with:
path: dependencies/runtimes
- name: Lipo (${{matrix.build}})
shell: pwsh
run: |
Set-Location "dependencies/runtimes"
# No RID for universal binaries, see: https://github.com/dotnet/runtime/issues/53156
$OutputPath = Join-Path "${{ matrix.os }}-universal" "native"
New-Item -ItemType Directory -Path $OutputPath | Out-Null
$Libraries = Get-ChildItem -Recurse -Path "sspi-${{ matrix.os }}-*-${{ matrix.build }}" -Filter "*.dylib" | Foreach-Object { $_.FullName } | Select -Unique
$LipoCmd = $(@('lipo', '-create', '-output', (Join-Path -Path $OutputPath -ChildPath "libDevolutionsSspi.dylib")) + $Libraries) -Join ' '
Write-Host $LipoCmd
Invoke-Expression $LipoCmd
- name: Framework (${{matrix.build}})
shell: pwsh
if: ${{ matrix.os == 'ios' }}
run: |
$Version = '${{ needs.preflight.outputs.project-version }}'
$ShortVersion = '${{ needs.preflight.outputs.package-version }}'
$BundleName = "libDevolutionsSspi"
$RuntimesDir = Join-Path "dependencies" "runtimes" "ios-universal" "native"
$FrameworkDir = Join-Path "$RuntimesDir" "$BundleName.framework"
New-Item -Path $FrameworkDir -ItemType "directory" -Force
$FrameworkExecutable = Join-Path $FrameworkDir $BundleName
Copy-Item -Path (Join-Path "$RuntimesDir" "$BundleName.dylib") -Destination $FrameworkExecutable -Force
$RPathCmd = $(@('install_name_tool', '-id', "@rpath/$BundleName.framework/$BundleName", "$FrameworkExecutable")) -Join ' '
Write-Host $RPathCmd
Invoke-Expression $RPathCmd
[xml] $InfoPlistXml = Get-Content "Info.plist"
Select-Xml -xml $InfoPlistXml -XPath "/plist/dict/key[. = 'CFBundleIdentifier']/following-sibling::string[1]" |
%{
$_.Node.InnerXml = "com.devolutions.sspi"
}
Select-Xml -xml $InfoPlistXml -XPath "/plist/dict/key[. = 'CFBundleExecutable']/following-sibling::string[1]" |
%{
$_.Node.InnerXml = $BundleName
}
Select-Xml -xml $InfoPlistXml -XPath "/plist/dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" |
%{
$_.Node.InnerXml = $Version
}
Select-Xml -xml $InfoPlistXml -XPath "/plist/dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" |
%{
$_.Node.InnerXml = $ShortVersion
}
# Write the plist *without* a BOM
$Encoding = New-Object System.Text.UTF8Encoding($false)
$Writer = New-Object System.IO.StreamWriter((Join-Path $FrameworkDir "Info.plist"), $false, $Encoding)
$InfoPlistXml.Save($Writer)
$Writer.Close()
# .NET XML document inserts two square brackets at the end of the DOCTYPE tag
# It's perfectly valid XML, but we're dealing with plists here and dyld will not be able to read the file
((Get-Content -Path (Join-Path $FrameworkDir "Info.plist") -Raw) -Replace 'PropertyList-1.0.dtd"\[\]', 'PropertyList-1.0.dtd"') | Set-Content -Path (Join-Path $FrameworkDir "Info.plist")
- name: Upload native components
uses: actions/upload-artifact@v4
with:
name: sspi-${{ matrix.os }}-universal-${{ matrix.build }}
path: dependencies/runtimes/${{ matrix.os }}-universal