How to build an executable while installing in normal and editable mode
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 領域
- build-system
調査の方向性
まず setup.py と CMakeLists.txt を読み、issue に記載されているコマンドとプロジェクト構成を使って pip install . と pip install -e . の両方を再現します。それぞれのモードで実行可能ファイル helloworld がどこに生成されるかを比較し、既存の CMake の出力ディレクトリ設定を追跡します。両方のインストールモードで、適切な Python root path 配下に実行可能ファイルが作成されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hello, I'm currently learning how to use CMake and pybind11 with this project. As part of the installation process, I need to build and install a C++ source file. To ensure that everything is clear, I've included the reproduction code below.
Description
- My project structure: It's basically the same except there is my cpp source file
helloworld.cppinsrc/folder.
$ tree -L 2
.
├── CMakeLists.txt
├── pybind11
├── pyproject.toml
├── setup.py
└── src
├── helloworld.cpp
└── main.cpp
src/helloworld.cpp: A trivial helloworld program.$ cat src/helloworld.cpp
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello World!!!\n";
return 0;
}
CMakeLists.txt: It's basically the same as CMakeLists.tx exceptadd_executable(helloworld src/helloworld.cpp)is added to build executable.
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(cmake_example)
add_executable(helloworld src/helloworld.cpp)
add_subdirectory(pybind11)
pybind11_add_module(cmake_example src/main.cpp)
target_compile_definitions(cmake_example
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
pyproject.toml:
$ cat pyproject.toml
[build-system]
requires = ["setuptools>=62.0.0", "wheel", "cmake>=3.22"]
build-backend = "setuptools.build_meta"
pybind11is a git submodule, andsetup.pyis exactly the same as this setup.py.
Build in normal mode.
- Create virtual env and update pip:
python3 -m venv venv && source venv/bin/activate && python3 -m pip install --upgrade pip - Install in normal mode:
python3 -m pip install . cmake_examplelibrary is installed correctly but myhelloworldprogram is not. There is nohelloworldprogram invenv.
$ ls venv/lib/python3.8/site-packages/
cmake_example-0.0.1.dist-info
cmake_example.cpython-38-x86_64-linux-gnu.so
Build in editable mode.
- Create virtual env and update pip:
python3 -m venv venv && source venv/bin/activate && python3 -m pip install --upgrade pip - Install in editable mode:
python3 -m pip install -e . cmake_examplelibrary is also installed correctly but myhelloworldprogram is not. There is nohelloworldprogram created in the current folder.
$ ls
cmake_example.cpython-38-x86_64-linux-gnu.so cmake_example.egg-info CMakeLists.txt pybind11 pyproject.toml setup.py src venv
My experiment:
I actually tried to make it work by modifying setup.py with the following way.
- Add code snippet in
setup.pyin Line:47.
bindir = extdir / "bin"
print(f"User's executables resides in {bindir}")
cmake_args = [
# My innovation. helloworld can be called in scripts.
f"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY={bindir}{os.sep}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
]
This approach kind of work. Now I can do pip install . and helloworld program appears in venv/lib/python3.8/site-packages/bin/helloworld. However, this approach doesn't work in editable model. I.e., I do pip install -e ., but helloworld program is no created anywhere in the project.
My question is how to achieve the following goal: I would like the helloworld program to be created automatically when I run pip install . and pip install -e ., and I want this program to be installed in the correct Python root path in both modes. Do you have any suggestions or advice on how I can make this happen? Thank you for your help!
System info:
OS: ubuntu20.04
Python: Python3.8
- 主要言語
- C++
- スター
- 671
- フォーク
- 220
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pybind/cuda_example のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
pybind/cuda_example#191 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
pybind/cuda_example#187 · コメント 8 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
pybind/cuda_example#153 · コメント 5 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
pybind/cuda_example#123 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
pybind/cuda_example#122 · コメント 5 件 ·
pybind/cuda_example の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
patrick-hudson/put.gd-desktop#2044 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
uxlfoundation/oneDNN#6604 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信