diff --git a/examples/darwin-framework-tool/BUILD.gn b/examples/darwin-framework-tool/BUILD.gn index 231ebac679b240..c5dc23711d6d0e 100644 --- a/examples/darwin-framework-tool/BUILD.gn +++ b/examples/darwin-framework-tool/BUILD.gn @@ -16,6 +16,7 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") import("${chip_root}/build/chip/tools.gni") +import("${chip_root}/build/config/compiler/compiler.gni") import("${chip_root}/build/config/mac/mac_sdk.gni") import("${chip_root}/examples//chip-tool/chip-tool.gni") @@ -77,6 +78,18 @@ action("build-darwin-framework") { args += [ "--no-ipv4" ] } + if (defined(is_asan) && is_asan) { + args += [ "--asan" ] + } else { + args += [ "--no-asan" ] + } + + if (defined(is_tsan) && is_tsan) { + args += [ "--tsan" ] + } else { + args += [ "--no-tsan" ] + } + output_name = "Matter.framework" outputs = [ "${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}", diff --git a/scripts/build/build_darwin_framework.py b/scripts/build/build_darwin_framework.py index 5b872dbaa891b1..2a7fdc6063b17e 100644 --- a/scripts/build/build_darwin_framework.py +++ b/scripts/build/build_darwin_framework.py @@ -53,11 +53,6 @@ def build_darwin_framework(args): '-derivedDataPath', abs_path, "ARCHS={}".format(args.target_arch), - # For now disable unguarded-availability-new warnings because we - # internally use APIs that we are annotating as only available on - # new enough versions. Maybe we should change out deployment - # target versions instead? - "OTHER_CFLAGS=${inherited} -Wno-unguarded-availability-new", ] if args.target_sdk != "macosx": @@ -75,6 +70,38 @@ def build_darwin_framework(args): command += [ "CHIP_INET_CONFIG_ENABLE_IPV4=NO", ] + + if not args.asan and not args.tsan: + # For now disable unguarded-availability-new warnings because we + # internally use APIs that we are annotating as only available on + # new enough versions. Maybe we should change out deployment + # target versions instead? + command += [ + "OTHER_CFLAGS=${inherited} -Wno-unguarded-availability-new", + ] + + if args.asan: + command += [ + "CHIP_IS_ASAN=YES", + "OTHER_LDFLAGS=${inherited} -fsanitize=address -fno-omit-frame-pointer", + "OTHER_CFLAGS=${inherited} -Wno-unguarded-availability-new -fsanitize=address -fno-omit-frame-pointer", + ] + else: + command += [ + "CHIP_IS_ASAN=NO", + ] + + if args.tsan: + command += [ + "CHIP_IS_TSAN=YES", + "OTHER_LDFLAGS=${inherited} -fsanitize=thread", + "OTHER_CFLAGS=${inherited} -Wno-unguarded-availability-new -fsanitize=thread", + ] + else: + command += [ + "CHIP_IS_TSAN=NO", + ] + command_result = run_command(command) print("Build Framework Result: {}".format(command_result)) @@ -114,6 +141,8 @@ def build_darwin_framework(args): help="Output log file destination", required=True) parser.add_argument('--ipv4', action=argparse.BooleanOptionalAction) + parser.add_argument('--asan', action=argparse.BooleanOptionalAction) + parser.add_argument('--tsan', action=argparse.BooleanOptionalAction) args = parser.parse_args() build_darwin_framework(args) diff --git a/src/darwin/Framework/chip_xcode_build_connector.sh b/src/darwin/Framework/chip_xcode_build_connector.sh index 3843effbc4b52c..b73dcbc194cd67 100755 --- a/src/darwin/Framework/chip_xcode_build_connector.sh +++ b/src/darwin/Framework/chip_xcode_build_connector.sh @@ -123,6 +123,18 @@ declare -a args=( ) } +[[ $CHIP_IS_ASAN == YES ]] && { + args+=( + 'is_asan=true' + ) +} + +[[ $CHIP_IS_TSAN == YES ]] && { + args+=( + 'is_tsan=true' + ) +} + # search current (or $2) and its parent directories until # a name match is found, which is output on stdout find_in_ancestors() {