-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_rust.ps1
48 lines (40 loc) · 1.53 KB
/
build_rust.ps1
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
Push-Location
# Step 0: Get the host's cpu architecture
$arch = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
"X64" { "x64" }
"X86" { "x86" }
"Arm" { "arm" }
"Arm64" { "arm64" }
Default { "unknown" }
}
# Step 1: Read the version from VERSION.txt
$version = Get-Content -Path ".\NATIVE_LIB_VERSION.txt"
Write-Output "Version: $version"
# Step 2: Replace the version in Cargo.toml
$cargoTomlPath = ".\rust\Cargo.toml"
$cargoContent = Get-Content -Path $cargoTomlPath
$cargoContent = $cargoContent -replace '(?<=^version\s*=\s*")[^"]*', $version
Set-Content -Path $cargoTomlPath -Value $cargoContent
Write-Output "Updated version in Cargo.toml"
# Step 3: Replace the version in every .nuspec file
# If we just use $arch, other .nuspec file won't be updated since $arch only contains the current architecture
$archList = @("x64", "arm64")
foreach ($currentArch in $archList) {
$nuspecFilePath = ".\nuget\win-$currentArch\Tokenizers.DotNet.runtime.win-$currentArch.nuspec"
$nuspecContent = Get-Content -Path $nuspecFilePath
$nuspecContent = $nuspecContent -replace '(?<=<version>)[^<]*', $version
Set-Content -Path $nuspecFilePath -Value $nuspecContent
}
Write-Output "Updated version in nuspec file"
# Step 4: Build the library
Set-Location -Path "rust"
cargo build --release
if ($LASTEXITCODE -ne 0) {
Pop-Location
exit $LASTEXITCODE
}
&.\copy_libs.ps1
Set-Location -Path ".."
Set-Location -Path "nuget\win-$arch"
nuget pack Tokenizers.DotNet.runtime.win-$arch.nuspec
Pop-Location