10
10
#
11
11
# ----------------------------------------------------------------------------
12
12
13
+ import os
14
+
13
15
from . import product
14
16
from .. import shell
17
+ from .. import targets
15
18
16
19
17
20
class TensorFlowSwiftAPIs (product .Product ):
@@ -27,21 +30,39 @@ def should_build(self, host_target):
27
30
return self .args .build_tensorflow_swift_apis
28
31
29
32
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
+ ])
45
66
46
67
def should_test (self , host_target ):
47
68
return False
0 commit comments