Skip to content

Commit

Permalink
[infra] Update to pybind11 2.8.1. (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Nov 26, 2021
1 parent 930fb8a commit 74b840e
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 21 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ jobs:
conan_cmd=/home/runner/.local/bin/conan
${conan_cmd} profile new tket --detect
${conan_cmd} profile update settings.compiler.libcxx=libstdc++11 tket
${conan_cmd} config set general.revisions_enabled=1
echo "CONAN_CMD=${conan_cmd}" >> $GITHUB_ENV
- name: Install ninja and ccache
run: sudo apt-get install ninja-build ccache
Expand All @@ -69,6 +68,8 @@ jobs:
run: ${CONAN_CMD} create --profile=tket recipes/tket-tests
- name: Build and run tket proptests
run: ${CONAN_CMD} create --profile=tket recipes/tket-proptests
- name: Install pybind11
run: ${CONAN_CMD} create --profile=tket recipes/pybind11
- name: Set up Python 3.7
if: github.event_name == 'push'
uses: actions/setup-python@v2
Expand Down Expand Up @@ -173,7 +174,6 @@ jobs:
run: |
pip install conan
conan profile new tket --detect --force
conan config set general.revisions_enabled=1
export CC=`which conan`
echo "CONAN_CMD=${CC}" >> $GITHUB_ENV
- name: Build symengine
Expand All @@ -184,6 +184,8 @@ jobs:
run: conan create --profile=tket recipes/tket-tests
- name: Build and run tket proptests
run: conan create --profile=tket recipes/tket-proptests
- name: Install pybind11
run: conan create --profile=tket recipes/pybind11
- name: Set up Python 3.7
if: github.event_name == 'push'
uses: actions/setup-python@v2
Expand Down Expand Up @@ -260,7 +262,6 @@ jobs:
id: conan
run: |
conan profile new tket --detect --force
conan config set general.revisions_enabled=1
export CC=`which conan`
echo "CONAN_CMD=${CC}" >> $GITHUB_ENV
- name: Install boost
Expand All @@ -273,6 +274,8 @@ jobs:
run: conan create --profile=tket recipes/tket-tests -o boost:without_fiber=True -o boost:without_json=True -o boost:without_nowide=True
- name: Build and run tket proptests
run: conan create --profile=tket recipes/tket-proptests -o boost:without_fiber=True -o boost:without_json=True -o boost:without_nowide=True
- name: Install pybind11
run: conan create --profile=tket recipes/pybind11
- name: Build pytket (3.8)
if: github.event_name == 'pull_request' || github.event_name == 'push'
run: |
Expand Down Expand Up @@ -339,7 +342,6 @@ jobs:
run: |
pip install conan
conan profile new tket --detect
conan config set general.revisions_enabled=1
$conan_cmd = (gcm conan).Path
echo "CONAN_CMD=${conan_cmd}" >> $GITHUB_ENV
- name: Cache tket build
Expand All @@ -357,6 +359,8 @@ jobs:
run: conan create --profile=tket recipes/tket-tests
- name: Build and run tket proptests
run: conan create --profile=tket recipes/tket-proptests
- name: Install pybind11
run: conan create --profile=tket recipes/pybind11
- name: Set up Python 3.7
if: github.event_name == 'push'
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linuxbuildwheel
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export CONAN_CMD=${PYBIN}/conan
cd /tket

${CONAN_CMD} profile new tket --detect
${CONAN_CMD} config set general.revisions_enabled=1
${CONAN_CMD} create --profile=tket recipes/symengine
${CONAN_CMD} create --profile=tket --test-folder=None recipes/tket
${CONAN_CMD} create --profile=tket --test-folder=None recipes/pybind11

cd /tket/pytket
mkdir wheelhouse
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pytket_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ jobs:
pip install conan
conan profile new tket --detect
conan profile update settings.compiler.libcxx=libstdc++11 tket
conan config set general.revisions_enabled=1
- name: Build symengine
run: conan create --profile=tket recipes/symengine
- name: Build tket
run: conan create --profile=tket recipes/tket
- name: Install pybind11
run: conan create --profile=tket recipes/pybind11
- name: Build pytket
run: |
cd pytket
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ jobs:
run: |
pip install conan
conan profile new tket --detect --force
conan config set general.revisions_enabled=1
conan create --profile=tket recipes/symengine
conan create --profile=tket recipes/tket
- name: Install pybind11
run: conan create --profile=tket recipes/pybind11
- name: Build wheel (3.7)
run: .github/workflows/build_macos_wheel
- name: Set up Python 3.8
Expand Down Expand Up @@ -102,10 +103,10 @@ jobs:
eval "$(pyenv init -)"
pyenv shell tket-3.8
conan profile new tket --detect --force
conan config set general.revisions_enabled=1
conan install --profile=tket boost/1.77.0@ --build=missing -o boost:without_fiber=True -o boost:without_json=True -o boost:without_nowide=True
conan create --profile=tket recipes/symengine -o boost:without_fiber=True -o boost:without_json=True -o boost:without_nowide=True
conan create --profile=tket recipes/tket -o boost:without_fiber=True -o boost:without_json=True -o boost:without_nowide=True
conan create --profile=tket recipes/pybind11
.github/workflows/build_macos_m1_wheel
pyenv shell tket-3.9
.github/workflows/build_macos_m1_wheel
Expand Down Expand Up @@ -145,7 +146,6 @@ jobs:
run: |
pip install conan
conan profile new tket --detect
conan config set general.revisions_enabled=1
$conan_cmd = (gcm conan).Path
echo "CONAN_CMD=${conan_cmd}" >> $GITHUB_ENV
- name: Cache tket build
Expand All @@ -159,6 +159,8 @@ jobs:
- name: Build tket
if: steps.cache-tket.outputs.cache-hit != 'true'
run: conan create --profile=tket recipes/tket
- name: Install pybind11
run: conan create --profile=tket recipes/pybind11
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ If you wish you can set your profile to Debug mode:
conan profile update settings.build_type=Debug tket
```

#### Enable revisions

In order to pick up the proper revision of the `pybind11` package, it is
currently necessary to do the following (or equivalent):

```shell
conan config set general.revisions_enabled=1
```

#### Test dependencies

A few of the tket tests require a working LaTeX installation, including
Expand Down Expand Up @@ -161,7 +152,13 @@ with:
conan create --profile=tket recipes/tket-proptests
```

Now to build pytket:
Now to build pytket, first install the `pybind11` headers:

```shell
conan create --profile=tket recipes/pybind11
```

Then build the pytket module:

```shell
cd pytket
Expand Down
5 changes: 4 additions & 1 deletion pytket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ find_file(CONANBUILDINFO_FILE conanbuildinfo.cmake HINTS ${CMAKE_BINARY_DIR})
include(${CONANBUILDINFO_FILE})
conan_basic_setup(NO_OUTPUT_DIRS)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
find_package(pybind11 REQUIRED)

set(Boost_NO_BOOST_CMAKE ON)

if (WIN32)
Expand All @@ -37,7 +40,7 @@ else()
endif()

function(build_module module)
pybind11_add_module(${module} NO_EXTRAS ${ARGN})
pybind11_add_module(${module} ${ARGN})
target_include_directories(${module} PRIVATE binders/include)
target_link_libraries(${module} PRIVATE ${CONAN_LIBS})
endfunction(build_module)
Expand Down
3 changes: 2 additions & 1 deletion pytket/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[requires]
tket/1.0.1
pybind11/2.6.2#66f97eac059bef5b60bd6898ec4869fd
pybind11/2.8.1
nlohmann_json/3.10.4
pybind11_json/0.2.11

[generators]
cmake
cmake_find_package
97 changes: 97 additions & 0 deletions recipes/pybind11/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 2019-2021 Cambridge Quantum Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from conans import ConanFile, tools, CMake
import os
import sys


class PyBind11Conan(ConanFile):
name = "pybind11"
version = "2.8.1"
description = "Seamless operability between C++11 and Python"
topics = "conan", "pybind11", "python", "binding"
homepage = "https://github.com/pybind/pybind11"
license = "BSD-3-Clause"
exports_sources = "CMakeLists.txt"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
no_copy_source = True

_source_subfolder = "source_subfolder"

_cmake = None

def source(self):
tools.get(
f"https://github.com/pybind/pybind11/archive/refs/tags/v{self.version}.tar.gz"
)
os.rename("{}-{}".format(self.name, self.version), self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["PYBIND11_INSTALL"] = True
self._cmake.definitions["PYBIND11_TEST"] = False
self._cmake.definitions[
"PYBIND11_CMAKECONFIG_INSTALL_DIR"
] = "lib/cmake/pybind11"

# Use pybind11's CMakeLists.txt directly. Otherwise,
# PYBIND11_MASTER_PROJECT is set to FALSE and the installation does not
# generate pybind11Targets.cmake. Without that the generated package
# config cannot be used successfully. We want to use the generated
# package config as this starting in version 2.6.0 onwards defines the
# pybind11::headers target that is required to make full use of all
# installed cmake files.
self._cmake.configure(
source_dir=os.path.join(self.source_folder, self._source_subfolder),
defs={"PYTHON_EXECUTABLE": sys.executable},
)
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
lib_folder = os.path.join(self.package_folder, "lib", "cmake", "pybind11")
os.rename(
os.path.join(lib_folder, "pybind11Config.cmake"),
os.path.join(lib_folder, "pybind11Install.cmake"),
)
os.unlink(os.path.join(lib_folder, "pybind11ConfigVersion.cmake"))

def package_id(self):
self.info.header_only()

def package_info(self):
self.cpp_info.includedirs.append(
os.path.join(self.package_folder, "include", "pybind11")
)

cmake_base_path = os.path.join("lib", "cmake", "pybind11")
self.cpp_info.builddirs = [cmake_base_path]

def get_path(filename):
return os.path.join(cmake_base_path, filename)

self.cpp_info.build_modules = [
get_path("FindPythonLibsNew.cmake"),
get_path("pybind11Install.cmake"),
]

0 comments on commit 74b840e

Please sign in to comment.