Skip to content

Commit 7b5e280

Browse files
committed
create and validate build_variables.bzl
First step of #8268 -- we are moving from buck-extracted filelist to using one shared filelist, and the first step is to create the shared filelist and validate it against the buck generation. ghstack-source-id: c4195ce ghstack-comment-id: 2644414497 Pull Request resolved: #8326
1 parent ac81c88 commit 7b5e280

File tree

3 files changed

+625
-2
lines changed

3 files changed

+625
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
cmake_minimum_required(VERSION 3.19)
4646
project(executorch)
47+
include(build/Codegen.cmake)
4748
include(build/Utils.cmake)
4849
include(CMakeDependentOption)
4950

@@ -401,6 +402,7 @@ if(NOT EXECUTORCH_SRCS_FILE)
401402
message(STATUS "executorch: Generating source lists")
402403
set(EXECUTORCH_SRCS_FILE "${CMAKE_CURRENT_BINARY_DIR}/executorch_srcs.cmake")
403404
extract_sources(${EXECUTORCH_SRCS_FILE})
405+
validate_build_variables()
404406
endif()
405407

406408
# This file defines the `_<target>__srcs` variables used below.

build/Codegen.cmake

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Selective build. See codegen/tools/gen_oplist.py for how to use these
1111
# arguments.
12-
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
12+
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)
1313

