Skip to content

Commit

Permalink
[build] Added support for Windows on Arm64 (#3110).
Browse files Browse the repository at this point in the history
When building the libsrt binary installer for Windows, also build the
libraries for Arm64 target, in addition to Win32 and Win64. The
build can be performed anywhere, Visual Studio can build for distinct
targets. Before the build on Intel, make sure that your VS installation
includes the build tools for Arm64. See scripts/win-installer/README.md
for more details.

On existing build systems, be sure to run install-openssl.ps1 once to
make sure that the Arm64 libraries for OpenSSL are installed.

Also fixed a few harmless warnings.
  • Loading branch information
lelegard authored Feb 13, 2025
1 parent 5cd2414 commit bc8a084
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 44 deletions.
13 changes: 10 additions & 3 deletions scripts/win-installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ libsrt on Windows systems for Visual Studio applications using SRT.

### Prerequisites

These first two steps need to be executed once only.
These initial steps need to be executed once only.

- Prerequisite 1: Install OpenSSL for Windows, both 64 and 32 bits.
- Prerequisite 1: Install Visual Studio. The free Community Edition is recommended
for open-source software. See https://visualstudio.microsoft.com/. Be sure to
install the compilation tools for the all target architectures, including 64-bit Arm.
In the Visual Studio Installer program, select "Modify" -> "Individual Components".
In section "Compilers, build tools, and runtimes", select "MSVC v143 - VS2022 C++
ARM64/ARM64EC build tools (latest)" (the exact version may vary).

- Prerequisite 2: Install OpenSSL for Windows, 64-bit Intel, 32-bit Intel, 64-bit Arm.
This can be done automatically by running the PowerShell script `install-openssl.ps1`.

- Prerequisite 2: Install NSIS, the NullSoft Installation Scripting system.
- Prerequisite 3: Install NSIS, the NullSoft Installation Scripting system.
This can be done automatically by running the PowerShell script `install-nsis.ps1`.

### Building the libsrt installer
Expand Down
49 changes: 31 additions & 18 deletions scripts/win-installer/build-win-installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ $SSL = @{
"bits" = 32;
"root" = "C:\Program Files (x86)\OpenSSL-Win32"
}
"ARM64" = @{
"alt" = "arm64";
"bits" = 64;
"root" = "C:\Program Files\OpenSSL-Win64-ARM"
};
}

