Skip to content

Commit

Permalink
update windows build script
Browse files Browse the repository at this point in the history
  • Loading branch information
admercs committed Feb 26, 2024
1 parent 3aa6920 commit abfb33a
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions scripts/mod_rpclib.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Import-Module "${PWD}\scripts\mod_utils.psm1"
###

[String]$PROJECT_DIR = "$PWD"
#[String]$SCRIPT_DIR = "${PROJECT_DIR}\scripts"
[String]$SCRIPT_DIR = "${PROJECT_DIR}\scripts"

[Version]$RPCLIB_VERSION = '2.3.0'
[String]$RCPLIB_VERSION_MAJ_MIN_BUILD = Get-VersionMajorMinorBuild -Version "$RPCLIB_VERSION"
Expand All @@ -43,20 +43,27 @@ Import-Module "${PWD}\scripts\mod_utils.psm1"

function Install-RpcLib {
[OutputType()]
param()
param(
[Parameter(HelpMessage='')]
[String]
$RpcLibPath = $RPCLIB_PATH,
[Parameter(HelpMessage='')]
[String]
$RpcLibUrl = $RPCLIB_URL
)
if ( $Verbose.IsPresent ) {
Write-Output '-----------------------------------------------------------------------------------------'
Write-Output ' Installing rpclib...'
Write-Output '-----------------------------------------------------------------------------------------'
}
# Set security protocol used for web requests and download rpclib
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # TLS v1.2
Invoke-WebRequest "$RPCLIB_URL" -OutFile '.\temp\rpclib.zip' -HttpVersion '2.0'
Invoke-WebRequest "$RpcLibUrl" -OutFile '.\temp\rpclib.zip' -HttpVersion '2.0'
# Unpack and remove archive
Expand-Archive -Path '.\temp\rpclib.zip' -DestinationPath '.\external\rpclib'
Remove-Item '.\temp\rpclib.zip'
# Fail build if unable to download and/or unpack rpclib
if ( -not (Test-Path -LiteralPath "$RPCLIB_PATH") ) {
if ( -not (Test-Path -LiteralPath "$RpcLibPath") ) {
Write-Error 'Error: Unable to download rpclib. Stopping build.' -ErrorAction SilentlyContinue
Invoke-Fail -ErrorMessage "Error: Failed to download and unpack RCPLib."
}
Expand All @@ -66,6 +73,9 @@ function Install-RpcLib {
function Build-RpcLib {
[OutputType()]
param(
[Parameter(HelpMessage='')]
[String]
$RpcLibPath = $RPCLIB_PATH,
[Parameter(HelpMessage = 'Options: [ "Visual Studio 17 2022" | "Visual Studio 16 2019" ]')]
[String]
$CmakeGenerator = "$CMAKE_GENERATOR"
Expand All @@ -75,12 +85,12 @@ function Build-RpcLib {
Write-Output ' Building rpclib...'
Write-Output '-----------------------------------------------------------------------------------------'
}
New-Item -ItemType Directory -Path "${RPCLIB_PATH}\build" -Force | Out-Null
Set-Location "${RPCLIB_PATH}\build"
if ( $Verbose.IsPresent ) { Write-Output "Current directory: ${RPCLIB_PATH}\build" }
New-Item -ItemType Directory -Path "${RpcLibPath}\build" -Force | Out-Null
Set-Location "${RpcLibPath}\build"
if ( $Verbose.IsPresent ) { Write-Output "Current directory: ${RpcLibPath}\build" }
# Generate RpcLib build files
Write-Output "Using CMake generator: ${CmakeGenerator}"
$ENV:CMAKE_GENERATOR = "$CmakeGenerator"
${env:CMAKE_GENERATOR} = "$CmakeGenerator" # [System.Environment]::GetEnvironmentVariables()
Start-Process -FilePath 'cmake.exe' -ArgumentList "-G `"${CmakeGenerator}"`", '..' -Wait -NoNewWindow
# Build RpcLib
if ( $BUILD_MODE -eq 'Release' ) {
Expand All @@ -98,31 +108,34 @@ function Build-RpcLib {
[String]$RPCLIB_TARGET_INCLUDE = '.\AutonomyLib\deps\rpclib\include'
New-Item -ItemType Directory -Path ("$RPCLIB_TARGET_LIB", "$RPCLIB_TARGET_INCLUDE") -Force | Out-Null
# copy directories robustly
Copy-Item -Path "${RPCLIB_PATH}\include" -Destination "${RPCLIB_TARGET_INCLUDE}" -Recurse -Force
Copy-Item -Path "${RpcLibPath}\include" -Destination "${RPCLIB_TARGET_INCLUDE}" -Recurse -Force
if ( $BUILD_MODE -eq 'Release' ) {
Copy-Item -Path "${RPCLIB_PATH}\build\Debug" -Destination "${RPCLIB_TARGET_LIB}\Debug" -Recurse -Force
Copy-Item -Path "${RPCLIB_PATH}\build\Release" -Destination "${RPCLIB_TARGET_LIB}\Release" -Recurse -Force
Copy-Item -Path "${RpcLibPath}\build\Debug" -Destination "${RPCLIB_TARGET_LIB}\Debug" -Recurse -Force
Copy-Item -Path "${RpcLibPath}\build\Release" -Destination "${RPCLIB_TARGET_LIB}\Release" -Recurse -Force
}
else {
Copy-Item -Path "${RPCLIB_PATH}\build\${BUILD_MODE}" -Destination "${RPCLIB_TARGET_LIB}\$BUILD_MODE" -Recurse -Force
Copy-Item -Path "${RpcLibPath}\build\${BUILD_MODE}" -Destination "${RPCLIB_TARGET_LIB}\$BUILD_MODE" -Recurse -Force
}
return $null
}

function Test-RpcLibVersion {
[OutputType()]
param(
[Parameter(HelpMessage='')]
[String]
$RpcLibPath = $RPCLIB_PATH,
[Parameter(HelpMessage = 'Options: [ "Visual Studio 17 2022" | "Visual Studio 16 2019" ]')]
[String]
$CmakeGenerator = "$CMAKE_GENERATOR"
)
if ( -not (Test-Path -LiteralPath "$RPCLIB_PATH") ) {
if ( -not (Test-Path -LiteralPath "$RpcLibPath") ) {
# Remove previous installations
Remove-Item '.\external\rpclib' -Force -Recurse
Install-RpcLib
Build-RpcLib -CmakeGenerator "$CmakeGenerator"
# Fail if rpclib version path not found
if ( -not (Test-Path -LiteralPath "$RPCLIB_PATH") ) {
if ( -not (Test-Path -LiteralPath "$RpcLibPath") ) {
Write-Error 'Error: Download and build of rpclib failed. Stopping build.' -ErrorAction SilentlyContinue
Invoke-Fail -ErrorMessage "Error: Failed to download and build rpclib."
}
Expand Down

0 comments on commit abfb33a

Please sign in to comment.