Skip to content

Commit

Permalink
Lookup library name from Python (#64)
Browse files Browse the repository at this point in the history
I have a suspicion this fixes #63 also
  • Loading branch information
gatesn authored Sep 8, 2023
1 parent 2517b7e commit d5aa05f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pydust/buildzig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import contextlib
import os
import subprocess
import sys
import sysconfig
Expand All @@ -24,7 +25,12 @@
PYVER_MINOR = ".".join(str(v) for v in sys.version_info[:2])
PYVER_HEX = f"{sys.hexversion:#010x}"
PYINC = sysconfig.get_path("include")
PYLIB = sysconfig.get_config_var("LIBDIR")
PYLIBDIR = sysconfig.get_config_var("LIBDIR")
PYLDLIB = sysconfig.get_config_var("LDLIBRARY")

# Strip libpython3.11.a.so => python3.11.a
PYLDLIB = PYLDLIB[3:] if PYLDLIB.startswith("lib") else PYLDLIB
PYLDLIB = os.path.splitext(PYLDLIB)[0]


def zig_build(argv: list[str]):
Expand Down Expand Up @@ -210,8 +216,8 @@ def generate_build_zig(build_zig_file):
pydust: []const u8, compile: *std.Build.CompileStep, pyconf: *std.Build.Step.Options
) void {{
configurePythonInclude(pydust, compile, pyconf);
compile.linkSystemLibrary("python{PYVER_MINOR}");
compile.addLibraryPath(.{{ .path = "{PYLIB}" }});
compile.linkSystemLibrary("{PYLDLIB}");
compile.addLibraryPath(.{{ .path = "{PYLIBDIR}" }});
}}
"""
)
Expand Down

0 comments on commit d5aa05f

Please sign in to comment.