Skip to content

Commit 4c2222e

Browse files
committed
ENH: Add option to exclude libs from repaired module wheel on Windows
Allow users to exclude libraries the module depends on, but which should not be part of the wheel. e.g. The CUDA Driver library.
1 parent eb1cd68 commit 4c2222e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/windows_build_module_wheels.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,36 @@ def rename_wheel_init(py_env, filepath):
107107
check_call([python_executable, "-m", "wheel", "pack", wheel_dir, "-d", dist_dir])
108108
shutil.rmtree(wheel_dir)
109109

110-
def fixup_wheel(py_envs, filepath, lib_paths:str=''):
110+
def fixup_wheel(py_envs, filepath, lib_paths:str='', exclude_libs:str=''):
111111
lib_paths = ';'.join(["C:/P/IPP/oneTBB-prefix/bin",lib_paths.strip()]).strip(';')
112112
print(f'Library paths for fixup: {lib_paths}')
113113

114114
py_env = py_envs[0]
115115

116116
delve_wheel = os.path.join(ROOT_DIR, "venv-" + py_env, "Scripts", "delvewheel.exe")
117117
check_call([delve_wheel, "repair", "--no-mangle-all", "--add-path",
118-
lib_paths, "--ignore-in-wheel", "-w",
118+
lib_paths, "--no-dll", exclude_libs, "--ignore-in-wheel", "-w",
119119
os.path.join(ROOT_DIR, "dist"), filepath])
120120

121121
# The delve_wheel patch loading shared libraries is added to the module
122122
# __init__ file. Rename this file here to prevent conflicts on installation.
123123
# The renamed __init__ file will be executed when loading ITK.
124124
rename_wheel_init(py_env, filepath)
125125

126-
def fixup_wheels(py_envs, lib_paths:str=''):
126+
def fixup_wheels(py_envs, lib_paths:str='', exclude_libs:str=''):
127127
# shared library fix-up
128128
for wheel in glob.glob(os.path.join(ROOT_DIR, "dist", "*.whl")):
129-
fixup_wheel(py_envs, wheel, lib_paths)
129+
fixup_wheel(py_envs, wheel, lib_paths, exclude_libs)
130130

131131
if __name__ == '__main__':
132132
parser = argparse.ArgumentParser(description='Driver script to build ITK Python module wheels.')
133133
parser.add_argument('--py-envs', nargs='+', default=DEFAULT_PY_ENVS,
134134
help='Target Python environment versions, e.g. "37-x64".')
135135
parser.add_argument('--no-cleanup', dest='cleanup', action='store_false', help='Do not clean up temporary build files.')
136136
parser.add_argument('--lib-paths', nargs=1, default='', help='Add semicolon-delimited library directories for delvewheel to include in the module wheel')
137+
parser.add_argument('--exclude-libs', nargs=1, default='', help='Add semicolon-delimited library names that must not be included in the module wheel, e.g. "nvcuda.dll"')
137138
parser.add_argument('cmake_options', nargs='*', help='Extra options to pass to CMake, e.g. -DBUILD_SHARED_LIBS:BOOL=OFF')
138139
args = parser.parse_args()
139140

140141
build_wheels(cleanup=args.cleanup, py_envs=args.py_envs, cmake_options=args.cmake_options)
141-
fixup_wheels(args.py_envs, ';'.join(args.lib_paths))
142+
fixup_wheels(args.py_envs, ';'.join(args.lib_paths), ';'.join(args.exclude_libs))

0 commit comments

Comments
 (0)