Skip to content

Commit 0ca8d22

Browse files
committed
Optionally fetch gflags for BUCK
1 parent d9314de commit 0ca8d22

File tree

8 files changed

+41
-16
lines changed

8 files changed

+41
-16
lines changed

.ci/scripts/unittest-linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ elif [[ "$BUILD_TOOL" == "buck2" ]]; then
3030
# Removing this breaks sccache in the Buck build, apparently
3131
# because TMPDIR gets messed up? Please feel free to fix this and
3232
# speed up this CI job!
33+
CMAKE_ARGS="-DEXECUTORCH_FETCH_GFLAGS_FOR_BUCK=ON" \
3334
PYTHON_EXECUTABLE=python \
3435
.ci/scripts/setup-linux.sh "$@"
3536

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ endif()
697697

698698
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
699699
# Baseline libraries that executor_runner will link against.
700+
FetchContent_gflags()
700701
set(_executor_runner_libs executorch gflags)
701702

702703
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)

third-party/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ if(BUILD_TESTING)
1414
add_subdirectory(googletest)
1515
endif()
1616

17-
FetchContent_gflags()
18-
# Create a symlink from the gflags source directory to third-party/gflags
19-
message(STATUS "Creating a symlink from ${gflags_SOURCE_DIR} to third-party/gflags")
20-
execute_process(
21-
COMMAND ${CMAKE_COMMAND} -E create_symlink "${gflags_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/gflags"
22-
)
17+
if(EXECUTORCH_FETCH_GFLAGS_FOR_BUCK)
18+
FetchContent_gflags()
19+
# Create a symlink from the gflags source directory to third-party/gflags
20+
message(STATUS "Creating a symlink from ${gflags_SOURCE_DIR} to third-party/gflags")
21+
execute_process(
22+
COMMAND ${CMAKE_COMMAND} -E create_symlink "${gflags_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/gflags"
23+
)
24+
endif()
2325

2426
# MARK: - flatbuffers
2527

third-party/gflags.bzl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
load(":gflags_defs.bzl", "gflags_library", "gflags_sources")
33

44
def define_gflags():
5-
(exported_headers, headers, srcs) = gflags_sources(namespace = [
6-
"gflags",
7-
"google",
8-
])
5+
if native.read_config("et_oss", "enable_gflags", "true") == "true":
6+
(exported_headers, headers, srcs) = gflags_sources(namespace = [
7+
"gflags",
8+
"google",
9+
])
10+
else:
11+
(exported_headers, headers, srcs) = ([], [], [])
912

1013
gflags_library(
1114
name = "gflags",

tools/cmake/FetchContent.cmake

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include(FetchContent)
1212
# buck. Unfortunately, FetchContent bakes in generator information in the
1313
# fetched content. Thus, if the generator is changed, it causes build failures.
1414
# So, if the generator has changed, then nuke the content.
15-
function(_refresh_cache_if_necessary DIR)
15+
function(_invalidate_cache_if_generator_mismatch DIR)
1616
set(_generator_stamp_file "${DIR}/.executorch_cmake_generator_stamp")
1717
set(_current_generator "${CMAKE_GENERATOR}")
1818

@@ -24,13 +24,17 @@ function(_refresh_cache_if_necessary DIR)
2424
endif()
2525
endif()
2626

27-
file(WRITE "${_generator_stamp_file}" "${_current_generator}")
2827
endfunction()
2928

29+
# Fetch gflags, and make a symlink to third-party/gflags in the source tree.
30+
# Doing this to satisfy BUCK query for gflags. Also try to invalidate the cmake
31+
# cache if the generator has changed. Notice that symlink won't be created again
32+
# if it's already there.
3033
function(FetchContent_gflags)
31-
if(NOT ${gflags_SOURCE_DIR} STREQUAL "")
32-
_refresh_cache_if_necessary(${gflags_SOURCE_DIR})
33-
endif()
34+
# set(_symlink_target ${CMAKE_CURRENT_LIST_DIR}/../../third-party/gflags)
35+
# if(IS_DIRECTORY ${_symlink_target})
36+
# _invalidate_cache_if_generator_mismatch(${_symlink_target})
37+
# endif()
3438

3539
FetchContent_Declare(
3640
gflags
@@ -39,4 +43,12 @@ function(FetchContent_gflags)
3943
)
4044
set(GFLAGS_INTTYPES_FORMAT C99)
4145
FetchContent_MakeAvailable(gflags)
46+
47+
# if(NOT IS_DIRECTORY ${_symlink_target})
48+
# message(STATUS "Creating a symlink from ${gflags_SOURCE_DIR} to third-party/gflags")
49+
# execute_process(
50+
# COMMAND ${CMAKE_COMMAND} -E create_symlink "${gflags_SOURCE_DIR}" "${_symlink_target}"
51+
# )
52+
# file(WRITE "${_symlink_target}/.executorch_cmake_generator_stamp" "${CMAKE_GENERATOR}")
53+
# endif()
4254
endfunction()

tools/cmake/extract_sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def get_sources(
129129
# If we hit here, setup.py:check_submodule() should have already run
130130
# but it could be that the submodules are not synced or there's local changes.
131131
try:
132-
sources: set[str] = set(runner.run(["cquery", query] + buck_args))
132+
sources: set[str] = set(runner.run(["cquery", "--config", "et_oss.enable_gflags=false", query] + buck_args))
133133
except RuntimeError as e:
134134
logger.error(
135135
f"\033[31;1mFailed to query buck for sources. Failed command:\n\n"

tools/cmake/preset/default.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ define_overridable_option(
209209
"Build the Cortex-M backend"
210210
BOOL OFF
211211
)
212+
define_overridable_option(
213+
EXECUTORCH_FETCH_GFLAGS_FOR_BUCK
214+
"Fetch gflags for BUCK build/test"
215+
BOOL OFF
216+
)
212217
define_overridable_option(
213218
EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER
214219
"Build CoreML executor runner."

tools/cmake/preset/llm.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM ON)
1616
set_overridable_option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED ON)
1717
set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON)
1818
set_overridable_option(EXECUTORCH_BUILD_XNNPACK ON)
19+
set_overridable_option(EXECUTORCH_FETCH_GFLAGS_FOR_BUCK ON)
1920

2021
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2122
set_overridable_option(EXECUTORCH_BUILD_COREML ON)

0 commit comments

Comments
 (0)