Skip to content

Commit 0951961

Browse files
Feature/so versioning (#482)
* Removed DPCLSyclInterface library from MANIFEST.in Manifest is meant for source distributions, and binary libraries does not belong there. Added custom build_py step to copy shared object library from install/ to build_lib folder (build/lib.cpython-..../dpctl) Added custom post-build step to install command to remove hard links of versioned shared object library on linux, and recopy them from build_lib to installation folder. * Reenabled so-versioning now that setup.py has been tweaked to handle symlinks
1 parent 76680ff commit 0951961

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ include dpctl/_sycl_queue.h
77
include dpctl/_sycl_queue_manager.h
88
include dpctl/_sycl_event.h
99
include dpctl/memory/_memory.h
10-
include dpctl/*DPCTL*Interface.*
1110
include dpctl/tests/input_files/*

dpctl-capi/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,24 @@ target_link_libraries(DPCTLSyclInterface
151151
PRIVATE ${IntelSycl_OPENCL_LIBRARY}
152152
)
153153

154+
include(GetProjectVersion)
155+
# the get_version function is defined in the GetProjectVersion module and
156+
# defines: VERSION, SEMVER, MAJOR, MINOR, PATCH. These variables are populated
157+
# by parsing the output of git describe.
158+
get_version()
159+
set_target_properties(DPCTLSyclInterface
160+
PROPERTIES
161+
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}
162+
SOVERSION ${VERSION_MAJOR}
163+
)
164+
154165
if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
155166
target_include_directories(DPCTLSyclInterface
156167
PRIVATE
157168
${LEVEL_ZERO_INCLUDE_DIR}
158169
)
159170
endif()
160171

161-
# FIXME: Turning off for release until conda build can be packaging symbolic links
162-
# NOTE: Till we hit 1.0.0 we will keep using the MINOR version to set the API
163-
# version of the library.
164-
# include(GetProjectVersion)
165-
# the get_version function is defined in the GetProjectVersion module and
166-
# defines: VERSION, SEMVER, MAJOR, MINOR, PATCH. These variables are populated
167-
# by parsing the output of git describe.
168-
# get_version()
169-
# set_target_properties(DPCTLSyclInterface PROPERTIES VERSION ${VERSION_MINOR})
170-
# set_target_properties(DPCTLSyclInterface PROPERTIES SOVERSION 1)
171-
172172
install(TARGETS
173173
DPCTLSyclInterface
174174
LIBRARY

setup.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import glob
1718
import os
1819
import os.path
20+
import shutil
1921
import sys
2022

2123
import numpy as np
2224
import setuptools.command.build_ext as orig_build_ext
25+
import setuptools.command.build_py as orig_build_py
2326
import setuptools.command.develop as orig_develop
2427
import setuptools.command.install as orig_install
2528
from Cython.Build import cythonize
@@ -251,6 +254,34 @@ def run(self):
251254
return super().run()
252255

253256

257+
class build_py(orig_build_py.build_py):
258+
def run(self):
259+
dpctl_src_dir = self.get_package_dir("dpctl")
260+
dpctl_build_dir = os.path.join(self.build_lib, "dpctl")
261+
os.makedirs(dpctl_build_dir, exist_ok=True)
262+
if IS_LIN:
263+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.so*")):
264+
# Check if the file already exists before copying. The check is
265+
# needed when dealing with symlinks.
266+
if not os.path.exists(
267+
os.path.join(dpctl_build_dir, os.path.basename(fn))
268+
):
269+
shutil.copy(
270+
src=fn,
271+
dst=dpctl_build_dir,
272+
follow_symlinks=False,
273+
)
274+
elif IS_WIN:
275+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.lib")):
276+
shutil.copy(src=fn, dst=dpctl_build_dir)
277+
278+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.dll")):
279+
shutil.copy(src=fn, dst=dpctl_build_dir)
280+
else:
281+
raise NotImplementedError("Unsupported platform")
282+
return super().run()
283+
284+
254285
class install(orig_install.install):
255286
description = "Installs dpctl into Python prefix"
256287
user_options = orig_install.install.user_options + [
@@ -308,7 +339,22 @@ def run(self):
308339
else:
309340
self.define = ",".join((pre_d, "CYTHON_TRACE"))
310341
cythonize(self.distribution.ext_modules)
311-
return super().run()
342+
ret = super().run()
343+
if IS_LIN:
344+
dpctl_build_dir = os.path.join(
345+
os.path.dirname(__file__), self.build_lib, "dpctl"
346+
)
347+
dpctl_install_dir = os.path.join(self.install_libbase, "dpctl")
348+
for fn in glob.glob(
349+
os.path.join(dpctl_install_dir, "*DPCTLSyclInterface.so*")
350+
):
351+
os.remove(fn)
352+
shutil.copy(
353+
src=os.path.join(dpctl_build_dir, os.path.basename(fn)),
354+
dst=dpctl_install_dir,
355+
follow_symlinks=False,
356+
)
357+
return ret
312358

313359

314360
class develop(orig_develop.develop):
@@ -393,6 +439,7 @@ def _get_cmdclass():
393439
cmdclass["install"] = install
394440
cmdclass["develop"] = develop
395441
cmdclass["build_ext"] = build_ext
442+
cmdclass["build_py"] = build_py
396443
return cmdclass
397444

398445

0 commit comments

Comments
 (0)