Skip to content

Commit 1e886e2

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: 8fe94f4 ghstack-comment-id: 2644414497 Pull Request resolved: #8326
1 parent 421a316 commit 1e886e2

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

0 commit comments

Comments
 (0)