Skip to content

Commit 8f5b757

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: 397ff68 ghstack-comment-id: 2644414497 Pull Request resolved: #8326
1 parent 9e669a4 commit 8f5b757

File tree

3 files changed

+579
-0
lines changed

3 files changed

+579
-0
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

@@ -391,6 +392,7 @@ if(NOT EXECUTORCH_SRCS_FILE)
391392
message(STATUS "executorch: Generating source lists")
392393
set(EXECUTORCH_SRCS_FILE "${CMAKE_CURRENT_BINARY_DIR}/executorch_srcs.cmake")
393394
extract_sources(${EXECUTORCH_SRCS_FILE})
395+
validate_build_variables()
394396
endif()
395397

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

build/Codegen.cmake

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,113 @@ function(merge_yaml)
218218
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
219219
)
220220
endfunction()
221+
222+
function(append_filelist name outputvar)
223+
# configure_file adds its input to the list of CMAKE_RERUN dependencies
224+
configure_file(
225+
${PROJECT_SOURCE_DIR}/build/build_variables.bzl
226+
${PROJECT_BINARY_DIR}/build_variables.bzl COPYONLY
227+
)
228+
execute_process(
229+
COMMAND
230+
"${PYTHON_EXECUTABLE}" -c
231+
"exec(open('${PROJECT_SOURCE_DIR}/build/build_variables.bzl').read());print(';'.join(${name}))"
232+
WORKING_DIRECTORY "${_rootdir}"
233+
RESULT_VARIABLE _retval
234+
OUTPUT_VARIABLE _tempvar
235+
ERROR_VARIABLE _stderr
236+
)
237+
if(NOT _retval EQUAL 0)
238+
message(
239+
FATAL_ERROR
240+
"Failed to fetch filelist ${name} from build_variables.bzl with output ${_tempvar} and stderr ${_stderr}"
241+
)
242+
endif()
243+
string(REPLACE "\n" "" _tempvar "${_tempvar}")
244+
list(APPEND ${outputvar} ${_tempvar})
245+
set(${outputvar}
246+
"${${outputvar}}"
247+
PARENT_SCOPE
248+
)
249+
endfunction()
250+
251+
function(validate_build_variables)
252+
include(${EXECUTORCH_SRCS_FILE})
253+
set(BUILD_VARIABLES_FILELISTS
254+
EXECUTORCH_SRCS
255+
EXECUTORCH_CORE_SRCS
256+
PORTABLE_KERNELS_SRCS
257+
OPTIMIZED_KERNELS_SRCS
258+
QUANTIZED_KERNELS_SRCS
259+
PROGRAM_SCHEMA_SRCS
260+
OPTIMIZED_CPUBLAS_SRCS
261+
OPTIMIZED_NATIVE_CPU_OPS_OSS_SRCS
262+
EXTENSION_DATA_LOADER_SRCS
263+
EXTENSION_MODULE_SRCS
264+
EXTENSION_RUNNER_UTIL_SRCS
265+
EXTENSION_LLM_RUNNER_SRCS
266+
EXTENSION_TENSOR_SRCS
267+
EXTENSION_THREADPOOL_SRCS
268+
EXTENSION_TRAINING_SRCS
269+
TRAIN_XOR_SRCS
270+
EXECUTOR_RUNNER_SRCS
271+
SIZE_TEST_SRCS
272+
MPS_EXECUTOR_RUNNER_SRCS
273+
MPS_BACKEND_SRCS
274+
MPS_SCHEMA_SRCS
275+
XNN_EXECUTOR_RUNNER_SRCS
276+
XNNPACK_BACKEND_SRCS
277+
XNNPACK_SCHEMA_SRCS
278+
VULKAN_SCHEMA_SRCS
279+
CUSTOM_OPS_SRCS
280+
LLAMA_RUNNER_SRCS
281+
)
282+
set(BUILD_VARIABLES_VARNAMES
283+
_executorch__srcs
284+
_executorch_core__srcs
285+
_portable_kernels__srcs
286+
_optimized_kernels__srcs
287+
_quantized_kernels__srcs
288+
_program_schema__srcs
289+
_optimized_cpublas__srcs
290+
_optimized_native_cpu_ops_oss__srcs
291+
_extension_data_loader__srcs
292+
_extension_module__srcs
293+
_extension_runner_util__srcs
294+
_extension_llm_runner__srcs
295+
_extension_tensor__srcs
296+
_extension_threadpool__srcs
297+
_extension_training__srcs
298+
_train_xor__srcs
299+
_executor_runner__srcs
300+
_size_test__srcs
301+
_mps_executor_runner__srcs
302+
_mps_backend__srcs
303+
_mps_schema__srcs
304+
_xnn_executor_runner__srcs
305+
_xnnpack_backend__srcs
306+
_xnnpack_schema__srcs
307+
_vulkan_schema__srcs
308+
_custom_ops__srcs
309+
_llama_runner__srcs
310+
)
311+
foreach(filelist_and_varname IN ZIP_LISTS BUILD_VARIABLES_FILELISTS
312+
BUILD_VARIABLES_VARNAMES
313+
)
314+
append_filelist(
315+
${filelist_and_varname_0}
316+
"${filelist_and_varname_1}_from_build_variables"
317+
)
318+
if(NOT ${filelist_and_varname_1} STREQUAL
319+
${filelist_and_varname_1}_from_build_variables
320+
)
321+
message(
322+
FATAL_ERROR
323+
"Buck-generated ${filelist_and_varname_1} does not match hardcoded \
324+
${filelist_and_varname_0} in build_variables.bzl. Left: \
325+
${${filelist_and_varname_1}}\n \
326+
Right: ${${filelist_and_varname_1}_from_build_variables}"
327+
)
328+
endif()
329+
endforeach()
330+
endfunction()

0 commit comments

Comments
 (0)