ziggy-pydust icon indicating copy to clipboard operation
ziggy-pydust copied to clipboard

Linking issue with brew-installed Framework Python

Open erik-dunteman opened this issue 7 months ago • 2 comments

Problem

Pydust fails to link against macOS Framework Python when building Zig tests, due to how the LDLibrary string is parsed.

Environment

  • macOS (Apple Silicon)
  • Python 3.13.2 (Homebrew Framework installation)
  • Pydust 0.25.1
  • Zig 0.14.0

Error

error: unable to find dynamic system library 'Python.framework/Versions/3' using strategy 'paths_first'

Root Cause

Framework Python returns:

sysconfig.get_config_var('LDLIBRARY') = 'Python.framework/Versions/3.13/Python'

The parsing of this in getLibpython() parses assuming more unix-like python paths, splitting on the dot . in the middle of 3.13, which is why the linker is trying to link 'Python.framework/Versions/3'.

Workaround

I was able to get things working by using pyenv to get a non-framework version of Python.

pyenv install 3.13.1
pyenv local 3.13.1

Thanks for this project! I've tried my hand a few times to take a stab at building something similar, so I was excited to see Pydust.

Happy to put in a PR, though didn't see a contributing guide and figured it's a quick fix on your end. LMK if I can help any more

erik-dunteman avatar Jun 04 '25 04:06 erik-dunteman

what about...?

diff --git a/pydust/src/pydust.build.zig b/pydust/src/pydust.build.zig
index f43e4d5e..ec39bd48 100644
--- a/pydust/src/pydust.build.zig
+++ b/pydust/src/pydust.build.zig
@@ -312,8 +312,9 @@ fn getLibpython(allocator: std.mem.Allocator, python_exe: []const u8) ![]const u
     }
 
     // Strip python3.11.a.so => python3.11.a
-    const lastIdx = std.mem.lastIndexOfScalar(u8, libname, '.') orelse libname.len;
-    libname = libname[0..lastIdx];
+    if (std.mem.endsWith(u8, libname, ".so")) {
+        libname = libname[0 .. libname.len - 3];
+    }
 
     return libname;
 }

GreyElaina avatar Jul 11 '25 05:07 GreyElaina

Solved in my fork, copied pyo3's impl, support windows build. WIP.

GreyElaina avatar Jul 12 '25 21:07 GreyElaina