Skip to content

Commit 594b02f

Browse files
committed
use multiplatform cmake
1 parent ef6c00e commit 594b02f

File tree

2 files changed

+143
-62
lines changed

2 files changed

+143
-62
lines changed

.github/workflows/github-actions-demo.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/libzedmd-python-pybind11-extension.yml

Lines changed: 143 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defaults:
99

1010
jobs:
1111
version:
12-
name: Detect version
12+
name: Detect libzedmd version
1313
runs-on: ubuntu-latest
1414
outputs:
1515
tag: ${{ steps.version.outputs.tag }}
@@ -27,15 +27,7 @@ jobs:
2727
TAG="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
2828
echo "${TAG}"
2929
echo "tag=${TAG}" >> $GITHUB_OUTPUT
30-
# - name: Check git tag
31-
# if: startsWith(github.ref, 'refs/tags/v')
32-
# run: |
33-
# GIT_TAG="${GITHUB_REF#refs/tags/}"
34-
# EXPECTED_TAG="v${{ steps.version.outputs.tag }}"
35-
# if [[ "${GIT_TAG}" != "${EXPECTED_TAG}" ]]; then
36-
# echo "Error: Git tag (${GIT_TAG}) does not match version from ZeDMD.h (v${{ steps.version.outputs.tag }})"
37-
# exit 1
38-
# fi
30+
3931
build:
4032
name: Build libzedmd-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.type }}
4133
runs-on: ${{ matrix.os }}
@@ -54,13 +46,32 @@ jobs:
5446
- uses: actions/checkout@v4
5547
with:
5648
submodules: recursive
49+
5750
- if: (matrix.platform == 'win')
5851
name: Add msbuild to path (win runner)
5952
uses: microsoft/setup-msbuild@v2
53+
54+
- if: (matrix.platform == 'win') && (matrix.arch == 'x86')
55+
name: Set up Python x86
56+
uses: actions/setup-python@v5
57+
with:
58+
architecture: 'x86'
59+
python-version: 3.11.9
60+
- if: (matrix.platform == 'macos') && (matrix.arch == 'x64')
61+
name: Set up Python x64
62+
uses: actions/setup-python@v5
63+
with:
64+
architecture: 'x64'
65+
python-version: 3.11.9
66+
6067
- if: (matrix.platform == 'macos')
6168
name: Add autoconf and automake (mac runner)
6269
run: |
63-
brew install autoconf automake libtool
70+
brew install autoconf automake libtool
71+
72+
- name: Which python
73+
run: which -a python
74+
6475
- name: Build libzedmd-${{ matrix.platform }}-${{ matrix.arch }}
6576
working-directory: extern/libzedmd/
6677
run: |
@@ -84,21 +95,131 @@ jobs:
8495
cmake --build build -- -j${NUM_PROCS}
8596
fi
8697
87-
- name: Setup Cpp
88-
uses: aminya/setup-cpp@v1
89-
with:
90-
compiler: gcc
91-
cppcheck: true # instead of `true`, which chooses the default version, you can pass a specific version.
98+
- name: Setting var PYBIND11_DIR
99+
run: echo "PYBIND11_DIR=$(python -c 'import pybind11; print(pybind11.get_cmake_dir())')" >> $GITHUB_ENV
100+
101+
- name: Testing PYBIND11_DIR
102+
run: echo "PYBIND11_DIR=${{ env.PYBIND11_DIR }}"
92103

