Skip to content

Commit 814414c

Browse files
huydhnfacebook-github-bot
authored andcommitted
Add macos_kernel_link_options for MacOS (#70)
Summary: This addresses the linker issue on MacOS `ld: unknown option: --whole-archive` Pull Request resolved: #70 Reviewed By: larryliu0820 Differential Revision: D48411148 Pulled By: huydhn fbshipit-source-id: 7e8839dbf698c8290d4989f2ec00464659f700a2
1 parent 9581086 commit 814414c

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ target_link_libraries(portable_kernels_bindings INTERFACE portable_kernels)
259259

260260
# Ensure that the load-time constructor functions run. By default, the linker
261261
# would remove them since there are no other references to them.
262-
kernel_link_options(portable_kernels_bindings)
262+
if(APPLE)
263+
macos_kernel_link_options(portable_kernels_bindings)
264+
else()
265+
kernel_link_options(portable_kernels_bindings)
266+
endif()
263267

264268
#
265269
# executor_runner: A simple commandline tool that loads and runs a program file.

build/Utils.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ function(kernel_link_options target_name)
3232
-Wl,--no-whole-archive
3333
)
3434
endfunction()
35+
36+
function(macos_kernel_link_options target_name)
37+
target_link_options(${target_name}
38+
INTERFACE
39+
# Same as kernel_link_options but it's for MacOS linker
40+
-Wl,-force_load,$<TARGET_FILE:${target_name}>
41+
)
42+
endfunction()

examples/custom_ops/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ if(REGISTER_EXAMPLE_CUSTOM_OP_2)
110110

111111
# Ensure that the load-time constructor functions run. By default, the linker
112112
# would remove them since there are no other references to them.
113-
kernel_link_options("custom_ops_aot_lib")
113+
if(APPLE)
114+
macos_kernel_link_options("custom_ops_aot_lib")
115+
else()
116+
kernel_link_options("custom_ops_aot_lib")
117+
endif()
114118
endif()
115119

116120
# 1. C++ library to register custom ops into Executorch runtime.

0 commit comments

Comments
 (0)