From d9128a449f8cef66d559208dcf4fc6dd52157ca1 Mon Sep 17 00:00:00 2001 From: Adrian Stanea Date: Mon, 23 Oct 2023 18:48:02 +0300 Subject: [PATCH] ci: windows builds - Initial setup, download dependencies Signed-off-by: Adrian Stanea --- CI/windows/install_deps.ps1 | 50 +++++++ CI/windows/make_windows.ps1 | 26 ++++ azure-pipelines.yml | 278 +++++++++++++++++++++--------------- 3 files changed, 236 insertions(+), 118 deletions(-) create mode 100644 CI/windows/install_deps.ps1 create mode 100644 CI/windows/make_windows.ps1 diff --git a/CI/windows/install_deps.ps1 b/CI/windows/install_deps.ps1 new file mode 100644 index 00000000..4d5453b6 --- /dev/null +++ b/CI/windows/install_deps.ps1 @@ -0,0 +1,50 @@ +$ErrorActionPreference = "Stop" +$ErrorView = "NormalView" + +$LIBIIO_VERSION = "libiio-v0" +$SRC_DIR = (Get-Location).Path +$COMPILER = $Env:COMPILER +$ARCH = $Env:ARCH + +Write-Output "# libiio $LIBIIO_VERSION for $COMPILER" + +git clone https://github.com/analogdevicesinc/libiio -b $LIBIIO_VERSION libiio +Set-Location -Path "$SRC_DIR\libiio" +git submodule update --init + +Write-Output "# Building libiio dependencies" + +if (-not (Test-Path -Path "$SRC_DIR\deps")) { + New-Item -Path "$SRC_DIR\deps" -ItemType Directory +} + +New-Item -Path "$SRC_DIR\deps\libxml" -ItemType Directory +Set-Location -Path "$SRC_DIR\deps\libxml" +# TODO: check that content is extracted in the right place +# Download and extract libxml +Invoke-WebRequest -Uri "https://www.zlatkovic.com/pub/libxml/64bit/libxml2-2.9.3-win32-x86_64.7z" -OutFile "libxml.7z" +& 7z x -y libxml.7z +Remove-Item -Path "libxml.7z" +ls + +# Download and extract libiio dependencies for Windows +New-Item -Path "$SRC_DIR\deps\libiio-deps" -ItemType Directory +Set-Location -Path "$SRC_DIR\deps\libiio-deps" +Invoke-WebRequest -Uri "http://swdownloads.analog.com/cse/build/libiio-deps-20220517.zip" -OutFile "libiio-win-deps.zip" +& 7z x -y "libiio-win-deps.zip" +Remove-Item -Path "libiio-win-deps.zip" +ls + +# Build libiio -> script 2 from libiio CI (take from github) +Write-Output "### Running cmake for $COMPILER on $ARCH" +Set-Location -Path "$SRC_DIR\libiio" +New-Item -Path "$SRC_DIR\libiio\build-$ARCH" -ItemType Directory +Copy-Item .\libiio.iss.cmakein ".\build-$ARCH" +Set-Location -Path "$SRC_DIR\libiio\build-$ARCH" + +cmake -G "$COMPILER" -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '\python.exe')") -DCMAKE_SYSTEM_PREFIX_PATH="C:" -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DPYTHON_BINDINGS=ON -DCSHARP_BINDINGS:BOOL=$USE_CSHARP -DLIBXML2_LIBRARIES="C:\\libs\\64\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libs\\64\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libs\\64\\libserialport.dll.a" -DLIBUSB_INCLUDE_DIR="C:\\include\\libusb-1.0" -DLIBXML2_INCLUDE_DIR="C:\\include\\libxml2" -DLIBZSTD_INCLUDE_DIR="C:\\include" -DLIBZSTD_LIBRARIES="C:\\libs\\64\\libzstd.dll.a" .. + +cmake --build . --config Release +if ( $LASTEXITCODE -ne 0 ) { + throw "[*] cmake build failure" +} \ No newline at end of file diff --git a/CI/windows/make_windows.ps1 b/CI/windows/make_windows.ps1 new file mode 100644 index 00000000..18875bba --- /dev/null +++ b/CI/windows/make_windows.ps1 @@ -0,0 +1,26 @@ +# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.2#erroractionpreference +$ErrorActionPreference = "Stop" +$ErrorView = "NormalView" + +$COMPILER=$Env:COMPILER +$USE_CSHARP=$Env:USE_CSHARP +$src_dir=$pwd + +echo "Running cmake for $COMPILER on 64 bit..." +mkdir build-x64 +cp .\libiio.iss.cmakein .\build-x64 +cd build-x64 + +cmake -G "$COMPILER" -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '\python.exe')") -DCMAKE_SYSTEM_PREFIX_PATH="C:" -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DPYTHON_BINDINGS=ON -DCSHARP_BINDINGS:BOOL=$USE_CSHARP -DLIBXML2_LIBRARIES="C:\\libs\\64\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libs\\64\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libs\\64\\libserialport.dll.a" -DLIBUSB_INCLUDE_DIR="C:\\include\\libusb-1.0" -DLIBXML2_INCLUDE_DIR="C:\\include\\libxml2" -DLIBZSTD_INCLUDE_DIR="C:\\include" -DLIBZSTD_LIBRARIES="C:\\libs\\64\\libzstd.dll.a" .. + +cmake --build . --config Release +if ( $LASTEXITCODE -ne 0 ) { + throw "[*] cmake build failure" + } +cp .\libiio.iss $env:BUILD_ARTIFACTSTAGINGDIRECTORY + +cd bindings/python +python.exe setup.py sdist +Get-ChildItem dist\pylibiio-*.tar.gz | Rename-Item -NewName "libiio-py39-amd64.tar.gz" +mv .\dist\*.gz . +rm .\dist\*.gz \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f74957ca..8677b0e5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,133 +32,175 @@ parameters: - 3.7 jobs: -- job: LinuxBuilds - strategy: - matrix: - ubuntu_20_04: - imageName: 'ubuntu-20.04' - OS_TYPE: 'ubuntu_docker' - OS_VERSION: focal - artifactName: 'Linux-Ubuntu-20.04' - PACKAGE_TO_INSTALL: 'build/*.deb' - ubuntu_22_04: - imageName: 'ubuntu-22.04' - OS_TYPE: 'ubuntu_docker' - OS_VERSION: jammy - artifactName: 'Linux-Ubuntu-22.04' - PACKAGE_TO_INSTALL: 'build/*.deb' - deploy_doxygen: - imageName: 'ubuntu-20.04' - OS_TYPE: 'doxygen' - OS_VERSION: focal - artifactName: 'Linux-Ubuntu-20.04' - PACKAGE_TO_INSTALL: 'build/*.deb' - pool: - vmImage: $(imageName) - steps: - - checkout: self - fetchDepth: 1 - clean: true - persistCredentials: true - - script: ./CI/ubuntu/install_deps - displayName: "Install Dependencies" - - script: ./CI/ubuntu/make_linux - displayName: "Build" - - task: CopyFiles@2 - condition: ne(variables['System.JobName'], 'deploy_doxygen') - inputs: - sourceFolder: '$(Agent.BuildDirectory)/s/build/' - contents: '$(Agent.BuildDirectory)/s/build/?(*.deb|*.rpm)' - targetFolder: '$(Build.ArtifactStagingDirectory)' - - task: PublishPipelineArtifact@1 - condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), ne(variables['System.JobName'], 'deploy_doxygen')) - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)' - artifactName: '$(artifactName)' +# - job: LinuxBuilds +# strategy: +# matrix: +# ubuntu_20_04: +# imageName: 'ubuntu-20.04' +# OS_TYPE: 'ubuntu_docker' +# OS_VERSION: focal +# artifactName: 'Linux-Ubuntu-20.04' +# PACKAGE_TO_INSTALL: 'build/*.deb' +# ubuntu_22_04: +# imageName: 'ubuntu-22.04' +# OS_TYPE: 'ubuntu_docker' +# OS_VERSION: jammy +# artifactName: 'Linux-Ubuntu-22.04' +# PACKAGE_TO_INSTALL: 'build/*.deb' +# deploy_doxygen: +# imageName: 'ubuntu-20.04' +# OS_TYPE: 'doxygen' +# OS_VERSION: focal +# artifactName: 'Linux-Ubuntu-20.04' +# PACKAGE_TO_INSTALL: 'build/*.deb' +# pool: +# vmImage: $(imageName) +# steps: +# - checkout: self +# fetchDepth: 1 +# clean: true +# persistCredentials: true +# - script: ./CI/ubuntu/install_deps +# displayName: "Install Dependencies" +# - script: ./CI/ubuntu/make_linux +# displayName: "Build" +# - task: CopyFiles@2 +# condition: ne(variables['System.JobName'], 'deploy_doxygen') +# inputs: +# sourceFolder: '$(Agent.BuildDirectory)/s/build/' +# contents: '$(Agent.BuildDirectory)/s/build/?(*.deb|*.rpm)' +# targetFolder: '$(Build.ArtifactStagingDirectory)' +# - task: PublishPipelineArtifact@1 +# condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), ne(variables['System.JobName'], 'deploy_doxygen')) +# inputs: +# targetPath: '$(Build.ArtifactStagingDirectory)' +# artifactName: '$(artifactName)' + +# - job: macOSBuilds +# workspace: +# clean: all +# strategy: +# matrix: +# macOS_11: +# poolName: 'Azure Pipelines' +# vmImage: 'macOS-11' +# agentName: 'Azure Pipelines 4' +# artifactName: 'macOS-11' +# macOS_12: +# poolName: 'Azure Pipelines' +# vmImage: 'macOS-12' +# agentName: 'Azure Pipelines 3' +# artifactName: 'macOS-12' +# macOS_13_x64: +# poolName: 'Azure Pipelines' +# vmImage: 'macOS-13' +# agentName: 'Azure Pipelines 2' +# artifactName: 'macOS-13-x64' +# # TODO: discuss with DevOps team how to setup ARM agent +# # macOS_13_arm64: +# # poolName: 'Default' +# # vmImage: +# # agentName: 'macOS_arm64' +# # artifactName: 'macOS-13-arm64' +# pool: +# name: $(poolName) +# vmImage: $(vmImage) +# demands: +# - agent.name -equals $(agentName) +# variables: +# PACKAGE_TO_INSTALL: 'build/*.pkg' +# steps: +# - checkout: self +# fetchDepth: 1 +# clean: true +# - script: ./CI/macOS/install_deps +# displayName: "Install Dependencies" +# condition: ne(variables['agentName'],'macOS_arm64') +# - script: ./CI/macOS/make_macOS +# displayName: "Build" +# - ${{ each pyVersion in parameters.pythonVersions }}: +# - task: UsePythonVersion@0 +# displayName: Use Python ${{ pyVersion }} +# inputs: +# versionSpec: '${{ pyVersion }}' +# - script: | +# python3 --version +# python3 -m pip install wheel twine build virtualenv +# cd '$(Agent.BuildDirectory)/s/build/' +# mkdir -p wheelhouse +# export COMPILE_BINDINGS=True +# python3 -m build +# export COMPILE_BINDINGS= +# cp dist/*.whl wheelhouse +# displayName: Wheel Python ${{ pyVersion }} +# - task: CopyFiles@2 +# inputs: +# sourceFolder: '$(Agent.BuildDirectory)/s/build/' +# contents: '$(Agent.BuildDirectory)/s/build/?(*.pkg)' +# targetFolder: '$(Build.ArtifactStagingDirectory)' +# - task: CopyFiles@2 +# inputs: +# sourceFolder: '$(Agent.BuildDirectory)/s/build/' +# contents: '$(Agent.BuildDirectory)/s/build/wheelhouse/?(*.whl)' +# targetFolder: '$(Build.ArtifactStagingDirectory)' +# - task: CopyFiles@2 +# inputs: +# sourceFolder: '$(Agent.BuildDirectory)/s/build_tar/' +# contents: '$(Agent.BuildDirectory)/s/build_tar/?(*.tar.gz)' +# targetFolder: '$(Build.ArtifactStagingDirectory)' +# - task: PublishPipelineArtifact@1 +# condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) +# inputs: +# targetPath: '$(Build.ArtifactStagingDirectory)' +# artifactName: '$(artifactName)' +# - script: | +# python -m pip install --upgrade pip twine +# cd '$(Agent.BuildDirectory)/s/build/wheelhouse/' +# python -m twine upload --repository "testpypi" *.whl +# condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v')) +# displayName: "Upload to PyPI" +# env: +# TWINE_USERNAME: '__token__' +# TWINE_PASSWORD: $(TWINE_PASSWORD) -- job: macOSBuilds +- job: WindowsBuilds workspace: clean: all strategy: matrix: - macOS_11: + windows_2019: poolName: 'Azure Pipelines' - vmImage: 'macOS-11' - agentName: 'Azure Pipelines 4' - artifactName: 'macOS-11' - macOS_12: + vmImage: 'windows-2019' + imageName: 'windows-2019' + COMPILER: 'Visual Studio 16 2022' + artifactName: 'Windows-VS-2022-x64' + ARCH: 'x64' + windows_2022: poolName: 'Azure Pipelines' - vmImage: 'macOS-12' - agentName: 'Azure Pipelines 3' - artifactName: 'macOS-12' - macOS_13_x64: - poolName: 'Azure Pipelines' - vmImage: 'macOS-13' - agentName: 'Azure Pipelines 2' - artifactName: 'macOS-13-x64' - # TODO: discuss with DevOps team how to setup ARM agent - # macOS_13_arm64: - # poolName: 'Default' - # vmImage: - # agentName: 'macOS_arm64' - # artifactName: 'macOS-13-arm64' + vmImage: 'windows-2022' + imageName: 'windows-2019' + COMPILER: 'Visual Studio 16 2022' + artifactName: 'Windows-VS-2022-x64' + ARCH: 'x64' pool: - name: $(poolName) vmImage: $(vmImage) - demands: - - agent.name -equals $(agentName) - variables: - PACKAGE_TO_INSTALL: 'build/*.pkg' steps: - - checkout: self - fetchDepth: 1 - clean: true - - script: ./CI/macOS/install_deps - displayName: "Install Dependencies" - condition: ne(variables['agentName'],'macOS_arm64') - - script: ./CI/macOS/make_macOS - displayName: "Build" - - ${{ each pyVersion in parameters.pythonVersions }}: + - checkout: self + fetchDepth: 1 + clean: true - task: UsePythonVersion@0 - displayName: Use Python ${{ pyVersion }} inputs: - versionSpec: '${{ pyVersion }}' - - script: | - python3 --version - python3 -m pip install wheel twine build virtualenv - cd '$(Agent.BuildDirectory)/s/build/' - mkdir -p wheelhouse - export COMPILE_BINDINGS=True - python3 -m build - export COMPILE_BINDINGS= - cp dist/*.whl wheelhouse - displayName: Wheel Python ${{ pyVersion }} - - task: CopyFiles@2 - inputs: - sourceFolder: '$(Agent.BuildDirectory)/s/build/' - contents: '$(Agent.BuildDirectory)/s/build/?(*.pkg)' - targetFolder: '$(Build.ArtifactStagingDirectory)' - - task: CopyFiles@2 - inputs: - sourceFolder: '$(Agent.BuildDirectory)/s/build/' - contents: '$(Agent.BuildDirectory)/s/build/wheelhouse/?(*.whl)' - targetFolder: '$(Build.ArtifactStagingDirectory)' - - task: CopyFiles@2 - inputs: - sourceFolder: '$(Agent.BuildDirectory)/s/build_tar/' - contents: '$(Agent.BuildDirectory)/s/build_tar/?(*.tar.gz)' - targetFolder: '$(Build.ArtifactStagingDirectory)' - - task: PublishPipelineArtifact@1 - condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)' - artifactName: '$(artifactName)' - - script: | - python -m pip install --upgrade pip twine - cd '$(Agent.BuildDirectory)/s/build/wheelhouse/' - python -m twine upload --repository "testpypi" *.whl - condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v')) - displayName: "Upload to PyPI" - env: - TWINE_USERNAME: '__token__' - TWINE_PASSWORD: $(TWINE_PASSWORD) + versionSpec: '3.10' + - task: PowerShell@2 + displayName: 'Install Dependencies' + inputs: + targetType: filePath + filePath: ./CI/windows/install_deps.ps1 + # - task: PowerShell@2 + # inputs: + # targetType: 'filePath' + # filePath: .\CI\build_win.ps1 + # displayName: 'Build' + + +