93104
- name: Build libzedmd-python-python-extension
105+
working-directory: build/
94106
run: |
95-
rm -Rf build/${{ matrix.platform }}-${{ matrix.arch }}
96-
mkdir -p build/${{ matrix.platform }}-${{ matrix.arch }}
97-
gcc -xc++ -lstdc++ -std=c++11 -stdlib=libc++ -shared -O3 -Wall -fPIC $(python3-config --includes) -Iextern/pybind11/include -Iextern/libzedmd/src -Lextern/libzedmd/build extending.cpp -o build/${{ matrix.platform }}-${{ matrix.arch }}/extending$(python3-config --extension-suffix) -ldl -lpthread -lutil -lzedmd -lserialport
107+
ls ../extern/libzedmd/build
108+
echo '--------------------------------------'
109+
rm -Rf ./*
110+
if [[ "${{ matrix.platform }}" == "win" ]]; then
111+
if [[ "${{ matrix.arch }}" == "x64" ]]; then
112+
cmake -G "Visual Studio 17 2022" -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -Dpybind11_DIR=${{ env.PYBIND11_DIR }} ..
113+
elif [[ "${{ matrix.arch }}" == "x86" ]]; then
114+
cmake -G "Visual Studio 17 2022" -A Win32 -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -Dpybind11_DIR=${{ env.PYBIND11_DIR }} ..
115+
fi
116+
cmake --build . --config ${{ matrix.type }}
117+
else
118+
if [[ "$(uname)" == "Darwin" ]]; then
119+
NUM_PROCS=$(sysctl -n hw.ncpu)
120+
else
121+
NUM_PROCS=$(nproc)
122+
fi
123+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.type }} -DPLATFORM=${{ matrix.platform }} -DARCH=${{ matrix.arch }} -Dpybind11_DIR=${{ env.PYBIND11_DIR }} ..
124+
cmake --build . -- -j${NUM_PROCS}
125+
fi
98126
99-
- name: List files in build
127+
- name: List files in builds
100128
working-directory: build/
101-
run: ls -aR
129+
run: |
130+
ls -R
131+
echo '-----------------------------------'
132+
ls -R ../extern/libzedmd/build
102133
134+
- name: Prepare artifacts
135+
id: artifacts
136+
run: |
137+
mkdir tmp
138+
if [[ "${{ matrix.platform }}" == "win" ]]; then
139+
ARTIFACT_PATH="tmp"
140+
if [[ "${{ matrix.arch }}" == "x64" ]]; then
141+
cp extern/libzedmd/build/${{ matrix.type }}/zedmd64.lib tmp
142+
cp extern/libzedmd/build/${{ matrix.type }}/zedmd64.dll tmp
143+
cp extern/libzedmd/build/${{ matrix.type }}/libserialport64.lib tmp
144+
cp extern/libzedmd/build/${{ matrix.type }}/libserialport64.dll tmp
145+
elif [[ "${{ matrix.arch }}" == "x86" ]]; then
146+
cp extern/libzedmd/build/${{ matrix.type }}/zedmd.lib tmp
147+
cp extern/libzedmd/build/${{ matrix.type }}/zedmd.dll tmp
148+
cp extern/libzedmd/build/${{ matrix.type }}/libserialport.lib tmp
149+
cp extern/libzedmd/build/${{ matrix.type }}/libserialport.dll tmp
150+
fi
151+
cp build/${{ matrix.type }}/extending.lib tmp
152+
cp build/${{ matrix.type }}/extending.dll tmp
153+
else
154+
ARTIFACT_PATH="libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
155+
cp extern/libzedmd/build/libzedmd.* tmp
156+
cp extern/libzedmd/build/libserialport.* tmp
157+
if [[ "${{ matrix.platform }}" == "macos" ]]; then
158+
cp build/extending.dylib tmp
159+
elif [[ "${{ matrix.platform }}" == "linux" ]]; then
160+
cp build/extending.so tmp
161+
fi
162+
cd tmp
163+
tar -czvf ../${ARTIFACT_PATH} *
164+
fi
165+
echo "artifact_path=${ARTIFACT_PATH}" >> $GITHUB_OUTPUT
166+
- name: Upload artifacts
167+
uses: actions/upload-artifact@v4
168+
with:
169+
name: libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.type }}
170+
path: ${{ steps.artifacts.outputs.artifact_path }}
103171

104-
# - name: Prepare artifacts
172+
post-build:
173+
runs-on: macos-latest
174+
needs: [ version, build ]
175+
name: Build libzedmd-macos
176+
steps:
177+
- uses: actions/download-artifact@v4
178+
- name: Unpack artifacts
179+
run: |
180+
cd libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-x64-Release
181+
tar -xzvf libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-x64.tar.gz
182+
cd ..
183+
cd libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-arm64-Release
184+
tar -xzvf libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-arm64.tar.gz
185+
- name: Combine macos architectures
186+
run: |
187+
mkdir tmp
188+
find "libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-arm64-Release" -name "*.dylib" | while read -r file; do
189+
if [ -L "$file" ]; then
190+
cp -a "$file" "tmp/"
191+
elif [ -f "$file" ]; then
192+
filename=$(basename "$file")
193+
lipo -create -output "tmp/$filename" \
194+
"libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-arm64-Release/$filename" \
195+
"libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-x64-Release/$filename"
196+
fi
197+
done
198+
- name: Prepare artifacts
199+
run: |
200+
cd tmp
201+
tar -czvf ../libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos.tar.gz *
202+
- name: Upload artifacts
203+
uses: actions/upload-artifact@v4
204+
with:
205+
name: libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-Release
206+
path: libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos.tar.gz
207+
- name: Package
208+
# if: startsWith(github.ref, 'refs/tags/v')
209+
run: |
210+
zip -r libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-win-x64.zip libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-win-x64-Release
211+
zip -r libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-win-x86.zip libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-win-x86-Release
212+
213+
- name: Release
214+
uses: softprops/action-gh-release@v2
215+
# if: startsWith(github.ref, 'refs/tags/v')
216+
with:
217+
draft: true
218+
files: |
219+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-win-x64.zip
220+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-win-x86.zip
221+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-arm64-Release/libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-arm64.tar.gz
222+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-x64-Release/libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos-x64.tar.gz
223+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-macos.tar.gz
224+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-linux-x64-Release/libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-linux-x64.tar.gz
225+
libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-linux-aarch64-Release/libzedmd-python-pybind11-extension-${{ needs.version.outputs.tag }}-linux-aarch64.tar.gz

0 commit comments

Comments
 (0)