Skip to content

Commit 0a7e7b3

Browse files
authored
Introduce CMake build
2 parents 01620d5 + f22006f commit 0a7e7b3

File tree

14 files changed

+131
-4316
lines changed

14 files changed

+131
-4316
lines changed

.github/workflows/build-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
python-version: ${{ matrix.python-version }}
2626

2727
- name: Cache Bazel Unix
28-
uses: actions/cache@v2.1.5
28+
uses: actions/cache@v4
2929
with:
3030
path: |
3131
./bazel-PyDP
@@ -63,7 +63,7 @@ jobs:
6363
echo "::set-output name=dir::$(poetry config cache-dir)"
6464
6565
- name: poetry cache
66-
uses: actions/cache@v2
66+
uses: actions/cache@v4
6767
with:
6868
path: ${{ steps.poetry-cache.outputs.dir }}
6969
key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}

.github/workflows/publish.yml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ jobs:
1010
fail-fast: false
1111
max-parallel: 12
1212
matrix:
13-
os: [ubuntu-latest, macos-latest, windows-latest]
14-
python-version: [3.8, 3.9, "3.10", "3.11"]
13+
# TODO: fix for Mac and Windows.
14+
os: [ubuntu-latest]
15+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
1516
runs-on: ${{ matrix.os }}
1617

1718
steps:
@@ -34,18 +35,6 @@ jobs:
3435
run: |
3536
@("C:\Program Files\Git\usr\bin") + (Get-Content $env:GITHUB_PATH) | Set-Content $env:GITHUB_PATH -Encoding utf8
3637
37-
- name: Cache Bazel Unix
38-
# Not working on Windows: https://github.com/actions/cache/issues/576
39-
if: runner.os != 'Windows'
40-
uses: actions/[email protected]
41-
with:
42-
path: |
43-
./bazel-PyDP
44-
./bazel-bin
45-
./bazel-cache
46-
./bazel-out
47-
key: ${{ runner.os }}-bazel-${{ hashFiles('WORKSPACE') }}
48-
4938
- name: Update environment variables Windows
5039
if: runner.os == 'Windows'
5140
# See:
@@ -56,7 +45,7 @@ jobs:
5645
- name: Cache Bazel Windows
5746
if: runner.os == 'Windows'
5847
# https://stackoverflow.com/questions/66870002/github-actions-cache-maven-m2-repository-on-windows-environment-c-users-run
59-
uses: actions/cache@v2.1.5
48+
uses: actions/cache@v4
6049
with:
6150
path: |
6251
./bazel-cache
@@ -91,16 +80,7 @@ jobs:
9180
if: runner.os == 'macOS'
9281
timeout-minutes: 20
9382
run: |
94-
PYTHONHOME=$(which python)
95-
PYTHONPATH=$(python -c "import sys; print([x for x in sys.path if 'site-packages' in x][0]);")
96-
BAZEL_CONFIG_OS=$(python -c "print('${{ matrix.os }}'.split('-')[0].lower().replace('ubuntu', 'linux'))")
97-
echo "Running: ${{ matrix.os }}"
98-
echo "Using BAZEL_CONFIG_OS: $BAZEL_CONFIG_OS"
99-
bazel --output_base ./bazel-cache build src/python:pydp \
100-
--config $BAZEL_CONFIG_OS \
101-
--verbose_failures --action_env=PYTHON_BIN_PATH=$PYTHONHOME \
102-
--action_env=PYTHON_LIB_PATH=$PYTHONPATH
103-
cp -f ./bazel-bin/src/bindings/_pydp.so ./src/pydp
83+
bash build_PyDP.sh
10484
10585
- name: Build Google DP Windows
10686
if: runner.os == 'Windows'
@@ -128,7 +108,7 @@ jobs:
128108
echo "::set-output name=dir::$(poetry config cache-dir)"
129109
130110
- name: poetry cache
131-
uses: actions/cache@v2
111+
uses: actions/cache@v4
132112
with:
133113
path: ${{ steps.poetry-cache.outputs.dir }}
134114
key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}

