diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..28804a941 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,152 @@ +# https://aka.ms/yaml +jobs: +- job: Build + pool: + vmImage: 'vs2017-win2016' # other options: 'macOS-10.13', 'ubuntu-16.04' + strategy: + matrix: + # Python27: + # python.version: '2.7' + cp35-cp35m-win_amd64.whl: + python.version: '3.5' + python.architecture: 'x64' + cp36-cp36m-win_amd64.whl: + python.version: '3.6' + python.architecture: 'x64' + cp37-cp37m-win_amd64.whl: + python.version: '3.7' + python.architecture: 'x64' + cp35-cp35m-win32.whl: + python.version: '3.5' + python.architecture: 'x86' + cp36-cp36m-win32.whl: + python.version: '3.6' + python.architecture: 'x86' + cp37-cp37m-win32.whl: + python.version: '3.7' + python.architecture: 'x86' + maxParallel: 6 + + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + architecture: '$(python.architecture)' + + # Add additional tasks to run using each Python version in the matrix above + + # PowerShell + # Run a PowerShell script on Windows, macOS, or Linux. + - task: PowerShell@2 + inputs: + targetType: 'inline' # Optional. Options: filePath, inline + #arguments: # Optional + script: | # Required when targetType == Inline + pwd + Invoke-WebRequest -Uri "https://dl.bintray.com/lightwave-lab/klayout/klayout-microbits-1.0.zip" -OutFile klayout-microbits-1.0.zip + dir + Expand-Archive klayout-microbits-1.0.zip -DestinationPath klayout-microbits + dir klayout-microbits + #errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue + #failOnStderr: false # Optional + #ignoreLASTEXITCODE: false # Optional + #pwsh: false # Optional + #workingDirectory: # Optional + displayName: 'Download and Extract KLayout bits' + + # - script: | + # curl https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi -o VCForPython27.msi + # msiexec /i VCForPython27.msi /quiet + # set "VS90COMNTOOLS=C:\Users\VssAdministrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC" + # curl https://raw.githubusercontent.com/mattn/gntp-send/master/include/msinttypes/stdint.h -o "%VS90COMNTOOLS%\Include\stdint.h" + # dir "%VS90COMNTOOLS%\Include" + # condition: eq(variables['python.version'], '2.7') + # displayName: 'Install Microsoft Visual C++ Compiler for Python 2.7' + + - script: | + python -m pip install --upgrade pip setuptools wheel + displayName: 'Update pip, setuptools and wheel' + + - script: | + python -V + set "KLAYOUT_BITS=%cd%\klayout-microbits\klayout-microbits-1.0\msvc2017\%PYTHON_ARCHITECTURE%" + echo KLAYOUT_BITS=%KLAYOUT_BITS% + python setup.py bdist_wheel + displayName: 'Build KLayout' + + - bash: | + bash `pwd`/ci-scripts/windows/fix_wheel.sh `pwd`/dist/*.whl "`pwd`/klayout-microbits/klayout-microbits-1.0/msvc2017/$PYTHON_ARCHITECTURE" + displayName: 'Copy klayout bits dlls into wheel' + + - script: | + echo PATH=%PATH% + pip install klayout --no-index -f dist + python testdata/pymod/import_db.py + python testdata/pymod/import_rdb.py + python testdata/pymod/import_tl.py + python testdata/pymod/pya_tests.py + displayName: 'Test KLayout pymod' + + - task: CopyFiles@2 + condition: always() + inputs: + sourceFolder: '$(Build.SourcesDirectory)' + targetFolder: '$(Build.ArtifactStagingDirectory)' + contents: '**/?(*.whl)' + + - task: PublishBuildArtifacts@1 + condition: always() + inputs: + pathtoPublish: '$(Build.ArtifactStagingDirectory)' + artifactName: 'wheel-$(python.version).$(python.architecture)' + +- job: 'Deploy' + displayName: 'Combine Windows wheels' + dependsOn: Build + pool: + vmImage: 'vs2017-win2016' # other options: 'macOS-10.13', 'ubuntu-16.04' + steps: + - checkout: none #skip checking out the default repository resource + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts wheel-3.7.x64' + inputs: + artifactName: 'wheel-3.7.x64' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts wheel-3.6.x64' + inputs: + artifactName: 'wheel-3.6.x64' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts wheel-3.5.x64' + inputs: + artifactName: 'wheel-3.5.x64' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts wheel-3.7.x86' + inputs: + artifactName: 'wheel-3.7.x86' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts wheel-3.6.x86' + inputs: + artifactName: 'wheel-3.6.x86' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts wheel-3.5.x86' + inputs: + artifactName: 'wheel-3.5.x86' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: CopyFiles@2 + condition: always() + inputs: + sourceFolder: '$(System.DefaultWorkingDirectory)' + targetFolder: '$(Build.ArtifactStagingDirectory)' + contents: '**/?(*.whl)' + flattenFolders: true + - task: PublishBuildArtifacts@1 + condition: always() + inputs: + pathtoPublish: '$(Build.ArtifactStagingDirectory)' + artifactName: 'windows_wheels' + diff --git a/ci-scripts/windows/fix_wheel.sh b/ci-scripts/windows/fix_wheel.sh new file mode 100644 index 000000000..3ac9593c9 --- /dev/null +++ b/ci-scripts/windows/fix_wheel.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +SCRIPT_NAME=`basename "$0"` +TMP_WHEEL="$PWD/tmp/klayout_tempwheel" + +display_usage() { + echo "This script includes external libraries in windows-based wheels." + echo "Caution: This will delete the original wheel." + echo -e "\nUsage:\n./${SCRIPT_NAME} [--help|-h] klayout-...-win_amd64.whl \n" + } + +if [[ ( $1 == "--help") || $1 == "-h" ]] +then + display_usage + exit 0 +fi + +# Check number of arguments +if [ $# -eq 0 ]; then + >&2 echo -e "ERROR: No filename supplied\n" + display_usage + exit 1 +elif [ ! $# -eq 2 ]; then + >&2 echo -e "ERROR: Too many files supplied. Provide one filename at at time.\n" + display_usage + exit 1 +fi + +# Read wheel file from argument +WHL="$1" +WHL=$(echo $WHL | sed 's/\\/\//g' | sed 's/://') +KLAYOUT_BITS="$2" +KLAYOUT_BITS=$(echo $KLAYOUT_BITS | sed 's/\\/\//g' | sed 's/://') + + +# Check WHL is a valid file +if [[ ! -f "$WHL" ]]; then + >&2 echo -e "ERROR: $WHL is not a file" + exit 1 +fi + +# Convert to absolute path (linux only) +WHL=$(readlink -f $WHL) + +# Record old current directory +OLD_PWD=$PWD + +# Need to include external DLLs (klayout bits) into wheel + +# # Checking if it was previously patched +# if unzip -l $WHL | grep -q 'patch_external_libraries_included'; then +# echo "$(basename $WHL) is already patched. Doing nothing." +# exit 0 +# fi + +# Repair script below +if [[ -d $TMP_WHEEL ]]; then + rm -rf $TMP_WHEEL +else + mkdir -p $TMP_WHEEL +fi +echo "Unpacking $WHL inside $TMP_WHEEL" +wheel unpack $WHL -d $TMP_WHEEL || exit 1 +TMP_WHEEL="$TMP_WHEEL/`ls $TMP_WHEEL`" + +cd $TMP_WHEEL/klayout +echo "Copying libraries: libcurl.dll, expat.dll, pthreadVCE2.dll, zlib1.dll" +echo pwd: `pwd` +cp -v $KLAYOUT_BITS/curl/bin/* . +cp -v $KLAYOUT_BITS/expat/bin/* . +cp -v $KLAYOUT_BITS/ptw/bin/* . +cp -v $KLAYOUT_BITS/zlib/bin/* . +# if [ $? -ne 0 ]; then +# >&2 echo "ERROR: lib not found. Quitting." +# exit 1 +# fi +cd $TMP_WHEEL +# touch $TMP_WHEEL/patch_external_libraries_included +echo "Packing $WHL from $TMP_WHEEL" +rm -f $WHL +wheel pack $TMP_WHEEL -d `dirname $WHL` || exit 1 +echo "Done. $(basename $WHL) is patched." +# Cleanup (should always execute) +cd $OLD_PWD