How to build an executable while installing in normal and editable mode
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 38/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Domínio
- build-system
Direção de pesquisa
Comece lendo setup.py e CMakeLists.txt e, em seguida, reproduza tanto pip install . quanto pip install -e . usando os comandos e o layout do projeto indicados na issue. Compare onde o executável helloworld é gerado em cada modo e rastreie as configurações existentes de diretório de saída do CMake. O trabalho estará concluído quando ambos os modos de instalação criarem o executável sob o caminho raiz apropriado do Python.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- C++
- Estrelas
- 671
- Forks
- 220
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de pybind/cuda_example
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
pybind/cuda_example#191 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
pybind/cuda_example#187 · 8 comentários ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
pybind/cuda_example#153 · 5 comentários ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
pybind/cuda_example#123 · 1 comentário ·
-
How to specify python?Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 25/100
pybind/cuda_example#122 · 5 comentários ·
Todas as issues de pybind/cuda_example
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
-
triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 3 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
patrick-hudson/put.gd-desktop#2044 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
uxlfoundation/oneDNN#6604 · 1 comentário ·
Mantenedores costumam responder em até 2 dias