Skip to content

Commit 9b03bfa

Browse files
authored
Revert "Allow compiling against slightly different tensorflow directory layouts. (#21199)"
This reverts commit 3267cbb.
1 parent 6d4893a commit 9b03bfa

File tree

7 files changed

+11
-39
lines changed

7 files changed

+11
-39
lines changed

cmake/modules/FindTensorFlow.cmake

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
include(FindPackageHandleStandardArgs)
55

66
find_path(TF_INCLUDE_DIR
7-
NAMES third_party/tensorflow/c tensorflow/c
7+
NAMES tensorflow/c
88
HINTS ${SWIFT_TENSORFLOW_TARGET_INCLUDE_DIR} /usr/include /usr/local/include)
9-
if (EXISTS ${TF_INCLUDE_DIR}/third_party/tensorflow/c/c_api.h)
10-
# This is experimental and not covered by CI.
11-
set(TF_PATH_ADJUSTMENT "third_party")
12-
else()
13-
# Note: This is the normal workflow.
14-
set(TF_PATH_ADJUSTMENT "")
15-
endif()
169

1710
find_library(TF_LIBRARY
1811
NAMES tensorflow

lib/AST/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ endif()
55

66
if(SWIFT_ENABLE_TENSORFLOW)
77
find_package(TensorFlow REQUIRED)
8-
if (TF_PATH_ADJUSTMENT)
9-
include_directories(BEFORE "${TF_INCLUDE_DIR}/${TF_PATH_ADJUSTMENT}")
10-
endif()
118
include_directories(BEFORE "${TF_INCLUDE_DIR}")
129
endif()
1310

lib/SIL/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
if(SWIFT_ENABLE_TENSORFLOW)
22
find_package(TensorFlow REQUIRED)
3-
if (TF_PATH_ADJUSTMENT)
4-
include_directories(BEFORE "${TF_INCLUDE_DIR}/${TF_PATH_ADJUSTMENT}" )
5-
endif()
63
include_directories(BEFORE "${TF_INCLUDE_DIR}" )
74
endif()
85

lib/SILOptimizer/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
if(SWIFT_ENABLE_TENSORFLOW)
22
find_package(TensorFlow REQUIRED)
3-
if (TF_PATH_ADJUSTMENT)
4-
include_directories(BEFORE "${TF_INCLUDE_DIR}/${TF_PATH_ADJUSTMENT}")
5-
endif()
63
include_directories(BEFORE "${TF_INCLUDE_DIR}")
74
endif()
85

stdlib/public/CTensorFlow/CMakeLists.txt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ include("../../../cmake/modules/SwiftList.cmake")
2323
find_package(TensorFlow REQUIRED)
2424
message(STATUS "Building CTensorFlow.")
2525

26-
if (TF_PATH_ADJUSTMENT)
27-
include_directories(BEFORE "${TF_INCLUDE_DIR}/${TF_PATH_ADJUSTMENT}")
28-
endif()
2926
include_directories(BEFORE "${TF_INCLUDE_DIR}")
3027

3128
# Get target SDKs.
@@ -56,31 +53,20 @@ foreach(sdk ${TARGET_SDKS})
5653

5754
# Copy headers.
5855
macro(copy_tf_headers src dst)
59-
if (TF_PATH_ADJUSTMENT)
60-
set(copy_tf_headers_path_adjustment "${TF_PATH_ADJUSTMENT}/")
61-
else()
62-
set(copy_tf_headers_path_adjustment "")
63-
endif()
6456
add_custom_command(
6557
OUTPUT "${output_dir}/${dst}"
6658
DEPENDS "${src}"
6759
COMMAND
6860
"${SWIFT_SOURCE_DIR}/utils/fix-tf-headers.sh"
6961
"${src}"
70-
"${output_dir}/${dst}"
71-
"${copy_tf_headers_path_adjustment}")
62+
"${output_dir}/${dst}")
7263

7364
list(APPEND outputs "${output_dir}/${dst}")
7465
endmacro(copy_tf_headers)
7566

76-
if (TF_PATH_ADJUSTMENT)
77-
set(adjusted_tf_include_dir "${TF_INCLUDE_DIR}/${TF_PATH_ADJUSTMENT}")
78-
else()
79-
set(adjusted_tf_include_dir "${TF_INCLUDE_DIR}")
80-
endif()
81-
copy_tf_headers("${adjusted_tf_include_dir}/tensorflow/c/c_api.h" c_api.h)
82-
copy_tf_headers("${adjusted_tf_include_dir}/tensorflow/c/c_api_experimental.h" c_api_experimental.h)
83-
copy_tf_headers("${adjusted_tf_include_dir}/tensorflow/c/eager/c_api.h" c_api_eager.h)
67+
copy_tf_headers("${TF_INCLUDE_DIR}/tensorflow/c/c_api.h" c_api.h)
68+
copy_tf_headers("${TF_INCLUDE_DIR}/tensorflow/c/c_api_experimental.h" c_api_experimental.h)
69+
copy_tf_headers("${TF_INCLUDE_DIR}/tensorflow/c/eager/c_api.h" c_api_eager.h)
8470
copy_tf_headers("${CMAKE_CURRENT_SOURCE_DIR}/ctensorflow_init.h" ctensorflow_init.h)
8571

8672
# Put the output dir itself last so that it isn't considered the primary output.

stdlib/public/TensorFlow/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ endif()
2121
find_package(TensorFlow REQUIRED)
2222
message(STATUS "Building TensorFlow.")
2323

24+
include_directories(BEFORE "${TF_INCLUDE_DIR}")
25+
2426
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
2527
set(swift_stdlib_compile_flags "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}")
2628
list(APPEND swift_stdlib_compile_flags "-Xllvm" "-sil-inline-generics")
2729
list(APPEND swift_stdlib_compile_flags "-Xllvm" "-sil-partial-specialization")
2830
list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-sil-ownership")
2931
list(APPEND swift_stdlib_compile_flags "-swift-version" "4")
3032
list(APPEND swift_stdlib_compile_flags "-force-single-frontend-invocation")
33+
list(APPEND swift_stdlib_compile_flags "-Xcc" "-I${TF_INCLUDE_DIR}")
3134
# FIXME(SR-7972): Some tests fail when TensorFlow is optimized.
3235
list(APPEND swift_stdlib_compile_flags "-Onone")
3336

utils/fix-tf-headers.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ set -x
77

88
src="$1"
99
dst="$2"
10-
path_adjustment="$3"
1110

1211
mkdir -p "$(dirname $2)"
1312
cp "$1" "$2"
14-
sed -i -e 's#include "'"$3"'tensorflow/c/c_api.h"#include "c_api.h"#g' "$2"
15-
sed -i -e 's#include "'"$3"'tensorflow/c/c_api_experimental.h"#include "c_api_experimental.h"#g' "$2"
16-
sed -i -e 's#include "'"$3"'tensorflow/c/eager/c_api.h"#include "c_api_eager.h"#g' "$2"
13+
sed -i -e 's#include "tensorflow/c/c_api.h"#include "c_api.h"#g' "$2"
14+
sed -i -e 's#include "tensorflow/c/c_api_experimental.h"#include "c_api_experimental.h"#g' "$2"
15+
sed -i -e 's#include "tensorflow/c/eager/c_api.h"#include "c_api_eager.h"#g' "$2"

0 commit comments

Comments
 (0)