Skip to content

Commit cb5c51e

Browse files
authored
add Matlab GHA workflow (with a struct-definition addition to the basic example)
1 parent c8511e4 commit cb5c51e

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.github/workflows/matlab.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: matlab
2+
3+
defaults:
4+
run:
5+
shell: bash
6+
7+
on:
8+
push:
9+
branches: [ master ]
10+
pull_request:
11+
branches: [ master ]
12+
13+
14+
15+
jobs:
16+
matlab:
17+
runs-on: ubuntu-20.04
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
submodules: recursive
23+
24+
- uses: actions/setup-python@v1
25+
with:
26+
python-version: 3.8
27+
28+
- run: |
29+
echo "CC=gcc-9" >> $GITHUB_ENV
30+
echo "CXX=g++-9" >> $GITHUB_ENV
31+
VERBOSE=1 pip install --verbose -e .
32+
33+
- run: |
34+
echo "m = py.importlib.import_module('cmake_example')" > test.m
35+
echo "AStruct = m.AStruct" >> test.m
36+
echo "AStruct()" >> test.m
37+
cat test.m
38+
39+
- run: python -c "import cmake_example as m; m.AStruct()"
40+
41+
- uses: matlab-actions/setup-matlab@v0
42+
with:
43+
release: R2022a
44+
45+
- uses: matlab-actions/run-command@v0
46+
with:
47+
command: test

src/main.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ int add(int i, int j) {
77
return i + j;
88
}
99

10+
struct AStruct {
11+
AStruct() {
12+
}
13+
};
14+
1015
namespace py = pybind11;
1116

1217
PYBIND11_MODULE(cmake_example, m) {
@@ -35,6 +40,8 @@ PYBIND11_MODULE(cmake_example, m) {
3540
Some other explanation about the subtract function.
3641
)pbdoc");
3742

43+
py::class_<AStruct>(m, "AStruct").def(py::init<>());
44+
3845
#ifdef VERSION_INFO
3946
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
4047
#else

tests/test_basic.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ def test_main():
55
assert m.__version__ == "0.0.1"
66
assert m.add(1, 2) == 3
77
assert m.subtract(1, 2) == -1
8+
assert m.AStruct() is not None

0 commit comments

Comments
 (0)