Skip to content

Commit 5d87e43

Browse files
committed
build: improve the PythonKit build
This improves the PythonKit build for CMake <3.16 and for Python 2.7 or Python 3.x.
1 parent f00cf8a commit 5d87e43

File tree

1 file changed

+29
-15
lines changed
  • utils/swift_build_support/swift_build_support/products

1 file changed

+29
-15
lines changed

utils/swift_build_support/swift_build_support/products/pythonkit.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,35 @@ def build(self, host_target):
3434
self.args.install_prefix)
3535
swiftc = os.path.join(toolchain_path, 'usr', 'bin', 'swiftc')
3636

37-
shell.call([
38-
self.toolchain.cmake,
39-
'-G', 'Ninja',
40-
'-D', 'BUILD_SHARED_LIBS=YES',
41-
'-D', 'CMAKE_INSTALL_PREFIX={}/usr'.format(
42-
self.args.install_destdir),
43-
'-D', 'CMAKE_MAKE_PROGRAM={}'.format(self.toolchain.ninja),
44-
'-D', 'CMAKE_Swift_COMPILER={}'.format(swiftc),
45-
'-B', self.build_dir,
46-
'-S', self.source_dir,
47-
])
48-
shell.call([
49-
self.toolchain.cmake,
50-
'--build', self.build_dir,
51-
])
37+
# FIXME: this is a workaround for CMake <3.16 which does not correctly
38+
# generate the build rules if you are not in the build directory. As a
39+
# result, we need to create the build tree before we can use it and
40+
# change into it.
41+
#
42+
# NOTE: unfortunately, we do not know if the build is using Python
43+
# 2.7 or Python 3.2+. In the latter, the `exist_ok` named parameter
44+
# would alleviate some of this issue.
45+
try:
46+
os.makedirs(self.build_dir)
47+
except OSError:
48+
pass
49+
50+
with shell.pushd(self.build_dir):
51+
shell.call([
52+
self.toolchain.cmake,
53+
'-G', 'Ninja',
54+
'-D', 'BUILD_SHARED_LIBS=YES',
55+
'-D', 'CMAKE_INSTALL_PREFIX={}/usr'.format(
56+
self.args.install_destdir),
57+
'-D', 'CMAKE_MAKE_PROGRAM={}'.format(self.toolchain.ninja),
58+
'-D', 'CMAKE_Swift_COMPILER={}'.format(swiftc),
59+
'-B', self.build_dir,
60+
'-S', self.source_dir,
61+
])
62+
shell.call([
63+
self.toolchain.cmake,
64+
'--build', self.build_dir,
65+
])
5266

5367
def should_test(self, host_target):
5468
return self.args.test_pythonkit

0 commit comments

Comments
 (0)