Skip to content

Commit 433822d

Browse files
PaliCfacebook-github-bot
authored andcommitted
search recursively for static python (#290)
Summary: Pull Request resolved: #290 Somehow our [install tests](https://github.com/pytorch/multipy/actions/runs/3788974361/jobs/6444295267) and [runtime tests for python 3.7](https://github.com/pytorch/multipy/actions/runs/3788974394/jobs/6444296064) are broken on main due to what appears to be a linking issue. The root cause of these breakages ended up being that the static python library was moved a bit deeper into the directory we thought it would be in when using pyenv. We now search recursively for it, so that if it is there we are able to use it. Furthermore, we also fail early is we cannot find static python in order to help prevent future breakages. Test Plan: Imported from OSS Reviewed By: d4l3k Differential Revision: D42272568 Pulled By: PaliC fbshipit-source-id: 6b164d9a562be1aefaf9446aa7175cfd8150dd66
1 parent 63ead5f commit 433822d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

multipy/runtime/interpreter/CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,35 @@ message(STATUS "Python3_SITELIB - ${Python3_SITELIB}" )
1616
message(STATUS "Python3_LIBRARIES - ${Python3_LIBRARIES}" )
1717

1818
# Find static libpython with a preference for nolto since cross compiler version
19-
# LTO is problematic.
20-
string(REPLACE ".so" ".nolto.a" Python3_STATIC_LIBRARIES ${Python3_LIBRARIES})
19+
# LTO is problematic. We also recursively search in the directory for static
20+
# libpython, as it's not guarenteed to be in the same directory as libpython such
21+
# as with pyenv.
22+
23+
FUNCTION(find_file_with_different_suffix VAR FILE ORIGINAL_SUFFIX NEW_SUFFIX)
24+
string(REPLACE ${ORIGINAL_SUFFIX} ${NEW_SUFFIX} MODIFIED_FILE ${FILE})
25+
26+
if (NOT EXISTS ${MODIFIED_FILE})
27+
get_filename_component(MODIFIED_FILENAME ${MODIFIED_FILE} NAME)
28+
string(REPLACE "${MODIFIED_FILENAME}" "**/${MODIFIED_FILENAME}" MODIFIED_FILE_GLOB ${MODIFIED_FILE} )
29+
file(GLOB_RECURSE MODIFIED_FILE ${MODIFIED_FILE_GLOB})
30+
endif()
31+
set(${VAR} ${MODIFIED_FILE} PARENT_SCOPE)
32+
ENDFUNCTION()
33+
34+
find_file_with_different_suffix(Python3_STATIC_LIBRARIES ${Python3_LIBRARIES} ".so" ".nolto.a")
35+
2136
if (NOT EXISTS ${Python3_STATIC_LIBRARIES})
22-
string(REPLACE ".so" ".a" Python3_STATIC_LIBRARIES ${Python3_LIBRARIES})
37+
find_file_with_different_suffix(Python3_STATIC_LIBRARIES ${Python3_LIBRARIES} ".so" ".a")
2338
endif()
39+
40+
# If we still can't find the library, we fail early
41+
if (NOT EXISTS ${Python3_STATIC_LIBRARIES})
42+
get_filename_component(Python_FILENAME ${Python3_LIBRARIES} NAME)
43+
string(REPLACE ".so" ".nolto.a" Python3_STATIC_NOLTO_FILENAME ${Python_FILENAME})
44+
string(REPLACE ".so" ".a" Python3_STATIC_FILENAME ${Python_FILENAME})
45+
message(FATAL_ERROR "Cannot find ${Python3_STATIC_NOLTO_FILENAME} or ${Python3_STATIC_FILENAME} in ${libpython_DIR}. Are you using a static version of python? Please refer to https://github.com/pytorch/multipy for install instructions using conda and pyenv.")
46+
endif()
47+
2448
message(STATUS "Python3_STATIC_LIBRARIES - ${Python3_STATIC_LIBRARIES}" )
2549

2650
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/../..)

0 commit comments

Comments
 (0)