Skip to content

Commit

Permalink
ci/windows: add build commands for libm2k
Browse files Browse the repository at this point in the history
- try to fix deps not installing correctly

Signed-off-by: Adrian Stanea <[email protected]>
  • Loading branch information
Adrian-Stanea committed Nov 7, 2023
1 parent b811741 commit f1a8ea7
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 23 deletions.
21 changes: 20 additions & 1 deletion CI/windows/install_deps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ $DEPS_DIR = Join-Path $SRC_DIR "deps"
$BUILD_DIR = Join-Path $SRC_DIR "build-$ARCH"
$LIBIIO_VERSION = "libiio-v0"

Write-Output "Python located at:"
Get-Command python

Write-Output "Running script from $SRC_DIR"
Get-ChildItem

Expand All @@ -34,12 +37,17 @@ function Get-Libiio-Deps {
7z x -y "libxml.7z"
Remove-Item "libxml.7z"

Get-ChildItem


Write-Output "## Installing libiio-deps"
New-Item -Path (Join-Path $SRC_DIR "libiio-deps") -ItemType Directory
Set-Location (Join-Path $SRC_DIR "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 "libiio-win-deps.zip"

Get-ChildItem
}

function Install-Libiiio {
Expand All @@ -58,6 +66,8 @@ function Install-Libiiio {
Write-Output "## Running cmake for $COMPILER on $ARCH..." # x64 instead of ARCH in example
New-Item -Path (Join-Path $SRC_DIR "libiio\build-$ARCH") -ItemType Directory
Copy-Item -Path ".\libiio.iss.cmakein" -Destination (Join-Path $SRC_DIR "libiio\build-$ARCH")


Set-Location (Join-Path $SRC_DIR "libiio\build-$ARCH")

Write-Output "## Inside build-$ARCH before cmake"
Expand All @@ -73,6 +83,7 @@ function Install-Libiiio {

# Try the cmake config from libiio CI scripts
$pythonExecutable = python -c "import sys; print(sys.executable)"
Write-Output "## pythonExecutable = $pythonExecutable "
cmake -G "$COMPILER" `
-DPYTHON_EXECUTABLE:FILEPATH=$pythonExecutable `
-DCMAKE_SYSTEM_PREFIX_PATH="C:" `
Expand All @@ -92,6 +103,12 @@ function Install-Libiiio {
# -DLIBXML2_INCLUDE_DIR="C:\\include\\libxml2" `

cmake --build . --config Release
Get-ChildItem

if ($LASTEXITCODE -ne 0) {
Write-Output "## cmake failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}

# TODO: REVIEW THIS: is the executable installed? if so do i need it in the build dir / artifacts staging directory ?
# Move to build dir - move .dll
Expand All @@ -118,7 +135,7 @@ function Install-Swig {
Remove-Item "swigwin-4.0.0.zip"
Set-Location (Join-Path "swig" "swigwin-4.0.0")
xcopy * .. /s /e /h /Q

Get-ChildItem
}

function Install-Inno-Setup {
Expand All @@ -133,6 +150,7 @@ function Install-Inno-Setup {
$NEW_PATH = $CRNT_PATH + ";" + $NEW_PATH
[System.Environment]::SetEnvironmentVariable('PATH', $NEW_PATH, [System.EnvironmentVariableTarget]::Machine)
}
Get-ChildItem
}

function Install-Glog {
Expand All @@ -159,6 +177,7 @@ function Install-Glog {

cmake -DWITH_GFLAGS=off -DBUILD_SHARED_LIBS=on -G $GENERATOR -A $ARCH ..
cmake --build . --target install --config "Release"
Get-ChildItem
}

function Install-All {
Expand Down
105 changes: 83 additions & 22 deletions CI/windows/make_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,86 @@
$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
$COMPILER = $Env:COMPILER
$ARCH = $Env:ARCH

$SRC_DIR = Get-Location
$BUILD_DIR = Join-Path $SRC_DIR "build-$ARCH"
$DIST_DIR = Join-Path $SRC_DIR "build-$ARCH\dist"

if (-not (Test-Path -Path (Join-Path $SRC_DIR "build-$ARCH\dist"))) {
New-Item -Path $DIST_DIR -ItemType Directory
}

function Build-Python-Wheel {
param(
[string]$PLATFORM
[string]$PYTHON_PATH
)
# TODO: extend path to include swig => export PATH="/c/swig/;/c/swig/Lib/;$OLD_PATH" => TO BE TESTED
$OLD_PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)
$SWIG_PATH= (Join-Path $SRC_DIR "swig") + ";" + (Join-Path $SRC_DIR "swig\Lib")
$NEW_PATH = $SWIG_PATH + ";" + $OLD_PATH
[System.Environment]::SetEnvironmentVariable('PATH', $NEW_PATH, [System.EnvironmentVariableTarget]::Machine)

Invoke-Expression "$PYTHON_PATH -m pip install --user --upgrade pip setuptools wheel twine build virtualenv"
$env:COMPILE_BINDINGS = $true
Invoke-Expression "$PyPath -m build"
Remove-Item Env:\COMPILE_BINDINGS
Copy-Item "dist/libm2k*.whl" "$BUILD_DIR\dist"
}

function Build-Libm2k {
param(
[string]$PLATFORM
[string]$PYTHON_VERSION,
[string]$PYTHON_PATH,
[string]$GENERATOR,
[string]$ARCH,
)

# Create the official build directory for this platform
New-Item -Path (Join-Path $SRC_DIR "\build-$PLATFORM\dist") -ItemType Directory

# Create and clear up the temporary build directory for this platform
$TEMP_BUILD_DIR = Join-Path $SRC_DIR "tmp-build-$PLATFORM"
if (Test-Path -Path $TEMP_BUILD_DIR) {
Remove-Item $TEMP_BUILD_DIR -Recurse -Force
}
New-Item -Path $TEMP_BUILD_DIR -ItemType Directory

# Q: do i need to add python path manually if already did this in a previous step in the CI job?
# $OLD_PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)
# $NEW_PATH = $SWIG_PATH + ";" + $OLD_PATH
# [System.Environment]::SetEnvironmentVariable('PATH', $NEW_PATH, [System.EnvironmentVariableTarget]::Machine)
Set-Location (Join-Path $SRC_DIR "tmp-build-$ARCH")

cmake -G $GENERATOR `
-A $ARCH `
-DIIO_LIBRARIES:FILEPATH="$DEST_LIBIIO"-"$PLATFORM"/libiio.lib `
-DIIO_INCLUDE_DIRS:PATH="$DEST_LIBIIO"-"$PLATFORM" `
-DCMAKE_CONFIGURATION_TYPES=RELEASE `
-DSWIG_DIR=/c/swig/Lib `
-DSWIG_EXECUTABLE=/c/swig/swig.exe `
-DSWIG_VERSION="4.0.0" `
-DENABLE_TOOLS=ON `
-DENABLE_LOG=ON `
-DPython_EXECUTABLE="$PY_PATH/python.exe" `
-DBUILD_EXAMPLES=ON `
-DENABLE_CSHARP=ON `
-DENABLE_LABVIEW=ON `
..

cmake --build . --config Release

cat setup.py

$PY_SUFFIX=""
if ($PLATFORM -eq "win64") {
$PY_SUFFIX = "-x64"
}

Build-Python-Wheel -PLATFORM $PLATFORM -PYTHON_PATH $PYTHON_PATH
}

Build-Libm2k -PLATFORM "win32" -PYTHON_VERSION 37 -PYTHON_PATH "C:\Python39" -GENERATOR $COMPILER -ARCH $ARCH

0 comments on commit f1a8ea7

Please sign in to comment.