File tree Expand file tree Collapse file tree 4 files changed +39
-7
lines changed Expand file tree Collapse file tree 4 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ export MACOSX_DEPLOYMENT_TARGET=15.0
77
88${CONDA_RUN} pip install --upgrade pip
99
10- ${CONDA_RUN} conda install conda-forge::rust -y
1110# for orjson
1211export UNSAFE_PYO3_BUILD_FREE_THREADED=1
1312
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ if "%CONDA_RUN%"=="" (
77
88:: Run the pip install command
99%CONDA_RUN% conda install conda-forge::pybind11 -y
10- %CONDA_RUN% conda install conda-forge::rust -y
1110
1211:: Check if the installation was successful
1312if errorlevel 1 (
Original file line number Diff line number Diff line change @@ -36,13 +36,16 @@ else()
3636 )
3737endif ()
3838
39+ find_package (Python COMPONENTS Development.Static )
40+ target_link_libraries (_C ${Python_STATIC_LIBRARIES} )
41+
3942target_include_directories (_C PRIVATE ${PROJECT_SOURCE_DIR} )
4043
41- if (APPLE OR WIN32 ) # Check if the target OS is OSX/macOS
42- target_link_libraries (_C PRIVATE pybind11::module)
43- else ()
44- target_link_libraries (_C PRIVATE Python3::Python pybind11::module)
45- endif ()
44+ # if(APPLE OR WIN32) # Check if the target OS is OSX/macOS
45+ target_link_libraries (_C PRIVATE pybind11::module)
46+ # else()
47+ # target_link_libraries(_C PRIVATE Python3::Python pybind11::module)
48+ # endif()
4649
4750if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
4851 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fsanitize=address" )
Original file line number Diff line number Diff line change 22#
33# This source code is licensed under the MIT license found in the
44# LICENSE file in the root directory of this source tree.
5+ import subprocess
6+ import sys
7+ from pathlib import Path
8+
9+ _IS_LINUX = sys .platform .startswith ("linux" )
510
611
712def test_imports_deps ():
@@ -23,6 +28,32 @@ def test_imports():
2328 print ("version" , tensordict .__version__ ) # noqa
2429
2530
31+ def test_static_linking ():
32+ if not _IS_LINUX :
33+ return
34+ # Locate _C.so
35+ try :
36+ import tensordict ._C
37+ except ImportError as e :
38+ raise RuntimeError (f"Failed to import tensordict._C: { e } " )
39+ # Get the path to _C.so
40+ _C_path = Path (tensordict ._C .__file__ )
41+ if not _C_path .exists ():
42+ raise RuntimeError (f"_C.so not found at { _C_path } " )
43+ # Run ldd on _C.so
44+ try :
45+ output = subprocess .check_output (["ldd" , str (_C_path )]).decode ("utf-8" )
46+ except subprocess .CalledProcessError as e :
47+ raise RuntimeError (f"Failed to run ldd on { _C_path } : { e } " )
48+ # Check if libpython is dynamically linked
49+ for line in output .splitlines ():
50+ if "libpython" in line and "=>" in line and "not found" not in line :
51+ raise RuntimeError (
52+ f"tensordict/_C.so is dynamically linked against { line .strip ()} "
53+ )
54+ print ("Test passed: tensordict/_C.so does not show dynamic linkage to libpython." ) # noqa
55+
56+
2657if __name__ == "__main__" :
2758 test_imports_deps ()
2859 test_imports ()
You can’t perform that action at this time.
0 commit comments