.github/workflows/tests.yml

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -77,48 +77,11 @@ jobs:
7777
run: |
7878
@("C:\Program Files\Git\usr\bin") + (Get-Content $env:GITHUB_PATH) | Set-Content $env:GITHUB_PATH -Encoding utf8
7979
80-
- name: Cache Bazel Unix
81-
# Not working on Windows: https://github.com/actions/cache/issues/576
82-
if: runner.os != 'Windows'
83-
uses: actions/[email protected]
84-
with:
85-
path: |
86-
./bazel-PyDP
87-
./bazel-bin
88-
./bazel-cache
89-
./bazel-out
90-
key: ${{ runner.os }}-bazel-${{ hashFiles('WORKSPACE') }}
91-
92-
- name: Update environment variables Windows
93-
if: runner.os == 'Windows'
94-
# See:
95-
# - On Bazel cache: https://docs.bazel.build/versions/master/output_directories.html
96-
run: |
97-
echo "BAZEL_CACHE_DIR=$env:USERPROFILE\_bazel_$env:USERNAME" >> $env:GITHUB_ENV
98-
99-
- name: Cache Bazel Windows
100-
if: runner.os == 'Windows'
101-
# https://stackoverflow.com/questions/66870002/github-actions-cache-maven-m2-repository-on-windows-environment-c-users-run
102-
uses: actions/[email protected]
103-
with:
104-
path: |
105-
./bazel-cache
106-
key: ${{ runner.os }}-bazel-${{ hashFiles('WORKSPACE') }}
107-
10880
- name: Build Google DP Unix
10981
if: runner.os != 'Windows'
11082
timeout-minutes: 20
11183
run: |
112-
PYTHONHOME=$(which python)
113-
PYTHONPATH=$(python -c "import sys; print([x for x in sys.path if 'site-packages' in x][0]);")
114-
BAZEL_CONFIG_OS=$(python -c "print('${{ matrix.os }}'.split('-')[0].lower().replace('ubuntu', 'linux'))")
115-
echo "Running: ${{ matrix.os }}"
116-
echo "Using BAZEL_CONFIG_OS: $BAZEL_CONFIG_OS"
117-
bazel --output_base ./bazel-cache build src/python:pydp \
118-
--config $BAZEL_CONFIG_OS \
119-
--verbose_failures --action_env=PYTHON_BIN_PATH=$PYTHONHOME \
120-
--action_env=PYTHON_LIB_PATH=$PYTHONPATH
121-
cp -f ./bazel-bin/src/bindings/_pydp.so ./src/pydp
84+
bash build_PyDP.sh
12285
12386
- name: Build Google DP Windows
12487
if: runner.os == 'Windows'
@@ -146,7 +109,7 @@ jobs:
146109
echo "::set-output name=dir::$(poetry config cache-dir)"
147110
148111
- name: poetry cache
149-
uses: actions/cache@v2
112+
uses: actions/cache@v4
150113
with:
151114
path: ${{ steps.poetry-cache.outputs.dir }}
152115
key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}

.github/workflows/versions.yml

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ jobs:
5252
fail-fast: false
5353
max-parallel: 12
5454
matrix:
55-
os: [ubuntu-latest, macos-latest, windows-latest]
56-
python-version: [3.8, 3.9, "3.10", "3.11"]
55+
# TODO: fix for Mac and Windows.
56+
os: [ubuntu-latest]
57+
python-version: [ 3.9, "3.10", "3.11", "3.12", "3.13"]
5758

5859
steps:
59-
- uses: actions/checkout@v2
60+
- uses: actions/checkout@v4
6061
with:
6162
submodules: true
6263

@@ -65,70 +66,62 @@ jobs:
6566
with:
6667
python-version: ${{ matrix.python-version }}
6768

