Skip to content

Commit

Permalink
ci/windows: refactor paths and build logic
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Stanea <[email protected]>
  • Loading branch information
Adrian-Stanea committed Nov 17, 2023
1 parent c70f836 commit 14eac6f
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 133 deletions.
60 changes: 9 additions & 51 deletions CI/windows/create_installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,19 @@ $ErrorActionPreference = "Stop"
$ErrorView = "NormalView"

$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo

function Get-Dll-Paths() {
$vsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if ($vsPath -eq $null) {
Write-Host "Visual Studio (vswhere.exe) not found - can't find dll paths."
return $null
}

$vsInstallerPath = & $vsPath -latest -requires Microsoft.Component.MSBuild -property installationPath
if ($vsInstallerPath -eq $null) {
Write-Host "Visual Studio Installer path is not available"
return $null
}

$msvcp140Path = Join-Path $vsInstallerPath 'VC\Tools\MSVC\14.*\bin\Hostx64\x64\msvcp140.dll'
$vcruntime140Path = Join-Path $vsInstallerPath 'VC\Tools\MSVC\14.*\bin\Hostx64\x64\vcruntime140.dll'
if (($msvcp140Path -eq $null) -or ($vcruntime140Path -eq $null)) {
Write-Host "Dll paths not found in Visual Studion installation path."
return $null
}

$result = New-Object PSObject -Property @{
msvcp140Path = $msvcp140Path
vcruntime140Path = $vcruntime140Path
}
return $result
}
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$BUILD_DIR = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM"
$INSTALLER_PATH = "C:\libm2k-system-setup.exe"

Set-Location $SRC_DIR

$ddlPaths = Get-Dll-Paths

if ($ddlPaths -ne $null) {
Write-Host "msvcp140Path: $($ddlPaths.msvcp140Path)"
Write-Host "vcruntime140Path: $($ddlPaths.vcruntime140Path)"
} else {
Write-Host "Dll Paths not found."
}

$INSALLER_PATH = Join-Path $SRC_DIR "build-win64\installer"
$DIST_PATH = Join-Path $SRC_DIR "build-win64\dist" # should already exist from th step where we build libm2k

Copy-Item -Path $ddlPaths.msvcp140Path -Destination $DIST_PATH
Copy-Item -Path $ddlPaths.vcruntime140Path -Destination $DIST_PATH

# creates installer in: C:\libm2k-system-setup.exe
ISCC (Join-Path $DIST_PATH "libm2k.iss")

if (-not (Test-Path -Path $INSALLER_PATH)) {
New-Item -Path $INSALLER_PATH -ItemType Directory
}
Move-Item -Path "C:\libm2k-system-setup.exe" -Destination $INSALLER_PATH
ISCC (Join-Path $BUILD_DIR "libm2k.iss")

# clear artifacts staging directory and copy the installer -> new step is to push an artifact
Get-ChildItem $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Force -Recurse | Remove-Item -Force -Recurse
Copy-Item -Path (Join-Path $INSALLER_PATH "libm2k-system-setup.exe") -Destination $env:BUILD_ARTIFACTSTAGINGDIRECTORY

$ARTIFACTS_DIR = Get-Item -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY # path to repo

New-Item -Path (Join-Path $ARTIFACTS_DIR "installer") -ItemType Directory
Copy-Item -Path $INSTALLER_PATH -Destination (Join-Path $ARTIFACTS_DIR "installer")

Set-Location $SRC_DIR
80 changes: 45 additions & 35 deletions CI/windows/create_zips.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,53 @@ $ARCH = $Env:ARCH
$PLATFORM = $Env:PLATFORM

$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
$BUILD_DIR = Join-Path $SRC_DIR "build-$PLATFORM\dist"

$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$DEST_LIBM2K = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM"
$DEST_LIBM2K_DIST = Join-Path $DEST_LIBM2K "dist"
$BUILD_DIR = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM\*"

if (-not (Test-Path -Path $DEST_LIBM2K)) {
New-Item -Path $DEST_LIBM2K -ItemType Directory
}
if (-not (Test-Path -Path $DEST_LIBM2K_DIST)) {
New-Item -Path $DEST_LIBM2K_DIST -ItemType Directory
}

