Skip to content

Commit 91c7906

Browse files
authored
Merge pull request #29973 from compnerd/tensorflow-build
build: make tensorflow-swift-apis build with older CMake
2 parents 428a08d + ac6e34c commit 91c7906

File tree

1 file changed

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

1 file changed

+36
-15
lines changed

utils/swift_build_support/swift_build_support/products/tensorflow.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
import os
14+
1315
from . import product
1416
from .. import shell
17+
from .. import targets
1518

1619

1720
class TensorFlowSwiftAPIs(product.Product):
@@ -27,21 +30,39 @@ def should_build(self, host_target):
2730
return self.args.build_tensorflow_swift_apis
2831

2932
def build(self, host_target):
30-
shell.call([
31-
self.toolchain.cmake,
32-
'-G', 'Ninja',
33-
'-D', 'BUILD_SHARED_LIBS=YES',
34-
'-D', 'CMAKE_INSTALL_PREFIX={}/usr'.format(
35-
self.args.install_destdir),
36-
'-D', 'CMAKE_MAKE_PROGRAM={}'.format(self.toolchain.ninja),
37-
'-D', 'CMAKE_Swift_COMPILER={}'.format(self.toolchain.swiftc),
38-
'-B', self.build_dir,
39-
'-S', self.source_dir,
40-
])
41-
shell.call([
42-
self.toolchain.cmake,
43-
'--build', self.build_dir,
44-
])
33+
toolchain_path = targets.toolchain_path(self.args.install_destdir,
34+
self.args.install_prefix)
35+
swiftc = os.path.join(toolchain_path, 'usr', 'bin', 'swiftc')
36+
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+
])
4566

4667
def should_test(self, host_target):
4768
return False

0 commit comments

Comments
 (0)