Skip to content

Commit 8c73505

Browse files
committed
[test] fix build for macos
1 parent dfb2891 commit 8c73505

1 file changed

Lines changed: 9 additions & 46 deletions

File tree

pytron/engines/native/build.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -97,53 +97,16 @@ def build():
9797
except Exception as e:
9898
print(f"[WARNING] Could not apply symbol shield: {e}")
9999

100-
# --- macOS: inject Python lib so the linker can resolve _Py* symbols ---
101-
# Raw `cargo rustc` does not ask the Python interpreter where its dylib
102-
# lives the way `maturin` does. We do it manually here.
100+
# --- macOS: tell pyo3's build script which Python interpreter to use ---
101+
# Setting PYO3_PYTHON is sufficient. pyo3's `extension-module` feature
102+
# automatically emits `-undefined dynamic_lookup` on macOS so all _Py*
103+
# symbols resolve at runtime from the embedding interpreter.
104+
# Do NOT add manual -l or RUSTFLAGS: macOS framework Python's LDLIBRARY
105+
# is a path ("Python.framework/Versions/3.11/Python"), not a valid -l name.
103106
if sys.platform == "darwin" and not is_android:
104-
try:
105-
import sysconfig
106-
107-
py_exec = sys.executable
108-
# Tell pyo3's build script which Python to use
109-
env["PYO3_PYTHON"] = py_exec
110-
111-
# Locate the Python library directory and dylib
112-
ldlibdir = sysconfig.get_config_var("LIBDIR") or ""
113-
ldlib = sysconfig.get_config_var("LDLIBRARY") or ""
114-
multiarch = sysconfig.get_config_var("MULTIARCH") or ""
115-
116-
# Also check the framework path (standard macOS CPython installs)
117-
framework_prefix = sysconfig.get_config_var("PYTHONFRAMEWORKPREFIX") or ""
118-
framework_dir = (
119-
os.path.join(framework_prefix, "lib") if framework_prefix else ""
120-
)
121-
122-
# Build a list of candidate library search directories
123-
lib_dirs = [d for d in [ldlibdir, framework_dir] if d and os.path.isdir(d)]
124-
125-
if lib_dirs:
126-
rustflags = env.get("RUSTFLAGS", "")
127-
for lib_dir in lib_dirs:
128-
rustflags += f" -L {lib_dir}"
129-
# Link the Python shared library explicitly
130-
if ldlib:
131-
# Strip lib prefix and extension for -l flag
132-
libname = ldlib
133-
if libname.startswith("lib"):
134-
libname = libname[3:]
135-
for ext in [".dylib", ".so", ".a"]:
136-
if libname.endswith(ext):
137-
libname = libname[: -len(ext)]
138-
break
139-
rustflags += f" -l {libname}"
140-
env["RUSTFLAGS"] = rustflags.strip()
141-
print(f"[INFO] macOS Python lib dirs: {lib_dirs}")
142-
print(f"[INFO] RUSTFLAGS set to: {env['RUSTFLAGS']}")
143-
else:
144-
print(f"[WARNING] Could not locate Python library directory on macOS.")
145-
except Exception as e:
146-
print(f"[WARNING] macOS Python lib detection failed: {e}")
107+
env["PYO3_PYTHON"] = sys.executable
108+
print(f"[INFO] macOS: PYO3_PYTHON set to {sys.executable}")
109+
147110

148111
try:
149112
subprocess.check_call(cargo_cmd, cwd=ENGINE_DIR, env=env)

0 commit comments

Comments
 (0)