Set-Location $SRC_DIR
xcopy include $DEST_LIBM2K /s /e /h
Copy-Item -Path "$BUILD_DIR\libm2k.*" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\_libm2k.*" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\libm2k_lv.dll" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\libm2k-sharp.dll" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\libm2k-sharp-cxx-wrap.dll" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\*.exe" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\msvc*.dll" -Destination $DEST_LIBM2K
Copy-Item -Path "$BUILD_DIR\vcruntime*.dll" -Destination $DEST_LIBM2K

# TODO: do we want to have the wheels build for different python versions? or just the latest
# current implementatino only .whl version using the latest python version
Copy-Item -Path "$BUILD_DIR\*.whl" -Destination $DEST_LIBM2K_DIST

Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $DEST_LIBM2K
Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $DEST_LIBM2K
Copy-Item -Path (Join-Path $OUTSIDE_BUILD "deps\glog\build_0_4_0-x64\Release\glog.dll") -Destination $DEST_LIBM2K

Set-Location $OUTSIDE_BUILD
7z a "libm2k-$PLATFORM.7z" "libm2k-$PLATFORM"

# Clean artifacts staging directory and copy the installer -> new step is to push an artifact
Get-ChildItem $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Force -Recurse | Remove-Item -Force -Recurse
Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM.7z") -Destination $env:BUILD_ARTIFACTSTAGINGDIRECTORY
$ARTIFACTS_DIR = Get-Item -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY # path to repo
New-Item -Path (Join-Path $ARTIFACTS_DIR "libm2k-$PLATFORM") -ItemType Directory
Copy-Item -Path $BUILD_DIR -Destination (Join-Path $ARTIFACTS_DIR "libm2k-$PLATFORM")


# $SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
# $BUILD_DIR = Join-Path $SRC_DIR "build-$PLATFORM\dist"

# $OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
# $DEST_LIBM2K = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM"
# $DEST_LIBM2K_DIST = Join-Path $DEST_LIBM2K "dist"

# if (-not (Test-Path -Path $DEST_LIBM2K)) {
# New-Item -Path $DEST_LIBM2K -ItemType Directory
# }
# if (-not (Test-Path -Path $DEST_LIBM2K_DIST)) {
# New-Item -Path $DEST_LIBM2K_DIST -ItemType Directory
# }

# Set-Location $SRC_DIR
# xcopy include $DEST_LIBM2K /s /e /h
# Copy-Item -Path "$BUILD_DIR\libm2k.*" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\_libm2k.*" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\libm2k_lv.dll" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\libm2k-sharp.dll" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\libm2k-sharp-cxx-wrap.dll" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\*.exe" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\msvc*.dll" -Destination $DEST_LIBM2K
# Copy-Item -Path "$BUILD_DIR\vcruntime*.dll" -Destination $DEST_LIBM2K

# # TODO: do we want to have the wheels build for different python versions? or just the latest
# # current implementatino only .whl version using the latest python version
# Copy-Item -Path "$BUILD_DIR\*.whl" -Destination $DEST_LIBM2K_DIST

# Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $DEST_LIBM2K
# Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $DEST_LIBM2K
# Copy-Item -Path (Join-Path $OUTSIDE_BUILD "deps\glog\build_0_4_0-x64\Release\glog.dll") -Destination $DEST_LIBM2K

# Set-Location $OUTSIDE_BUILD
# 7z a "libm2k-$PLATFORM.7z" "libm2k-$PLATFORM"

# # Clean artifacts staging directory and copy the installer -> new step is to push an artifact
# Get-ChildItem $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Force -Recurse | Remove-Item -Force -Recurse
# Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM.7z") -Destination $env:BUILD_ARTIFACTSTAGINGDIRECTORY

