Skip to content

Commit 42dae34

Browse files
committed
build: resolve DPI headers lazily during build_ext
1 parent fcd1352 commit 42dae34

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

setup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
HERE = os.path.dirname(os.path.abspath(__file__))
2121
DPI_BRIDGE_DIR = os.path.join(HERE, "dpi_bridge")
2222
NATIVE_SRC_DIR = os.path.join("src", "native")
23+
DPI_INCLUDE_PLACEHOLDER = "__DM_DPI_INCLUDE_PLACEHOLDER__"
2324

2425

2526
def read_project_version() -> str:
@@ -81,9 +82,6 @@ def find_dpi_include():
8182
"See README.md for details."
8283
)
8384

84-
85-
DPI_INCLUDE_DIR = find_dpi_include()
86-
8785
# Macros
8886
define_macros = []
8987
if struct.calcsize("P") == 8:
@@ -101,6 +99,12 @@ class build_ext(_build_ext):
10199
"""Custom build_ext that builds the Go bridge library before compiling."""
102100

103101
def run(self):
102+
dpi_include_dir = find_dpi_include()
103+
for ext in self.extensions:
104+
ext.include_dirs = [
105+
dpi_include_dir if d == DPI_INCLUDE_PLACEHOLDER else d
106+
for d in ext.include_dirs
107+
]
104108
if not os.environ.get("DMPYTHON_SKIP_GO_BUILD"):
105109
self._build_go_bridge()
106110
super().run()
@@ -146,7 +150,7 @@ def _build_go_bridge(self):
146150
extension = Extension(
147151
name="dmPython",
148152
sources=C_SOURCES,
149-
include_dirs=[DPI_INCLUDE_DIR, os.path.join(HERE, NATIVE_SRC_DIR)],
153+
include_dirs=[DPI_INCLUDE_PLACEHOLDER, os.path.join(HERE, NATIVE_SRC_DIR)],
150154
library_dirs=[DPI_BRIDGE_DIR],
151155
libraries=["dmdpi"],
152156
define_macros=define_macros,

0 commit comments

Comments
 (0)