Skip to content

Commit 4b17321

Browse files
committed
Migrate example to semiwrap
1 parent 3cc1032 commit 4b17321

File tree

14 files changed

+80
-51
lines changed

14 files changed

+80
-51
lines changed

examples/demo/.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ py.typed
99
/dist
1010

1111
_init*.py
12-
pkgcfg.py
12+
*.pc
1313
version.py
14-
rpy-include
14+
trampolines

examples/demo/gen/.gitkeep

Whitespace-only changes.

examples/demo/meson.build

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project('demo', ['cpp'],
2+
default_options: ['warning_level=1', 'cpp_std=c++20',
3+
'b_colorout=auto', 'optimization=2', 'b_pie=true'])
4+
5+
# Include autogenerated wrapcfg/meson.build
6+
subdir('wrapcfg')
7+
8+
# Add additional source files to predefined variable in wrapcfg/meson.build
9+
demo_sources += files(
10+
'swdemo/src/demo.cpp',
11+
'swdemo/src/main.cpp',
12+
)
13+
14+
# You can add extra compilation arguments by adding a dependency to predefined
15+
# variable
16+
demo_deps += [
17+
declare_dependency(include_directories: ['swdemo/include'])
18+
]
19+
20+
# Include autogenerated wrapcfg/modules/meson.build
21+
# - Builds the extension modules
22+
# - Generates the pyi file for the extension modules
23+
subdir('wrapcfg/modules')

examples/demo/pyproject.toml

+36-39
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11

2-
# This section tells pip to install robotpy-build before starting a build
2+
# This section tells pip to install semiwrap before starting a build
33
[build-system]
4-
requires = ["robotpy-build"]
5-
6-
# Tells robotpy-build where to place autogenerated metadata
7-
[tool.robotpy-build]
8-
base_package = "rpydemo"
9-
10-
# This section configures the 'rpydemo' python package. Multiple
11-
# sections are possible to build multiple packages
12-
[tool.robotpy-build.wrappers."rpydemo"]
13-
name = "rpydemo"
14-
15-
# C++ source files to compile, path is relative to the root of the project
16-
sources = [
17-
"rpydemo/src/demo.cpp",
18-
"rpydemo/src/main.cpp"
19-
]
20-
21-
# This is a directory that can be used to customize the autogenerated
22-
# C++ code
23-
# -> autogenerate those files via `robotpy-build create-gen`
24-
generation_data = "gen"
25-
26-
# This tells robotpy-build to parse include/demo.h and autogenerate pybind11
27-
# wrappers for the contents of the header.
28-
# -> autogenerate this via `robotpy-build scan-headers`
29-
[tool.robotpy-build.wrappers."rpydemo".autogen_headers]
30-
demo = "demo.h"
31-
32-
33-
# Standard python package metadata
34-
[tool.robotpy-build.metadata]
35-
name = "robotpy-build-demo"
36-
description = "robotpy-build demo program"
37-
author = "RobotPy Development Team"
38-
author_email = "[email protected]"
39-
url = "https://github.com/robotpy/robotpy-build"
40-
license = "BSD-3-Clause"
41-
install_requires = []
4+
build-backend = "hatchling.build"
5+
requires = ["semiwrap", "hatch-meson", "hatchling"]
6+
7+
[project]
8+
name = "swdemo"
9+
description = "Demo program"
10+
version = "0.0.1"
11+
12+
#
13+
# hatch-semiwrap configuration
14+
# .. this generates meson.build to perform autogen
15+
#
16+
17+
[tool.hatch.build.hooks.semiwrap]
18+
# autogen_build_path = "autogen"
19+
20+
#
21+
# hatch-meson configuration
22+
# .. this executes meson to build python extension modules
23+
#
24+
25+
[tool.hatch.build.hooks.meson]
26+
27+
28+
#
29+
# semiwrap code generation configuration
30+
#
31+
32+
[tool.semiwrap]
33+
34+
[tool.semiwrap.extension_modules."swdemo._demo"]
35+
name = "demo"
36+
37+
[tool.semiwrap.extension_modules."swdemo._demo".headers]
38+
demo = "include/demo.h"

examples/demo/rpydemo/src/main.cpp

-3
This file was deleted.

examples/demo/setup.py

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# autogenerated by 'robotpy-build create-imports rpydemo rpydemo._rpydemo'
2-
from ._rpydemo import DemoClass, add2
2+
from ._demo import DemoClass, add2
33

44
__all__ = ["DemoClass", "add2"]

examples/demo/rpydemo/include/demo.h renamed to examples/demo/swdemo/include/demo.h

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/** Adds 2 to the first parameter and returns it */
55
int add2(int x);
66

7+
namespace demo {
8+
79
/**
810
Doxygen documentation is automatically added to your python objects
911
when the bindings are autogenerated.
@@ -20,3 +22,5 @@ class DemoClass {
2022
private:
2123
int m_x = 0;
2224
};
25+
26+
} // namespace demo

examples/demo/rpydemo/src/demo.cpp renamed to examples/demo/swdemo/src/demo.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ int add2(int x) {
55
return x + 2;
66
}
77

8+
namespace demo {
9+
810
void DemoClass::setX(int x) {
911
m_x = x;
1012
}
1113

1214
int DemoClass::getX() const {
1315
return m_x;
14-
}
16+
}
17+
18+
} // namespace demo

examples/demo/swdemo/src/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <semiwrap_init.swdemo._demo.hpp>
2+
3+
SEMIWRAP_PYBIND11_MODULE(m) {
4+
initWrapper(m);
5+
}

examples/demo/wrapcfg/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/meson.build

examples/demo/gen/demo.yml renamed to examples/demo/wrapcfg/demo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
functions:
44
add2:
55
classes:
6-
DemoClass:
6+
demo::DemoClass:
77
methods:
88
setX:
99
getX:
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/meson.build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/meson.build

0 commit comments

Comments
 (0)