Skip to content

Commit

Permalink
Add Python bindings (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy authored Jun 21, 2023
1 parent cbf73be commit 6125d4b
Show file tree
Hide file tree
Showing 24 changed files with 1,445 additions and 114 deletions.
24 changes: 24 additions & 0 deletions .github/Invoke-VisualStudio.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Function Invoke-CmdScript {
param(
[String] $scriptName
)
$cmdLine = """$scriptName"" $args & set"
& $env:SystemRoot\system32\cmd.exe /c $cmdLine |
Select-String '^([^=]*)=(.*)$' | ForEach-Object {
$varName = $_.Matches[0].Groups[1].Value
$varValue = $_.Matches[0].Groups[2].Value
Set-Item Env:$varName $varValue
}
}

Function Invoke-VisualStudio2022win32 {
Invoke-CmdScript "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars32.bat"
}

Function Invoke-VisualStudio2022x64 {
Invoke-CmdScript "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
}

Function Invoke-VisualStudio2022arm64 {
Invoke-CmdScript "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsamd64_arm64.bat"
}
195 changes: 118 additions & 77 deletions .github/workflows/udmp-parser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,118 +2,159 @@ name: Builds

on: [push, pull_request]


jobs:
Windows:
runs-on: windows-latest
parser:
strategy:
fail-fast: false
matrix:
generator: ['ninja', 'msvc']
arch: ['win32', 'win64']
exclude:
# Ninja doesn't support the -A arch options with CMake
- generator: ninja
arch: win32

name: Windows latest / ${{ matrix.generator }}.${{ matrix.arch }}
variant:
- {os: windows-latest, generator: msvc, arch: x64, config: RelWithDebInfo}
- {os: windows-latest, generator: ninja, arch: x64, config: RelWithDebInfo}
- {os: windows-latest, generator: msvc, arch: win32, config: RelWithDebInfo}
- {os: windows-latest, generator: msvc, arch: arm64, config: RelWithDebInfo}
- {os: ubuntu-latest, generator: gcc, arch: , config: RelWithDebInfo}
- {os: ubuntu-latest, generator: clang, arch: , config: RelWithDebInfo}
- {os: macos-latest, generator: clang, arch: , config: Release}
runs-on: ${{ matrix.variant.os }}
name: parser / ${{ matrix.variant.os }} / ${{ matrix.variant.generator }} / ${{ matrix.variant.arch }}
env:
NB_CPU: 1
CMAKE_FLAGS: "-DBUILD_PARSER:BOOL=ON -DBUILD_PYTHON_BINDING:BOOL=OFF"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1
- name: Environment Setup (Windows)
if: matrix.variant.os == 'windows-latest'
run: |
echo "NB_CPU=$env:NUMBER_OF_PROCESSORS" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "CMAKE_ARCH='-A ${{ matrix.variant.arch }}'" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Import-Module .\.github\Invoke-VisualStudio.ps1
Invoke-VisualStudio2022${{ matrix.variant.arch }}
- name: Environment Setup (Linux)
if: matrix.variant.os == 'ubuntu-latest'
run: |
sudo apt-get -y update
echo "NB_CPU=$(grep -c ^processor /proc/cpuinfo)" >> $GITHUB_ENV
- name: Setup vs prompt
uses: ilammy/msvc-dev-cmd@v1
- name: Environment Setup (Linux/GCC)
if: matrix.variant.os == 'ubuntu-latest' && matrix.variant.generator == 'gcc'
run: |
sudo apt install -y g++ ninja-build
echo CC=gcc >> $GITHUB_ENV
echo CXX=g++ >> $GITHUB_ENV
- name: Build with Ninja/cl
if: matrix.generator == 'ninja'
- name: Environment Setup (Linux/CLang)
if: matrix.variant.os == 'ubuntu-latest' && matrix.variant.generator == 'clang'
run: |
cd src\build
.\build-release.bat
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
echo CC=clang >> $GITHUB_ENV
echo CXX=clang++ >> $GITHUB_ENV
- name: Build with msvc
if: matrix.generator == 'msvc'
- name: Environment Setup (MacOS)
if: matrix.variant.os == 'macos-latest'
run: |
cd src\build
.\build-release-msvc.bat ${{ matrix.arch }}
echo NB_CPU=$(sysctl -n hw.ncpu) >> $GITHUB_ENV
- name: Build
run: |
mkdir build
mkdir artifact
cmake -S ./src -B ./build ${{ env.CMAKE_ARCH }} ${{ env.CMAKE_FLAGS }}
cmake --build ./build --verbose --config ${{ matrix.variant.config }} --parallel ${{ env.NB_CPU }}
cmake --install ./build --config ${{ matrix.variant.config }} --prefix ./artifact --verbose
- name: Upload artifacts
if: matrix.generator == 'ninja'
uses: actions/upload-artifact@v3
with:
name: bin-${{ matrix.arch }}.RelWithDebInfo
path: |
src/build/parser/parser.exe
src/build/parser/parser.pdb
name: parser-${{ matrix.variant.os }}.${{ matrix.variant.generator }}-${{ matrix.variant.arch }}.${{ matrix.variant.config }}
path: artifact/

Linux:
runs-on: ubuntu-latest
bindings:
strategy:
fail-fast: false
matrix:
compiler: ['clang', 'gcc']

name: Ubuntu Latest / ${{ matrix.compiler }}
python-version: [3.9]
variant:
- {os: windows-latest, generator: msvc, arch: x64, config: RelWithDebInfo, py-arch: x64}
- {os: windows-latest, generator: msvc, arch: win32, config: RelWithDebInfo, py-arch: x86}
# - {os: windows-latest, generator: msvc, arch: arm64, config: RelWithDebInfo, py-arch: x64} # Unsupported (see https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json)
- {os: ubuntu-latest, generator: gcc, arch: , config: RelWithDebInfo, py-arch: x64}
- {os: ubuntu-latest, generator: clang, arch: , config: RelWithDebInfo, py-arch: x64}
- {os: macos-latest, generator: clang, arch: , config: Release, py-arch: x64}
runs-on: ${{ matrix.variant.os }}
name: bindings / ${{ matrix.variant.os }} / ${{ matrix.variant.generator }} / ${{ matrix.variant.arch }}
env:
NB_CPU: 1
CMAKE_FLAGS: "-DBUILD_PARSER:BOOL=OFF -DBUILD_PYTHON_BINDING:BOOL=ON"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Installing dependencies
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.variant.py-arch }}

- name: Install Python pre-requisites
run: |
sudo apt-get -y update
sudo apt install -y g++-12 ninja-build
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
python -m pip install --upgrade pip setuptools wheel
python -m pip install --user --upgrade -r src/python/requirements.txt
- name: Environment Setup (Windows)
if: matrix.variant.os == 'windows-latest'
run: |
echo "NB_CPU=$env:NUMBER_OF_PROCESSORS" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "CMAKE_ARCH='-A ${{ matrix.variant.arch }}'" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Import-Module .\.github\Invoke-VisualStudio.ps1
Invoke-VisualStudio2022${{ matrix.variant.arch }}
- name: Build with gcc
if: matrix.compiler == 'gcc'
env:
CC: gcc-12
CXX: g++-12
- name: Environment Setup (Linux)
if: matrix.variant.os == 'ubuntu-latest'
run: |
cd src/build
chmod u+x ./build-release.sh
./build-release.sh
- name: Build with clang
if: matrix.compiler == 'clang'
env:
CC: clang-15
CXX: clang++-15
sudo apt-get -y update
echo "NB_CPU=$(grep -c ^processor /proc/cpuinfo)" >> $GITHUB_ENV
- name: Environment Setup (Linux/GCC)
if: matrix.variant.os == 'ubuntu-latest' && matrix.variant.generator == 'gcc'
run: |
cd src/build
chmod u+x ./build-release.sh
./build-release.sh
sudo apt install -y g++ ninja-build
echo CC=gcc >> $GITHUB_ENV
echo CXX=g++ >> $GITHUB_ENV
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: bin-lin64-${{ matrix.compiler }}.Release
path: |
src/build/parser
- name: Environment Setup (Linux/CLang)
if: matrix.variant.os == 'ubuntu-latest' && matrix.variant.generator == 'clang'
run: |
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
echo CC=clang >> $GITHUB_ENV
echo CXX=clang++ >> $GITHUB_ENV
OSX:
runs-on: macos-latest
strategy:
fail-fast: false
- name: Environment Setup (MacOS)
if: matrix.variant.os == 'macos-latest'
run: |
echo NB_CPU=$(sysctl -n hw.ncpu) >> $GITHUB_ENV
name: OSX Latest / clang
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build
run: |
mkdir build
mkdir artifact
cmake -S ./src -B ./build ${{ env.CMAKE_ARCH }} ${{ env.CMAKE_FLAGS }}
cmake --build ./build --verbose --config ${{ matrix.variant.config }} --parallel ${{ env.NB_CPU }}
cmake --install ./build --config ${{ matrix.variant.config }} --prefix ./artifact --verbose
- name: Build with clang
env:
CC: clang
CXX: clang++
- name: Python Binding Tests
run: |
cd src/build
chmod u+x ./build-release-osx.sh
./build-release-osx.sh
cd src/python
python -m pip install -r tests/requirements.txt -U
python -m pip install --user -U .
pytest -vvv ./tests
cd ../..
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: bin-osxx64-clang.Release
path: |
src/build/parser
name: python-${{ matrix.variant.os }}.${{ matrix.variant.generator }}-bin-${{ matrix.variant.arch }}.${{ matrix.variant.config }}
path: artifact/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode
.pytest_cache
__pycache__
*.pyc
src/python/build
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Axel Souchet
Copyright (c) 2022-2023 Axel Souchet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 6125d4b

Please sign in to comment.