Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ if (LLDB_ENABLE_PYTHON)
set(cachestring_LLDB_PYTHON_EXT_SUFFIX
"Filename extension for native code python modules")

if (LLDB_ENABLE_PYTHON_LIMITED_API)
set(stable_abi "--stable-abi")
endif()

foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
execute_process(
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py
${stable_abi}
${var}
OUTPUT_VARIABLE value
OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down
8 changes: 7 additions & 1 deletion lldb/bindings/python/get-python-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def relpath_nodots(path, base):
def main():
parser = argparse.ArgumentParser(description="extract cmake variables from python")
parser.add_argument("variable_name")
parser.add_argument(
"--stable-abi", action="store_true", help="Target the Stable C ABI"
)
args = parser.parse_args()
if args.variable_name == "LLDB_PYTHON_RELATIVE_PATH":
# LLDB_PYTHON_RELATIVE_PATH is the relative path from lldb's prefix
Expand Down Expand Up @@ -68,7 +71,10 @@ def main():
print("sys.prefix:", sys.prefix, file=sys.stderr)
sys.exit(1)
elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
print(sysconfig.get_config_var("EXT_SUFFIX"))
if args.stable_abi:
print(".abi3%s" % sysconfig.get_config_var("SHLIB_SUFFIX"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to get this programmatically, though it's mentioned for example in https://peps.python.org/pep-0720/.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do see code using EXTENSION_SUFFIXES and checking for the entry that contains .abi3. It doesn't say it has a set order and in theory I could make my strange platform's shared object suffix start with .abi3 and end up with .cpython-311-x86_64-linux-letsbreakassumptions.abi3askingfortrouble as one of the entries.

So yes, what you've done is fine.

else:
print(sysconfig.get_config_var("EXT_SUFFIX"))
else:
parser.error(f"unknown variable {args.variable_name}")

Expand Down
Loading