Set-Location $SRC_DIR
19 changes: 10 additions & 9 deletions CI/windows/install_deps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ function Install-Swig {
Write-Output "# Installing swig"
Set-Location $DIR_PATH
# NOTE: -UserAgent "NativeHost" solved the issue with the download - wait timeout before the download starts
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.0.0/swigwin-4.0.0.zip/download" -OutFile "swigwin-4.0.0.zip" -UserAgent "Wget"
# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
curl.exe -L -o "swigwin-4.0.0.zip" "https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.0.0/swigwin-4.0.0.zip/download"
# Invoke-WebRequest -Uri "https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.0.0/swigwin-4.0.0.zip/download" -OutFile "swigwin-4.0.0.zip" -UserAgent "Wget" -TimeoutSec 60
7z x "swigwin-4.0.0.zip" -oswig
Remove-Item "swigwin-4.0.0.zip"
Set-Location (Join-Path "swig" "swigwin-4.0.0")
Expand All @@ -140,13 +141,13 @@ function Install-Inno-Setup {
Write-Output "# Installing inno-setup"
choco install InnoSetup -y

$CRNT_PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)
if ($CRNT_PATH -notcontains $NEW_PATH) {
Write-Output "## Adding inno-setup to PATH"
$NEW_PATH = "C:\Program Files (x86)\Inno Setup 6"
$NEW_PATH = $CRNT_PATH + ";" + $NEW_PATH
[System.Environment]::SetEnvironmentVariable('PATH', $NEW_PATH, [System.EnvironmentVariableTarget]::Machine)
}
# $CRNT_PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)
# if ($CRNT_PATH -notcontains $NEW_PATH) {
# Write-Output "## Adding inno-setup to PATH"
# $NEW_PATH = "C:\Program Files (x86)\Inno Setup 6"
# $NEW_PATH = $CRNT_PATH + ";" + $NEW_PATH
# [System.Environment]::SetEnvironmentVariable('PATH', $NEW_PATH, [System.EnvironmentVariableTarget]::Machine)
# }
}