68-
- name: Setup msbuild Windows
69-
if: runner.os == 'Windows'
70-
uses: microsoft/[email protected]
69+
- name: Install Protobuf Compiler Linux
70+
if: runner.os == 'Linux'
71+
run: |
72+
sudo apt-get update
73+
sudo apt-get install -y protobuf-compiler libprotobuf-dev
74+
- name: Install Protobuf Compiler Mac
75+
if: runner.os == 'macOS'
76+
run: |
77+
brew install protobuf
7178
72-
- name: Fix Paths Windows
73-
# Make sure that tar.exe from Git is used not from Windows
79+
- name: Install Protobuf Compiler Windows
7480
if: runner.os == 'Windows'
7581
run: |
76-
@("C:\Program Files\Git\usr\bin") + (Get-Content $env:GITHUB_PATH) | Set-Content $env:GITHUB_PATH -Encoding utf8
82+
$protobufVersion = "32.0"
83+
$downloadUrl = "https://github.com/protocolbuffers/protobuf/releases/download/v$protobufVersion/protoc-$protobufVersion-win64.zip"
84+
$destinationFolder = "$env:TEMP\protoc"
7785
78-
- name: Cache Bazel Unix
79-
# Not working on Windows: https://github.com/actions/cache/issues/576
80-
if: runner.os != 'Windows'
81-
uses: actions/[email protected]
82-
with:
83-
path: |
84-
./bazel-PyDP
85-
./bazel-bin
86-
./bazel-cache
87-
./bazel-out
88-
key: ${{ runner.os }}-bazel-${{ hashFiles('WORKSPACE') }}
89-
90-
- name: Update environment variables Windows
86+
Invoke-WebRequest -Uri $downloadUrl -OutFile protoc.zip
87+
Expand-Archive -Path protoc.zip -DestinationPath $destinationFolder
88+
89+
# Add the protoc directory to the PATH
90+
echo "$destinationFolder\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
91+
92+
- name: Verify protoc installation
93+
run: protoc --version
94+
95+
- name: Download proto header Windows
9196
if: runner.os == 'Windows'
92-
# See:
93-
# - On Bazel cache: https://docs.bazel.build/versions/master/output_directories.html
94-
run: |
95-
echo "BAZEL_CACHE_DIR=$env:USERPROFILE\_bazel_$env:USERNAME" >> $env:GITHUB_ENV
97+
run: vcpkg install protobuf:x64-windows
98+
99+
- name: Setup msbuild Windows
100+
if: runner.os == 'Windows'
101+
uses: microsoft/[email protected]
96102

97-
- name: Cache Bazel Windows
103+
- name: Setup Visual studio Windows
98104
if: runner.os == 'Windows'
99-
# https://stackoverflow.com/questions/66870002/github-actions-cache-maven-m2-repository-on-windows-environment-c-users-run
100-
uses: actions/[email protected]
101-
with:
102-
path: |
103-
./bazel-cache
104-
key: ${{ runner.os }}-bazel-${{ hashFiles('WORKSPACE') }}
105+
uses: ilammy/msvc-dev-cmd@v1
105106

