-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·86 lines (68 loc) · 2.33 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·86 lines (68 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
cd "$SCRIPT_DIR/.."
. _detail/set_env_vars.sh
./python/clean.sh
mkdir -p python/output/tmp
# Those are the Clang-style flags for the parser.
EXTRA_PARSER_CXX_FLAGS=(
-std=c++20 -Wall -Wextra -pedantic-errors
-fparse-all-comments
)
# Those are optional tunable flags for the parser.
EXTRA_PARSER_FLAGS=(
)
# Those are optional tunable flags for the compilation.
EXTRA_CXX_FLAGS=(
-DMB_PB11_STRIPPED_NAMESPACES='"Example"'
)
PYTHON_MODULE_EXT=.so
# Need extra flags on MSYS2.
if [[ $(uname -o) == Msys ]]; then
EXTRA_PARSER_CXX_FLAGS+=(--sysroot="$MSYSTEM_PREFIX")
EXTRA_CXX_FLAGS+=($(python3-config --libs))
PYTHON_MODULE_EXT=.pyd
fi
set -x
# Assemble the combined input header.
echo "#pragma once" >python/output/tmp/combined_input.h
find input \( -name '*.h' -or -name '*.hpp' \) -printf "#include <%p>\n" >>python/output/tmp/combined_input.h
# Parse the input header.
../build/mrbind \
python/output/tmp/combined_input.h \
--format=macros \
-o python/output/tmp/generated.cpp \
--ignore :: \
--allow Example \
"${EXTRA_PARSER_FLAGS[@]}" \
-- \
-xc++-header \
-resource-dir="${CLANG_RESOURCE_DIR:-$("$CLANG_CXX" -print-resource-dir)}" \
-I. \
"${EXTRA_PARSER_CXX_FLAGS[@]}"
# Clone Pybind, if it doesn't already exist.
if [[ ! -d python/pybind11 ]]; then
git clone https://github.com/pybind/pybind11 python/pybind11
# This is an arbitrary commit that's known to work.
(cd python/pybind11 && git checkout d2413f5bca91a2c091b9b0801e0c1b5bf089e31d)
fi
PYTHON=${PYTHON:-python3}
# Compile the Python module.
# Note that the output filename must match the name passed to `-DMB_PB11_MODULE_NAME=`, minus the extension.
"$CLANG_CXX" \
python/output/tmp/generated.cpp \
-shared -fPIC \
-o python/output/example$PYTHON_MODULE_EXT \
-std=c++20 \
-Wall -Wextra -pedantic-errors \
-I../include \
-Ipython/pybind11/include \
-I. \
-DMRBIND_HEADER='<mrbind/targets/pybind11.h>' \
-DMB_PB11_MODULE_NAME=example \
-DMB_DEFINE_IMPLEMENTATION \
-DPYBIND11_COMPILER_TYPE='"_mrbind_example"' -DPYBIND11_BUILD_ABI='"_mrbind_example"' \
$(${PYTHON}-config --cflags --embed) \
"${EXTRA_CXX_FLAGS[@]}"
# Run a test program using the Python module.
PYTHONPATH=python/output $PYTHON python/example_consumer.py