Skip to content

build: make tensorflow-swift-apis build with older CMake #29973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#
# ----------------------------------------------------------------------------

import os

from . import product
from .. import shell
from .. import targets


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

def build(self, host_target):
shell.call([
self.toolchain.cmake,
'-G', 'Ninja',
'-D', 'BUILD_SHARED_LIBS=YES',
'-D', 'CMAKE_INSTALL_PREFIX={}/usr'.format(
self.args.install_destdir),
'-D', 'CMAKE_MAKE_PROGRAM={}'.format(self.toolchain.ninja),
'-D', 'CMAKE_Swift_COMPILER={}'.format(self.toolchain.swiftc),
'-B', self.build_dir,
'-S', self.source_dir,
])
shell.call([
self.toolchain.cmake,
'--build', self.build_dir,
])
toolchain_path = targets.toolchain_path(self.args.install_destdir,
self.args.install_prefix)
swiftc = os.path.join(toolchain_path, 'usr', 'bin', 'swiftc')

# FIXME: this is a workaround for CMake <3.16 which does not correctly
# generate the build rules if you are not in the build directory. As a
# result, we need to create the build tree before we can use it and
# change into it.
#
# NOTE: unfortunately, we do not know if the build is using Python
# 2.7 or Python 3.2+. In the latter, the `exist_ok` named parameter
# would alleviate some of this issue.
try:
os.makedirs(self.build_dir)
except OSError:
pass

with shell.pushd(self.build_dir):
shell.call([
self.toolchain.cmake,
'-G', 'Ninja',
'-D', 'BUILD_SHARED_LIBS=YES',
'-D', 'CMAKE_INSTALL_PREFIX={}/usr'.format(
self.args.install_destdir),
'-D', 'CMAKE_MAKE_PROGRAM={}'.format(self.toolchain.ninja),
'-D', 'CMAKE_Swift_COMPILER={}'.format(swiftc),
'-B', self.build_dir,
'-S', self.source_dir,
])
shell.call([
self.toolchain.cmake,
'--build', self.build_dir,
])

def should_test(self, host_target):
return False
Expand Down