@@ -217,3 +217,127 @@ function(merge_yaml)
217
217
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
218
218
)
219
219
endfunction ()
220
+
221
+ # Append the file list in the variable named `name` in
222
+ # build/build_variables.bzl to the variable named `outputvar` in the
223
+ # caller's scope.
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
+ # Fail the build if the src lists in build_variables.bzl do not match
254
+ # the src lists extracted from Buck and placed into
255
+ # EXECUTORCH_SRCS_FILE. This is intended to be a safety mechanism
256
+ # while we are in the process of removing Buck from the CMake build
257
+ # and replacing it with build_variables.bzl; if you are seeing
258
+ # failures after you have intentionally changed Buck srcs, then simply
259
+ # update build_variables.bzl. If you are seeing failures after
260
+ # changing something about the build system, make sure your changes
261
+ # will work both before and after we finish replacing Buck with
262
+ # build_variables.bzl, which should involve getting these lists to
263
+ # match!
264
+ function (validate_build_variables )
265
+ include (${EXECUTORCH_SRCS_FILE} )
266
+ set (BUILD_VARIABLES_FILELISTS
267
+ EXECUTORCH_SRCS
268
+ EXECUTORCH_CORE_SRCS
269
+ PORTABLE_KERNELS_SRCS
270
+ OPTIMIZED_KERNELS_SRCS
271
+ QUANTIZED_KERNELS_SRCS
272
+ PROGRAM_SCHEMA_SRCS
273
+ OPTIMIZED_CPUBLAS_SRCS
274
+ OPTIMIZED_NATIVE_CPU_OPS_OSS_SRCS
275
+ EXTENSION_DATA_LOADER_SRCS
276
+ EXTENSION_MODULE_SRCS
277
+ EXTENSION_RUNNER_UTIL_SRCS
278
+ EXTENSION_LLM_RUNNER_SRCS
279
+ EXTENSION_TENSOR_SRCS
280
+ EXTENSION_THREADPOOL_SRCS
281
+ EXTENSION_TRAINING_SRCS
282
+ TRAIN_XOR_SRCS
283
+ EXECUTOR_RUNNER_SRCS
284
+ SIZE_TEST_SRCS
285
+ MPS_EXECUTOR_RUNNER_SRCS
286
+ MPS_BACKEND_SRCS
287
+ MPS_SCHEMA_SRCS
288
+ XNN_EXECUTOR_RUNNER_SRCS
289
+ XNNPACK_BACKEND_SRCS
290
+ XNNPACK_SCHEMA_SRCS
291
+ VULKAN_SCHEMA_SRCS
292
+ CUSTOM_OPS_SRCS
293
+ LLAMA_RUNNER_SRCS
294
+ )
295
+ set (BUILD_VARIABLES_VARNAMES
296
+ _executorch__srcs
297
+ _executorch_core__srcs
298
+ _portable_kernels__srcs
299
+ _optimized_kernels__srcs
300
+ _quantized_kernels__srcs
301
+ _program_schema__srcs
302
+ _optimized_cpublas__srcs
303
+ _optimized_native_cpu_ops_oss__srcs
304
+ _extension_data_loader__srcs
305
+ _extension_module__srcs
306
+ _extension_runner_util__srcs
307
+ _extension_llm_runner__srcs
308
+ _extension_tensor__srcs
309
+ _extension_threadpool__srcs
310
+ _extension_training__srcs
311
+ _train_xor__srcs
312
+ _executor_runner__srcs
313
+ _size_test__srcs
314
+ _mps_executor_runner__srcs
315
+ _mps_backend__srcs
316
+ _mps_schema__srcs
317
+ _xnn_executor_runner__srcs
318
+ _xnnpack_backend__srcs
319
+ _xnnpack_schema__srcs
320
+ _vulkan_schema__srcs
321
+ _custom_ops__srcs
322
+ _llama_runner__srcs
323
+ )
324
+ foreach (filelist_and_varname IN ZIP_LISTS BUILD_VARIABLES_FILELISTS
325
+ BUILD_VARIABLES_VARNAMES
326
+ )
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