Skip to content

Commit

Permalink
Add patch file for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
asus4 committed Sep 5, 2023
1 parent e961ab5 commit da42195
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 28 additions & 0 deletions Scripts/macos-v2.13.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git forkSrcPrefix/tensorflow/lite/build_def.bzl forkDstPrefix/tensorflow/lite/build_def.bzl
index 842879a053652363a0e328407d295c551c869702..a952a3b5cbbaa8025c5a93d10e6f1ce1308285b1 100644
--- forkSrcPrefix/tensorflow/lite/build_def.bzl
+++ forkDstPrefix/tensorflow/lite/build_def.bzl
@@ -150,8 +150,11 @@ def tflite_linkopts_no_undefined():
"""
return if_oss(
select({
+ # macOS/iOS linker uses "--undefined error" instead of "--no-undefined".
"//tensorflow:ios": [
- # iOS linker uses "--undefined error" instead of "--no-undefined".
+ "-Wl,-undefined,error",
+ ],
+ "//tensorflow:macos": [
"-Wl,-undefined,error",
],
"//conditions:default": ["-Wl,--no-undefined"],
@@ -165,7 +168,9 @@ def tflite_linkopts_no_undefined():
"//tools/cpp:msan_build": [],
"//tools/cpp:tsan_build": [],
"//tensorflow:ios": [
- # iOS linker uses "--undefined error" instead of "--no-undefined".
+ "-Wl,-undefined,error",
+ ],
+ "//tensorflow:macos": [
"-Wl,-undefined,error",
],
"//conditions:default": ["-Wl,--no-undefined"],
8 changes: 3 additions & 5 deletions build_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def patch(file_path, target_str, patched_str):
def build_mac(enable_xnnpack = True):
# Workaround for macOS build error
# https://github.com/tensorflow/tensorflow/pull/60771
run_cmd(f'git fetch --depth=1 origin 4869e557d603b211ca7d0b4640ee9aac08b48565')
run_cmd(f'git cherry-pick 4869e557d603b211ca7d0b4640ee9aac08b48565 --no-commit')
patch_file = os.path.abspath('Scripts/macos-v2.13.0.patch')
run_cmd(f'git apply {patch_file}')

# Main
option_xnnpack = 'true' if enable_xnnpack else 'false'
run_cmd(f'bazel build --config=macos --cpu=darwin -c opt --define tflite_with_xnnpack={option_xnnpack} tensorflow/lite/c:tensorflowlite_c')
Expand All @@ -62,8 +62,6 @@ def build_mac(enable_xnnpack = True):
run_cmd(f'lipo -create -output {PLUGIN_PATH}/macOS/libtensorflowlite_metal_delegate.dylib ' + ' '.join(metal_delegate_pathes))
# Restore patch
patch(cpuinfo_file, patched, original)
# Restore workaround
run_cmd('git reset --hard')

def build_windows(enable_xnnpack = True):
# Main
Expand Down

0 comments on commit da42195

Please sign in to comment.