106107
- name: Build Google DP Unix
107108
if: runner.os != 'Windows'
108109
timeout-minutes: 20
109110
run: |
110-
PYTHONHOME=$(which python)
111-
PYTHONPATH=$(python -c "import sys; print([x for x in sys.path if 'site-packages' in x][0]);")
112-
BAZEL_CONFIG_OS=$(python -c "print('${{ matrix.os }}'.split('-')[0].lower().replace('ubuntu', 'linux'))")
113-
echo "Running: ${{ matrix.os }}"
114-
echo "Using BAZEL_CONFIG_OS: $BAZEL_CONFIG_OS"
115-
bazel --output_base ./bazel-cache build src/python:pydp \
116-
--config $BAZEL_CONFIG_OS \
117-
--verbose_failures --action_env=PYTHON_BIN_PATH=$PYTHONHOME \
118-
--action_env=PYTHON_LIB_PATH=$PYTHONPATH
119-
cp -f ./bazel-bin/src/bindings/_pydp.so ./src/pydp
111+
bash build_PyDP.sh
120112
121113
- name: Build Google DP Windows
122114
if: runner.os == 'Windows'
123115
timeout-minutes: 20
124116
run: |
125-
$PYTHONHOME=$(python -c 'import sys; print(sys.executable);').replace('\', '/')
126-
$PYTHONPATH=$(python -c "import sys; print([x for x in sys.path if 'site-packages' in x][0]);").replace('\', '/')
127-
echo "PYTHONHOME=$PYTHONHOME"
128-
echo "PYTHONPATH=$PYTHONPATH"
129117
echo "Running: ${{ matrix.os }}"
130-
bazel.exe --output_base ./bazel-cache build src/python:pydp --config windows --verbose_failures --action_env=PYTHON_BIN_PATH=$PYTHONHOME --action_env=PYTHON_LIB_PATH=$PYTHONPATH
131-
copy ./bazel-bin/src/bindings/_pydp.so ./src/pydp/_pydp.pyd
118+
mkdir build
119+
cd build
120+
cmake .. -DCMAKE_BUILD_TYPE=Release
121+
cmake --build . --config Release -j
122+
echo %CD%
123+
dir
124+
move /Y .\src\bindings\PyDP\_pydp.pyd ..\src\pydp\_pydp.pyd
132125
133126
- name: Upgrade pip
134127
run: |
@@ -144,7 +137,7 @@ jobs:
144137
echo "::set-output name=dir::$(poetry config cache-dir)"
145138
146139
- name: poetry cache
147-
uses: actions/cache@v2
140+
uses: actions/cache@v4
148141
with:
149142
path: ${{ steps.poetry-cache.outputs.dir }}
150143
key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
@@ -153,7 +146,7 @@ jobs:
153146
154147
- name: Install dependencies
155148
run: |
156-
poetry config installer.modern-installation false
149+
poetry lock
157150
poetry install
158151
159152
- name: Build PyDP macOS

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(PyDP LANGUAGES CXX)
3+
4+
# C++ Standard
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
9+
10+
add_subdirectory(src/bindings/PyDP)

build_PyDP.sh

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
#!/bin/bash
2+
set -e # exit on error
23

3-
## Set variables
4-
PLATFORM=$(python scripts/get_platform.py)
5-
6-
# Search specific python bin and lib folders to compile against the poetry env
7-
PYTHONHOME=$(which python)
8-
PYTHONPATH=$(python -c 'import sys; print([x for x in sys.path if "site-packages" in x][0]);')
9-
10-
# Give user feedback
11-
echo -e "Running bazel with:\n\tPLATFORM=$PLATFORM\n\tPYTHONHOME=$PYTHONHOME\n\tPYTHONPATH=$PYTHONPATH"
12-
13-
# Compile code
14-
bazel build src/python:pydp \
15-
--config $PLATFORM \
16-
--verbose_failures \
17-
--action_env=PYTHON_BIN_PATH=$PYTHONHOME \
18-
--action_env=PYTHON_LIB_PATH=$PYTHONPATH
19-
20-
# Delete the previously compiled package and copy the new one
21-
rm -f ./src/pydp/_pydp.so
22-
cp -f ./bazel-bin/src/bindings/_pydp.so ./src/pydp
4+
mkdir -p build
5+
cd build
6+
cmake .. -DCMAKE_BUILD_TYPE=Release
7+
make _pydp -j
8+
mv ./src/bindings/PyDP/_pydp*so ../src/pydp/_pydp.so

build_PyDP_linux.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
#!/bin/bash
2-
# This script differs from build_PyDP.sh by installing bazel first (if needed).
3-
BAZELISK_VERSION=v1.8.1
4-
BAZELISK_BINARY=bazelisk-linux-amd64
5-
BAZELISK_DOWNLOAD_URL=https://github.com/bazelbuild/bazelisk/releases/download/
6-
7-
if command -v bazel &>/dev/null; then
8-
echo "Bazel already installed"
9-
else
10-
python -m wget "${BAZELISK_DOWNLOAD_URL}/${BAZELISK_VERSION}/${BAZELISK_BINARY}"
11-
chmod +x ${BAZELISK_BINARY}
12-
mkdir bazel_dir
13-
echo mv ${BAZELISK_BINARY} bazel_dir/bazel
14-
mv ${BAZELISK_BINARY} bazel_dir/bazel
15-
export PATH="$PATH:`pwd`/bazel_dir"
16-
fi
172

183
./build_PyDP.sh

0 commit comments

Comments
 (0)