Skip to content

Commit 0ee8e52

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: dc50258 ghstack-comment-id: 2644414497 Pull Request resolved: #8326
1 parent c99652e commit 0ee8e52

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

@@ -384,6 +385,7 @@ if(NOT EXECUTORCH_SRCS_FILE)
384385
message(STATUS "executorch: Generating source lists")
385386
set(EXECUTORCH_SRCS_FILE "${CMAKE_CURRENT_BINARY_DIR}/executorch_srcs.cmake")
386387
extract_sources(${EXECUTORCH_SRCS_FILE})
388+
validate_build_variables()
387389
endif()
388390

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

0 commit comments

Comments
 (0)