From 08e70dd51effb43f143b96e49e89f3754cded340 Mon Sep 17 00:00:00 2001 From: Dave Bort Date: Mon, 18 Mar 2024 11:05:26 -0700 Subject: [PATCH 1/2] Fix flatcc + pybindings linking on linux (#2467) Summary: On some linux systems, the pybindings build would fail with `relocation R_X86_64_32 against '.rodata' can not be used when making a shared object; recompile with -fPIC` Digging into it further, I also noticed that etdump was depending on `libflatcc` (the compiler) instead of `libflatccrt` (the runtime). Fix that dep, then mark `flatccrt` as positition-independent (thus adding `-fPIC` on appropriate systems) to fix the pybindings build. Reviewed By: larryliu0820 Differential Revision: D54966723 --- CMakeLists.txt | 1 - sdk/CMakeLists.txt | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 778b7886ccf..163c1bc0a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -453,7 +453,6 @@ if(EXECUTORCH_BUILD_PYBIND) etdump executorch extension_data_loader - flatcc portable_ops_lib util torch diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 05df3ba6ded..58a0dc52977 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -53,6 +53,11 @@ endforeach() add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc ${CMAKE_BINARY_DIR}/third-party/flatcc) +# Fix for "relocation R_X86_64_32 against `.rodata' can not be used when making +# a shared object; recompile with -fPIC" when building on some x86 linux +# systems. +set_property(TARGET flatccrt PROPERTY POSITION_INDEPENDENT_CODE ON) + # Assume we are cross-compiling and the CMAKE_TOOLCHAIN_FILE is set include(ExternalProject) @@ -118,7 +123,7 @@ add_library(etdump ${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_flatcc.cpp target_link_libraries( etdump - PUBLIC etdump_schema flatcc + PUBLIC etdump_schema flatccrt PRIVATE executorch) add_custom_command( @@ -148,7 +153,7 @@ target_include_directories( # Install libraries install( - TARGETS bundled_program etdump flatcc + TARGETS bundled_program etdump flatccrt DESTINATION ${CMAKE_BINARY_DIR}/lib INCLUDES DESTINATION ${_common_include_directories}) From 98736c6711fcb7d39571f9b806a3ae36b42eca97 Mon Sep 17 00:00:00 2001 From: Dave Bort Date: Mon, 18 Mar 2024 11:05:26 -0700 Subject: [PATCH 2/2] Don't build unnecessary flatbuffers/flatcc targets (#2466) Summary: We're currently building unnecessary pieces of the flatbuffers and flatcc submodules. I had tried disabling them before for flatbuffers, but didn't do it the right way. Now do it the right way, saving us some time during the build. Differential Revision: D54966722 --- CMakeLists.txt | 10 +++++----- sdk/CMakeLists.txt | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 163c1bc0a8a..43aadfcc9d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,11 +236,11 @@ if(EXECUTORCH_BUILD_FLATC) ) endif() set(FLATC_EXECUTABLE flatc) - option(FLATBUFFERS_BUILD_FLATC "" ON) - option(FLATBUFFERS_BUILD_FLATHASH "" OFF) - option(FLATBUFFERS_BUILD_FLATLIB "" OFF) - option(FLATBUFFERS_BUILD_TESTS "" OFF) - option(FLATBUFFERS_INSTALL "" OFF) + set(FLATBUFFERS_BUILD_FLATC ON CACHE BOOL "") + set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "") + set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "") + set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "") + set(FLATBUFFERS_INSTALL OFF CACHE BOOL "") add_subdirectory(third-party/flatbuffers) endif() if(NOT FLATC_EXECUTABLE) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 58a0dc52977..af43434ca29 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -50,6 +50,8 @@ foreach(schema_file ${_bundled_input_schema_names}) "${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema/${schema_file}") endforeach() +set(FLATCC_TEST OFF CACHE BOOL "") +set(FLATCC_REFLECTION OFF CACHE BOOL "") add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc ${CMAKE_BINARY_DIR}/third-party/flatcc) @@ -72,6 +74,7 @@ ExternalProject_Add( PREFIX ${CMAKE_BINARY_DIR}/_host_build SOURCE_DIR ${CMAKE_SOURCE_DIR}/third-party/flatcc BINARY_DIR ${CMAKE_BINARY_DIR}/_host_build + CMAKE_CACHE_ARGS -DFLATCC_TEST:BOOL=OFF -DFLATCC_REFLECTION:BOOL=OFF INSTALL_COMMAND "" # Prevent the install step, modify as needed )