-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
style: Google |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(pyshell LANGUAGES CXX) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS on) | ||
|
||
add_compile_options(-fPIC -std=c++20 -Wall -Wextra) | ||
|
||
file(GLOB MAIN_SOURCES src/*.cpp) | ||
file(GLOB SHELL_SOURCES shell/*.cpp shell/*.hpp) | ||
|
||
find_package(Python COMPONENTS Interpreter Development) | ||
find_package(pybind11 CONFIG) | ||
|
||
# Auto Generation | ||
set(cppygen_generated_hpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.hpp) | ||
set(cppygen_generated_cpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.cpp) | ||
set(cppygen_config_file ${CMAKE_CURRENT_LIST_DIR}/cppygenconfig.toml) | ||
|
||
find_program(_CPPYGEN_GENERATOR cppygen) | ||
message(${cppygen_config_file}) | ||
|
||
pybind11_add_module(pyshell MODULE ${MAIN_SOURCES} ${SHELL_SOURCES} | ||
${cppygen_generated_cpp}) | ||
|
||
target_link_libraries( | ||
pyshell | ||
PUBLIC # | ||
pybind11::module # | ||
pybind11::lto # | ||
pybind11::windows_extras # | ||
${MAIN_LINK_LIBRARIES}) | ||
target_include_directories(pyshell PRIVATE ${CMAKE_CURRENT_LIST_DIR}/shell | ||
${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
# pybind11_extension(pyshell) pybind11_strip(pyshell) | ||
|
||
set_target_properties( | ||
pyshell | ||
PROPERTIES # | ||
INTERPROCEDURAL_OPTIMIZATION ON | ||
CXX_VISIBILITY_PRESET "hidden" | ||
VISIBILITY_INLINES_HIDDEN ON) | ||
|
||
add_custom_command( | ||
OUTPUT ${cppygen_generated_hpp} ${cppygen_generated_cpp} | ||
COMMAND | ||
${_CPPYGEN_GENERATOR} ARGS # | ||
--config_file ${cppygen_config_file} # | ||
--cwd ${CMAKE_CURRENT_LIST_DIR} # | ||
--include_directories $<TARGET_PROPERTY:pyshell,INCLUDE_DIRECTORIES> # | ||
--verbose | ||
DEPENDS ${SHELL_SOURCES} ${cppygen_config_file} | ||
COMMENT | ||
"Generating CPPyGen Code To ${cppygen_generated_hpp} and ${cppygen_generated_cpp}" | ||
VERBATIM) | ||
|
||
# vim:sw=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
mode = "header" | ||
|
||
search_namespace = "Shell" # default: cppygen | ||
|
||
# class の定義が書かれた Shell namespace を持つ header の一覧: 重複は解決しない | ||
headers = ["shell/*.hpp"] | ||
|
||
# 出力ディレクトリ | ||
output_dir = "build" | ||
|
||
# ここでは shell 以下のヘッダーを source で include しているためそのことを宣言してあげる必要がある。 | ||
include_directories = ["shell"] | ||
|
||
flags = ["-Wall"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "hoge.hpp" | ||
#include <iostream> | ||
#include <string> | ||
|
||
namespace Shell { | ||
|
||
void start(std::string arg = "", std::string tty = "none") { | ||
std::cout << "This is dummy start function with arg = " << arg << std::endl; | ||
std::cout << "tty = " << tty << std::endl; | ||
} | ||
|
||
// このようなユーザー定義のクラスを用いている場合は | ||
// PyGen はデフォルトでは Header | ||
// の場所を探しきれず、ただしく、これがユーザー定義 | ||
// のクラスを返す変数であることを認識できないので、 flag を渡して | ||
// Header の位置を教えてあげる必要がある。 | ||
Foo make_foo() { return Foo(1, 2); } | ||
|
||
void hoge() { std::cout << "Hello" << std::endl; } | ||
|
||
void hoge(char) { std::cout << "Hello" << std::endl; } | ||
|
||
void fuga() { std::cout << "Hello Fuga" << std::endl; } | ||
|
||
int add(int a, int b) { return a + b; } | ||
|
||
int sub(int a, int b) { return a - b; } | ||
|
||
namespace hogehoge { | ||
|
||
/// Piyopiyo!!! | ||
namespace piyo { | ||
|
||
/// Comment!!! | ||
int add_piyo(int x, int y) { return x + y; } | ||
|
||
int add_(int x, int y) { return x + y; } | ||
|
||
} // namespace piyo | ||
|
||
} // namespace hogehoge | ||
|
||
Shell::VectorD return_vector(Shell::VectorD a) { return a; } | ||
|
||
} // namespace Shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include <vector> | ||
|
||
namespace Shell { | ||
|
||
void hoge(); | ||
|
||
void hoge(char); | ||
|
||
void fuga(); | ||
|
||
int add(int a, int b); | ||
|
||
int sub(int a, int b); | ||
|
||
class Foo { | ||
public: | ||
Foo() = default; // pybind11 から見えるのは この default コンストラクターのみ | ||
Foo(int a, int b) : a(a), b(b) {} | ||
|
||
void bar() {} | ||
void bar(int) {} | ||
int a = 32; | ||
int b = 42; | ||
}; | ||
|
||
typedef std::vector<double> VectorD; | ||
|
||
} // namespace Shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "piyo.hpp" | ||
#include "hoge.hpp" | ||
#include <vector> | ||
|
||
namespace Shell::piyo { | ||
|
||
Piyoyo make_piyoyo() { | ||
Piyoyo tmp; | ||
tmp.setValue(-5); | ||
return tmp; | ||
} | ||
std::vector<double> fugafuga() { return {3, 4, 5, 6}; } | ||
|
||
} // namespace Shell::piyo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace Shell { | ||
struct Piyoyo { | ||
int value; | ||
int getValue() { return value; } | ||
void setValue(int val) { value = val; } | ||
}; | ||
|
||
std::vector<double> fugafuga(); | ||
|
||
} // namespace Shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <pybind11/cast.h> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/pytypes.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "cppygen_generated.hpp" | ||
|
||
PYBIND11_MODULE(pyshell, m) { CPPyGen::CPPyGenExport(m); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# このコマンドで stub を作る | ||
cd ./build && stubgen -p pyshell -o ../python/stubs |