# Verify OpenSSL directories and static libraries.
Write-Output "Searching OpenSSL libraries ..."
$Missing = 0
foreach ($arch in @("x64", "Win32")) {
foreach ($arch in $SSL.Keys) {
$root = $SSL[$arch]["root"]
$bits = $SSL[$arch]["bits"]
$alt = $SSL[$arch]["alt"]
Expand All @@ -125,7 +130,6 @@ foreach ($arch in @("x64", "Win32")) {
"$root\lib\VC\${alt}\${conf}\lib${lib}_static.lib")) {
if (Test-Path $try) {
$SSL[$arch][$name] = $try
New-Variable "lib${lib}${bits}${conf}" "$try"
break
}
}
Expand Down Expand Up @@ -180,24 +184,29 @@ Write-Output "NSIS: $NSIS"


#-----------------------------------------------------------------------------
# Configure and build SRT library using CMake on two architectures.
# Configure and build SRT library using CMake on all architectures.
#-----------------------------------------------------------------------------

foreach ($Platform in @("x64", "Win32")) {
foreach ($Platform in $SSL.Keys) {

# Build directory. Cleanup to force a fresh cmake config.
$BuildDir = "$TmpDir\build.$Platform"
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $BuildDir
[void](New-Item -Path $BuildDir -ItemType Directory -Force)

# Run CMake.
# Note: In previous versions of CMake, it was necessary to specify where
# OpenSSL was located using OPENSSL_ROOT_DIR, OPENSSL_LIBRARIES, and
# OPENSSL_INCLUDE_DIR. Starting with CMake 3.29.0, this is no longer
# necessary because CMake knows where to find the OpenSSL binaries from
# slproweb. Additionally, for some unkown reason, defining the OPENSSL_xxx
# variables no longer works with Arm64 libraries, even though the path to
# that version is correct. So, it's better to let CMake find OpenSSL by itself.
Write-Output "Configuring build for platform $Platform ..."
$SRoot = $SSL[$Platform]["root"]
& $CMake -S $RepoDir -B $BuildDir -A $Platform `
-DENABLE_STDCXX_SYNC=ON `
-DOPENSSL_ROOT_DIR="$SRoot" `
-DOPENSSL_LIBRARIES="$SRoot\lib\libssl_static.lib;$SRoot\lib\libcrypto_static.lib" `
-DOPENSSL_INCLUDE_DIR="$SRoot\include"
$LibSSL = $SSL[$Platform]["libsslMD"]
$LibCrypto = $SSL[$Platform]["libcryptoMD"]
& $CMake -S $RepoDir -B $BuildDir -A $Platform -DENABLE_STDCXX_SYNC=ON

# Patch version string in version.h
Get-Content "$BuildDir\version.h" |
Expand All @@ -218,7 +227,7 @@ foreach ($Platform in @("x64", "Win32")) {
Write-Output "Checking compiled libraries ..."
$Missing = 0
foreach ($Conf in @("Release", "Debug")) {
foreach ($Platform in @("x64", "Win32")) {
foreach ($Platform in $SSL.Keys) {
$Path = "$TmpDir\build.$Platform\$Conf\srt_static.lib"
if (-not (Test-Path $Path)) {
Write-Output "**** Missing $Path"
Expand All @@ -245,14 +254,18 @@ Write-Output "Building installer ..."
/DOutDir="$OutDir" `
/DBuildRoot="$TmpDir" `
/DRepoDir="$RepoDir" `
/Dlibssl32MD="$libssl32MD" `
/Dlibssl32MDd="$libssl32MDd" `
/Dlibcrypto32MD="$libcrypto32MD" `
/Dlibcrypto32MDd="$libcrypto32MDd" `
/Dlibssl64MD="$libssl64MD" `
/Dlibssl64MDd="$libssl64MDd" `
/Dlibcrypto64MD="$libcrypto64MD" `
/Dlibcrypto64MDd="$libcrypto64MDd" `
/DlibsslWin32MD="$($SSL.Win32.libsslMD)" `
/DlibsslWin32MDd="$($SSL.Win32.libsslMDd)" `
/DlibcryptoWin32MD="$($SSL.Win32.libcryptoMD)" `
/DlibcryptoWin32MDd="$($SSL.Win32.libcryptoMDd)" `
/DlibsslWin64MD="$($SSL.x64.libsslMD)" `
/DlibsslWin64MDd="$($SSL.x64.libsslMDd)" `
/DlibcryptoWin64MD="$($SSL.x64.libcryptoMD)" `
/DlibcryptoWin64MDd="$($SSL.x64.libcryptoMDd)" `
/DlibsslArm64MD="$($SSL.ARM64.libsslMD)" `
/DlibsslArm64MDd="$($SSL.ARM64.libsslMDd)" `
/DlibcryptoArm64MD="$($SSL.ARM64.libcryptoMD)" `
/DlibcryptoArm64MDd="$($SSL.ARM64.libcryptoMDd)" `
"$ScriptDir\libsrt.nsi"

if (-not (Test-Path $InstallExe)) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/win-installer/install-openssl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ if ($status -ne 1 -and $status -ne 2) {
}
$config = ConvertFrom-Json $Response.Content

# Download and install MSI packages for 32 and 64 bit.
foreach ($bits in @(32, 64)) {
# Download and install MSI packages for 32 and 64-bit Intel, 64-bit Arm.
foreach ($conf in @(@{arch="intel"; bits=32}, @{arch="intel"; bits=64}, @{arch="arm"; bits=64})) {

# Get the URL of the MSI installer from the JSON config.
$Url = $config.files | Get-Member | ForEach-Object {
$name = $_.name
$info = $config.files.$($_.name)
if (-not $info.light -and $info.installer -like "msi" -and $info.bits -eq $bits -and $info.arch -like "intel") {
if (-not $info.light -and $info.installer -like "msi" -and $info.bits -eq $conf.bits -and $info.arch -like $conf.arch) {
$info.url
}
} | Select-Object -Last 1
if (-not $Url) {
Exit-Script "#### No MSI installer found for Win${bits}"
Exit-Script "#### No MSI installer found for $($conf.bits)-bit $($conf.arch)"
}

$MsiName = (Split-Path -Leaf $Url)
Expand Down
46 changes: 30 additions & 16 deletions scripts/win-installer/libsrt.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ Caption "SRT Libraries Installer"
!include "x64.nsh"
!verbose pop

!define ProductName "libsrt"
!define Build32Dir "${BuildRoot}\build.Win32"
!define Build64Dir "${BuildRoot}\build.x64"
!define ProductName "libsrt"
!define BuildWin32Dir "${BuildRoot}\build.Win32"
!define BuildWin64Dir "${BuildRoot}\build.x64"
!define BuildArm64Dir "${BuildRoot}\build.ARM64"

; Installer file information.
VIProductVersion ${VersionInfo}
Expand Down Expand Up @@ -93,6 +94,7 @@ functionEnd
function un.onInit
; In 64-bit installers, don't use registry redirection.
${If} ${RunningX64}
${OrIf} ${IsNativeARM64}
SetRegView 64
${EndIf}
functionEnd
Expand Down Expand Up @@ -128,7 +130,7 @@ Section "Install"
File "${RepoDir}\srtcore\platform_sys.h"
File "${RepoDir}\srtcore\srt.h"
File "${RepoDir}\srtcore\udt.h"
File "${Build64Dir}\version.h"
File "${BuildWin64Dir}\version.h"

CreateDirectory "$INSTDIR\include\win"
SetOutPath "$INSTDIR\include\win"
Expand All @@ -139,27 +141,39 @@ Section "Install"

CreateDirectory "$INSTDIR\lib\Release-x64"
SetOutPath "$INSTDIR\lib\Release-x64"
File /oname=srt.lib "${Build64Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${libcrypto64MD}"
File /oname=libssl.lib "${libssl64MD}"
File /oname=srt.lib "${BuildWin64Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${libcryptoWin64MD}"
File /oname=libssl.lib "${libsslWin64MD}"

CreateDirectory "$INSTDIR\lib\Debug-x64"
SetOutPath "$INSTDIR\lib\Debug-x64"
File /oname=srt.lib "${Build64Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${libcrypto64MDd}"
File /oname=libssl.lib "${libssl64MDd}"
File /oname=srt.lib "${BuildWin64Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${libcryptoWin64MDd}"
File /oname=libssl.lib "${libsslWin64MDd}"

CreateDirectory "$INSTDIR\lib\Release-Win32"
SetOutPath "$INSTDIR\lib\Release-Win32"
File /oname=srt.lib "${Build32Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${libcrypto32MD}"
File /oname=libssl.lib "${libssl32MD}"
File /oname=srt.lib "${BuildWin32Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${libcryptoWin32MD}"
File /oname=libssl.lib "${libsslWin32MD}"

CreateDirectory "$INSTDIR\lib\Debug-Win32"
SetOutPath "$INSTDIR\lib\Debug-Win32"
File /oname=srt.lib "${Build32Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${libcrypto32MDd}"
File /oname=libssl.lib "${libssl32MDd}"
File /oname=srt.lib "${BuildWin32Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${libcryptoWin32MDd}"
File /oname=libssl.lib "${libsslWin32MDd}"

CreateDirectory "$INSTDIR\lib\Release-Arm64"
SetOutPath "$INSTDIR\lib\Release-Arm64"
File /oname=srt.lib "${BuildArm64Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${libcryptoArm64MD}"
File /oname=libssl.lib "${libsslArm64MD}"

CreateDirectory "$INSTDIR\lib\Debug-Arm64"
SetOutPath "$INSTDIR\lib\Debug-Arm64"
File /oname=srt.lib "${BuildArm64Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${libcryptoArm64MDd}"
File /oname=libssl.lib "${libsslArm64MDd}"

; Add an environment variable to installation root.
WriteRegStr HKLM ${EnvironmentKey} "LIBSRT" "$INSTDIR"
Expand Down
6 changes: 3 additions & 3 deletions srtcore/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ void srt::CPktTimeWindowTools::initializeWindowArrays(int* r_pktWindow, int* r_p
r_probeWindow[k] = 1000; //1 msec -> 1000 pkts/sec

for (size_t i = 0; i < asize; ++ i)
r_bytesWindow[i] = max_payload_size; //based on 1 pkt/sec set in r_pktWindow[i]
r_bytesWindow[i] = int(max_payload_size); //based on 1 pkt/sec set in r_pktWindow[i]
}

int srt::CPktTimeWindowTools::ceilPerMega(double value, double count)
{
static const double MEGA = 1000.0 * 1000.0;
return ::ceil(MEGA / (value / count));
return int(::ceil(MEGA / (value / count)));
}

int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, const int* abytes, size_t asize, size_t hdr_size, int& w_bytesps)
Expand All @@ -183,7 +183,7 @@ int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica,
return 0;
}

bytes += (hdr_size * count); //Add protocol headers to bytes received
bytes += (unsigned long)(hdr_size * count); //Add protocol headers to bytes received
w_bytesps = ceilPerMega(sum, bytes);
return ceilPerMega(sum, count);
}
Expand Down

0 comments on commit bc8a084

Please sign in to comment.