scikit-build / scikit-build-core

A next generation Python CMake adaptor and Python API for plugins
https://scikit-build-core.readthedocs.io
Apache License 2.0
247 stars 52 forks source link

VSCode Pybind11 Include Path #635

Open mcleantom opened 9 months ago

mcleantom commented 9 months ago

I was wondering if you knew where to set the include path for pybind11 so that intellesense in vscode can find pybind11?

image

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\tom.mclean\src\wind_triangle\src\main.cpp).C/C++(1696)

Pybind11 is found in a tempoary directory, so I dont know how I can add it's header files to my vscode C/C++ configuration:

-- Found pybind11: C:/Users/tom.mclean/AppData/Local/Temp/pip-build-env-ttn80fca/overlay/Lib/site-packages/pybind11/include (found version "2.11.1")

(My project was bootstrapped using the cookiecutter template)

henryiii commented 9 months ago

That temporary directory is removed by pip, so the path is there, it's just gone by the time vscode is looking for it. If you disable build isolation and install the dependencies manually, then the path should work.

Something like:

@nox.session(venv_backend="none")
def dev(session: nox.Session) -> None:
    """
    Prepare a .venv folder.
    """

    session.run(sys.executable, "-m", "venv", ".venv")
    session.run(".venv/bin/pip", "install", "scikit-build-core[pyproject]", "pybind11")
    session.run(
        ".venv/bin/pip",
        "install",
        "--no-build-isolation",
        "--check-build-dependencies",
        "-ve.",
        "-Ccmake.define.CMAKE_EXPORT_COMPILE_COMMANDS=1",
        "-Cbuild-dir=build",
    )

That produces a /build dir with compile commands in it that vscode can read when you run nox -s dev.

henryiii commented 9 months ago

(which cookiecutter template?)

mcleantom commented 9 months ago

@henryiii from https://github.com/scientific-python/cookie :)