function Install-Glog {
Expand Down
69 changes: 64 additions & 5 deletions CI/windows/make_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ $SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$DEPS_DIR= Join-Path $OUTSIDE_BUILD "deps"

$DIST_DIR = Join-Path $SRC_DIR "build-$PLATFORM/dist"
$BUILD_DIR = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM"
$TEMP_BUILD_DIR = Join-Path $SRC_DIR "tmp-build-$PLATFORM"

$DEST_LIBIIO = Join-Path $OUTSIDE_BUILD "libiio-$ARCH"

Write-Output "SRC DIR = $SRC_DIR"
Write-Output "COMPILER = $COMPILER"
Write-Output "ARCH = $ARCH"
Write-Output "PLATFORM = $PLATFORM"
Write-Output "SRC DIR = $SRC_DIR"
Write-Output "OUTSIDE_BUILD = $OUTSIDE_BUILD"
Write-Output "DEPS_DIR = $DEPS_DIR"
Write-Output "BUILD_DIR = $BUILD_DIR"
Write-Output "TEMP_BUILD_DIR = $TEMP_BUILD_DIR"
Write-Output "DEST_LIBIIO = $DEST_LIBIIO"

# Create the official build directory for this platform
if (-not (Test-Path -Path $DIST_DIR)) {
New-Item -Path $DIST_DIR -ItemType Directory
if (-not (Test-Path -Path $BUILD_DIR)) {
New-Item -Path $BUILD_DIR -ItemType Directory
New-Item -Path (Join-Path $BUILD_DIR "dist") -ItemType Directory
}

function Build-Libm2k {
Expand Down Expand Up @@ -73,5 +76,61 @@ function Build-Libm2k {
Get-Content setup.py
}

function Get-Dll-Paths() {
$vsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if ($vsPath -eq $null) {
Write-Host "Visual Studio (vswhere.exe) not found - can't find dll paths."
return $null
}

$vsInstallerPath = & $vsPath -latest -requires Microsoft.Component.MSBuild -property installationPath
if ($vsInstallerPath -eq $null) {
Write-Host "Visual Studio Installer path is not available"
return $null
}

$msvcp140Path = Join-Path $vsInstallerPath 'VC\Tools\MSVC\14.*\bin\Hostx64\x64\msvcp140.dll'
$vcruntime140Path = Join-Path $vsInstallerPath 'VC\Tools\MSVC\14.*\bin\Hostx64\x64\vcruntime140.dll'
if (($msvcp140Path -eq $null) -or ($vcruntime140Path -eq $null)) {
Write-Host "Dll paths not found in Visual Studion installation path."
return $null
}

$result = New-Object PSObject -Property @{
msvcp140Path = $msvcp140Path
vcruntime140Path = $vcruntime140Path
}
return $result
}

function Move-To-Build-Dir() {
$ddlPaths = Get-Dll-Paths

if ($ddlPaths -ne $null) {
Write-Host "msvcp140Path: $($ddlPaths.msvcp140Path)"
Write-Host "vcruntime140Path: $($ddlPaths.vcruntime140Path)"
} else {
Write-Host "Dll Paths not found."
}

Copy-Item -Path $ddlPaths.msvcp140Path -Destination $BUILD_DIR
Copy-Item -Path $ddlPaths.vcruntime140Path -Destination $BUILD_DIR

Set-Location $TEMP_BUILD_DIR
Copy-Item -Path "*.dll" -Destination $BUILD_DIR
Copy-Item -Path "*.exe" -Destination $BUILD_DIR
Copy-Item -Path "*libm2k.lib" -Destination $BUILD_DIR
Copy-Item -Path "*.iss" -Destination $BUILD_DIR

Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $BUILD_DIR
Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $BUILD_DIR
Copy-Item -Path (Join-Path $OUTSIDE_BUILD "deps\glog\build_0_4_0-x64\Release\glog.dll") -Destination $BUILD_DIR

Set-Location $SRC_DIR
xcopy include $BUILD_DIR /s /e /h
}

Build-Libm2k -PLATFORM $PLATFORM -GENERATOR $COMPILER -ARCH $ARCH
Move-To-Build-Dir

Set-Location $SRC_DIR
26 changes: 8 additions & 18 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,31 +208,21 @@ jobs:
inputs:
versionSpec: '${{ pyVersion }}'
- powershell: |
$SRC_DIR = Get-Location
$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$BUILD_DIR = Join-Path $OUTSIDE_BUILD "libm2k-$Env:PLATFORM\dist"
$TEMP_BUILD_DIR = Join-Path $SRC_DIR "tmp-build-$Env:PLATFORM"
$DEST = Join-Path $SRC_DIR "build-$Env:PLATFORM\dist"
Set-Location $TEMP_BUILD_DIR
python.exe -m pip install --user --upgrade pip setuptools wheel twine build virtualenv
$env:COMPILE_BINDINGS = $true
python.exe -m build
Remove-Item Env:COMPILE_BINDINGS
Copy-Item -Path "dist/libm2k*.whl" -Destination $DEST
Copy-Item -Path "dist/libm2k*.whl" -Destination (Join-Path $BUILD_DIR "dist")
Set-Location $SRC_DIR
displayName: Wheel Python ${{ pyVersion }}
# condition: eq('${{ pyVersion }}', '3.11') # NOTE: remove after ci works fine
- powershell: |
$SRC_DIR = Get-Location
$DEST_DIR = Join-Path $SRC_DIR "build-$Env:PLATFORM\dist"
$TEMP_BUILD_DIR = Join-Path $SRC_DIR "tmp-build-$Env:PLATFORM"
Set-Location $TEMP_BUILD_DIR
Copy-Item -Path "*.dll" -Destination $DEST_DIR
Copy-Item -Path "*.exe" -Destination $DEST_DIR
Copy-Item -Path "*.lib" -Destination $DEST_DIR
Copy-Item -Path "*.iss" -Destination $DEST_DIR
Set-Location ..
displayName: 'Move to build directory'
condition: eq('${{ pyVersion }}', '3.11') # NOTE: remove after ci works fine
- task: PowerShell@2
displayName: 'Create libm2k-system-setup installer'
condition: eq(variables['System.JobName'], 'VS_2022')
Expand All @@ -242,7 +232,7 @@ jobs:
- task: PublishPipelineArtifact@1
condition: eq(variables['System.JobName'], 'VS_2022')
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
targetPath: '$(Build.ArtifactStagingDirectory)/installer'
artifactName: 'Libm2k-System-Setup-Exe'
- task: PowerShell@2
displayName: "Create ZIPs"
Expand All @@ -251,7 +241,7 @@ jobs:
filePath: ./CI/windows/create_zips.ps1
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
targetPath: '$(Build.ArtifactStagingDirectory)/libm2k-$(env:PLATFORM)'
artifactName: '$(artifactName)'


Expand Down
Loading

0 comments on commit 14eac6f

Please sign in to comment.