| 
1 | 1 | load("@fbsource//xplat/executorch/build:build_variables.bzl", "PROGRAM_NO_PRIM_OPS_SRCS")  | 
2 | 2 | load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_aten_mode_options", "runtime")  | 
3 | 3 | 
 
  | 
 | 4 | +def program_verification_enabled():  | 
 | 5 | +    return native.read_config("executorch", "enable_program_verification", "true") == "true"  | 
 | 6 | + | 
 | 7 | +def logging_enabled():  | 
 | 8 | +    return native.read_config("executorch", "enable_logging", "true") == "true"  | 
 | 9 | + | 
4 | 10 | def _program_preprocessor_flags():  | 
5 | 11 |     """Returns the preprocessor_flags to use when building Program.cpp"""  | 
6 | 12 | 
 
  | 
7 | 13 |     # The code for flatbuffer verification can add ~30k of .text to the binary.  | 
8 | 14 |     # It's a valuable feature, but make it optional for space-constrained  | 
9 | 15 |     # systems.  | 
10 |  | -    enable_verification = native.read_config(  | 
11 |  | -        "executorch",  | 
12 |  | -        "enable_program_verification",  | 
13 |  | -        # Default value  | 
14 |  | -        "true",  | 
15 |  | -    )  | 
16 |  | -    if enable_verification == "false":  | 
17 |  | -        return ["-DET_ENABLE_PROGRAM_VERIFICATION=0"]  | 
18 |  | -    elif enable_verification == "true":  | 
19 |  | -        # Enabled by default.  | 
20 |  | -        return []  | 
 | 16 | +    flags = []  | 
 | 17 | +      | 
 | 18 | +    if runtime.is_oss:  | 
 | 19 | +        # OSS builds only check the native.read_config  | 
 | 20 | +        if not program_verification_enabled():  | 
 | 21 | +            flags.append("-DET_ENABLE_PROGRAM_VERIFICATION=0")  | 
 | 22 | +        if not logging_enabled():  | 
 | 23 | +            flags.append("-DET_LOG_ENABLED=0")  | 
 | 24 | +        return flags  | 
21 | 25 |     else:  | 
22 |  | -        fail("executorch.enable_program_verification must be one of 'true' or 'false'; saw '" +  | 
23 |  | -             enable_verification + "'")  | 
 | 26 | +        # Non-OSS builds: constraint takes priority, then check config in DEFAULT case  | 
 | 27 | +        flags += select({  | 
 | 28 | +            "DEFAULT": ["-DET_ENABLE_PROGRAM_VERIFICATION=0"] if not program_verification_enabled() else [],  | 
 | 29 | +            "fbsource//xplat/executorch/tools/buck/constraints:executorch-program-verification-disabled": ["-DET_ENABLE_PROGRAM_VERIFICATION=0"]  | 
 | 30 | +        })  | 
 | 31 | +        flags += select({  | 
 | 32 | +            "DEFAULT": ["-DET_LOG_ENABLED=0"] if not logging_enabled() else [],  | 
 | 33 | +            "fbsource//xplat/executorch/tools/buck/constraints:executorch-logs-disabled": ["-DET_LOG_ENABLED=0"]  | 
 | 34 | +        })  | 
 | 35 | +    return flags  | 
24 | 36 | 
 
  | 
25 | 37 | def define_common_targets():  | 
26 | 38 |     """Defines targets that should be shared between fbcode and xplat.  | 
 | 
0 commit comments