1414
function(gen_selected_ops)
1515
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS)
@@ -97,7 +97,7 @@ function(generate_bindings_for_kernels)
9797
--tags-path=${site-packages-out}/torchgen/packaged/ATen/native/tags.yaml
9898
--aten-yaml-path=${site-packages-out}/torchgen/packaged/ATen/native/native_functions.yaml
9999
--op-selection-yaml-path=${_oplist_yaml}
100-
)
100+
)
101101
if(GEN_ADD_EXCEPTION_BOUNDARY)
102102
set(_gen_command "${_gen_command}" --add-exception-boundary)
103103
endif()
@@ -217,3 +217,127 @@ function(merge_yaml)
217217
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
218218
)
219219
endfunction()
220+
221+
# Append the file list in the variable named `name` in build/build_variables.bzl
222+
# to the variable named `outputvar` in the caller's scope.
223+
function(append_filelist name outputvar)
224+
# configure_file adds its input to the list of CMAKE_RERUN dependencies
225+
configure_file(
226+
${PROJECT_SOURCE_DIR}/shim_et/xplat/executorch/build/build_variables.bzl
227+
${PROJECT_BINARY_DIR}/build_variables.bzl COPYONLY
228+
)
229+
execute_process(
230+
COMMAND
231+
"${PYTHON_EXECUTABLE}" -c
232+
"exec(open('${PROJECT_SOURCE_DIR}/shim_et/xplat/executorch/build/build_variables.bzl').read());print(';'.join(${name}))"
233+
WORKING_DIRECTORY "${_rootdir}"
234+
RESULT_VARIABLE _retval
235+
OUTPUT_VARIABLE _tempvar
236+
ERROR_VARIABLE _stderr
237+
)
238+
if(NOT _retval EQUAL 0)
239+
message(
240+
FATAL_ERROR
241+
"Failed to fetch filelist ${name} from build_variables.bzl with output ${_tempvar} and stderr ${_stderr}"
242+
)
243+
endif()
244+
string(REPLACE "\n" "" _tempvar "${_tempvar}")
245+
list(APPEND ${outputvar} ${_tempvar})
246+
set(${outputvar}
247+
"${${outputvar}}"
248+
PARENT_SCOPE
249+
)
250+
endfunction()
251+
252+
# Fail the build if the src lists in build_variables.bzl do not match the src
253+
# lists extracted from Buck and placed into EXECUTORCH_SRCS_FILE. This is
254+
# intended to be a safety mechanism while we are in the process of removing Buck
255+
# from the CMake build and replacing it with build_variables.bzl; if you are
256+
# seeing failures after you have intentionally changed Buck srcs, then simply
257+
# update build_variables.bzl. If you are seeing failures after changing
258+
# something about the build system, make sure your changes will work both before
259+
# and after we finish replacing Buck with build_variables.bzl, which should
260+
# involve getting these lists to match!
261+
function(validate_build_variables)
262+
include(${EXECUTORCH_SRCS_FILE})
263+
set(BUILD_VARIABLES_FILELISTS
264+
EXECUTORCH_SRCS
265+
EXECUTORCH_CORE_SRCS
266+
PORTABLE_KERNELS_SRCS
267+
OPTIMIZED_KERNELS_SRCS
268+
QUANTIZED_KERNELS_SRCS
269+
PROGRAM_SCHEMA_SRCS
270+
OPTIMIZED_CPUBLAS_SRCS
271+
OPTIMIZED_NATIVE_CPU_OPS_SRCS
272+
EXTENSION_DATA_LOADER_SRCS
273+
EXTENSION_MODULE_SRCS
274+
EXTENSION_RUNNER_UTIL_SRCS
275+
EXTENSION_LLM_RUNNER_SRCS
276+
EXTENSION_TENSOR_SRCS
277+
EXTENSION_THREADPOOL_SRCS
278+
EXTENSION_TRAINING_SRCS
279+
TRAIN_XOR_SRCS
280+
EXECUTOR_RUNNER_SRCS
281+
SIZE_TEST_SRCS
282+
MPS_EXECUTOR_RUNNER_SRCS
283+
MPS_BACKEND_SRCS
284+
MPS_SCHEMA_SRCS
285+
XNN_EXECUTOR_RUNNER_SRCS
286+
XNNPACK_BACKEND_SRCS
287+
XNNPACK_SCHEMA_SRCS
288+
VULKAN_SCHEMA_SRCS
289+
CUSTOM_OPS_SRCS
290+
LLAMA_RUNNER_SRCS
291+
)
292+
set(BUILD_VARIABLES_VARNAMES
293+
_executorch__srcs
294+
_executorch_core__srcs
295+
_portable_kernels__srcs
296+
_optimized_kernels__srcs
297+
_quantized_kernels__srcs
298+
_program_schema__srcs
299+
_optimized_cpublas__srcs
300+
_optimized_native_cpu_ops__srcs
301+
_extension_data_loader__srcs
302+
_extension_module__srcs
303+
_extension_runner_util__srcs
304+
_extension_llm_runner__srcs
305+
_extension_tensor__srcs
306+
_extension_threadpool__srcs
307+
_extension_training__srcs
308+
_train_xor__srcs
309+
_executor_runner__srcs
310+
_size_test__srcs
311+
_mps_executor_runner__srcs
312+
_mps_backend__srcs
313+
_mps_schema__srcs
314+
_xnn_executor_runner__srcs
315+
_xnnpack_backend__srcs
316+
_xnnpack_schema__srcs
317+
_vulkan_schema__srcs
318+
_custom_ops__srcs
319+
_llama_runner__srcs
320+
)
321+
foreach(filelist_and_varname IN ZIP_LISTS BUILD_VARIABLES_FILELISTS
322+
BUILD_VARIABLES_VARNAMES
323+
)
324+
if("${filelist_and_varname_1}" STREQUAL "_custom_ops__srcs")
325+
continue()
326+
endif()
327+
append_filelist(
328+
${filelist_and_varname_0}
329+
"${filelist_and_varname_1}_from_build_variables"
330+
)
331+
if(NOT ${filelist_and_varname_1} STREQUAL
332+
${filelist_and_varname_1}_from_build_variables
333+
)
334+
message(
335+
FATAL_ERROR
336+
"Buck-generated ${filelist_and_varname_1} does not match hardcoded "
337+
"${filelist_and_varname_0} in build_variables.bzl. Left: "
338+
"${${filelist_and_varname_1}}\n "
339+
"Right: ${${filelist_and_varname_1}_from_build_variables}"
340+
)
341+
endif()
342+
endforeach()
343+
endfunction()

0 commit comments

Comments
 (0)