aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/python.yml57
-rw-r--r--examples/python/CMakeLists.txt11
-rw-r--r--examples/python/hello.cpp19
3 files changed, 87 insertions, 0 deletions
diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml
new file mode 100644
index 0000000..42c8386
--- /dev/null
+++ b/.github/workflows/python.yml
@@ -0,0 +1,57 @@
+name: Boost.Python
+
+on:
+ push:
+ pull_request:
+ schedule:
+ # Weekly, at 5:45 AM on Friday (somewhat randomly chosen).
+ - cron: '45 5 * * 5'
+ workflow_dispatch:
+
+jobs:
+ python:
+ strategy:
+ matrix:
+ os: [ubuntu-latest, windows-latest]
+ include:
+ - version: '1.78.0'
+
+ runs-on: '${{ matrix.os }}'
+
+ name: 'Boost.Python: ${{ matrix.version }} / ${{ matrix.os }}'
+
+ defaults:
+ run:
+ shell: pwsh
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Set up Python
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.x'
+
+ - name: Cache Boost
+ uses: actions/cache@v3
+ with:
+ path: '${{ runner.workspace }}/boost_*.tar.gz'
+ key: 'boost-${{ matrix.version }}'
+
+ - id: build
+ name: Build Boost
+ uses: ./
+ with:
+ version: '${{ matrix.version }}'
+ libraries: python
+
+ - name: Fix PATH
+ run: |
+ $bin_dir = & python -c "import sysconfig; print(sysconfig.get_path('scripts', 'nt_user'))"
+ echo $bin_dir >> $env:GITHUB_PATH
+ if: runner.os == 'Windows'
+
+ - name: Build an example module
+ run: |
+ cmake-build --platform x64 --boost '${{ steps.build.outputs.root }}' --configuration Release -- ./examples/python/
diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt
new file mode 100644
index 0000000..f43c3a7
--- /dev/null
+++ b/examples/python/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.5) # for Boost::* imported targets
+
+project(example_python)
+
+find_package(Python REQUIRED COMPONENTS Development)
+set(boost_python "python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}")
+find_package(Boost REQUIRED COMPONENTS "${boost_python}")
+
+add_library(hello SHARED hello.cpp)
+target_link_libraries(hello PRIVATE Python::Module)
+target_link_libraries(hello PRIVATE Boost::disable_autolinking "Boost::${boost_python}")
diff --git a/examples/python/hello.cpp b/examples/python/hello.cpp
new file mode 100644
index 0000000..b7516e4
--- /dev/null
+++ b/examples/python/hello.cpp
@@ -0,0 +1,19 @@
+#include <string>
+
+#include <boost/python.hpp>
+using namespace boost::python;
+
+struct World
+{
+ void set(const std::string& msg) { this->msg = msg; }
+ std::string greet() const { return msg; }
+ std::string msg;
+};
+
+BOOST_PYTHON_MODULE(hello)
+{
+ class_<World>("World")
+ .def("greet", &World::greet)
+ .def("set", &World::set)
+ ;
+}