diff --git a/examples/darwin-framework-tool/BUILD.gn b/examples/darwin-framework-tool/BUILD.gn index 231ebac679b240..67939fcb311f28 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") @@ -31,6 +32,8 @@ declare_args() { # When config_enable_yaml_tests is false, the Matter SDK options are not available. if (!config_enable_yaml_tests) { chip_inet_config_enable_ipv4 = true + chip_config_network_layer_ble = true + is_clang = false } } @@ -73,10 +76,30 @@ action("build-darwin-framework") { ] } - if (defined(chip_inet_config_enable_ipv4) && !chip_inet_config_enable_ipv4) { + if (defined(chip_inet_config_enable_ipv4) && chip_inet_config_enable_ipv4) { + args += [ "--ipv4" ] + } else { args += [ "--no-ipv4" ] } + if (defined(is_asan) && is_asan) { + args += [ "--asan" ] + } else { + args += [ "--no-asan" ] + } + + if (defined(chip_config_network_layer_ble) && chip_config_network_layer_ble) { + args += [ "--ble" ] + } else { + args += [ "--no-ble" ] + } + + if (defined(is_clang) && is_clang) { + args += [ "--clang" ] + } else { + args += [ "--no-clang" ] + } + 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..af7e428c27be07 100644 --- a/scripts/build/build_darwin_framework.py +++ b/scripts/build/build_darwin_framework.py @@ -13,11 +13,22 @@ # See the License for the specific language governing permissions and # limitations under the License. import argparse +import glob import os import platform from subprocess import PIPE, Popen +def get_file_from_pigweed(name): + CHIP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) + PIGWEED = os.path.join(CHIP_ROOT, ".environment/cipd/packages/pigweed") + + pattern = os.path.join(PIGWEED, '**', name) + for filename in glob.glob(pattern, recursive=True): + if os.path.isfile(filename): + return filename + + def run_command(command): returncode = -1 command_log = b'' @@ -53,11 +64,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": @@ -71,12 +77,47 @@ def build_darwin_framework(args): "GCC_SYMBOLS_PRIVATE_EXTERN=NO", ] - if not args.ipv4: + options = { + 'CHIP_INET_CONFIG_ENABLE_IPV4': args.ipv4, + 'CHIP_IS_ASAN': args.asan, + 'CHIP_IS_BLE': args.ble, + 'CHIP_IS_CLANG': args.clang, + } + for option in options: + command += ["{}={}".format(option, "YES" if options[option] else "NO")] + + # 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? + cflags = ["${inherited}", "-Wno-unguarded-availability-new"] + ldflags = ["${inherited}"] + + if args.clang: command += [ - "CHIP_INET_CONFIG_ENABLE_IPV4=NO", + "CC={}".format(get_file_from_pigweed("clang")), + "CXX={}".format(get_file_from_pigweed("clang++")), + "COMPILER_INDEX_STORE_ENABLE=NO", + "CLANG_ENABLE_MODULES=NO", ] - command_result = run_command(command) + ldflags += [ + "-nostdlib++", + get_file_from_pigweed("libc++.a"), + ] + + if args.asan: + flags = ["-fsanitize=address", "-fno-omit-frame-pointer"] + cflags += flags + ldflags += flags + + if args.clang: + ldflags += [ + get_file_from_pigweed("libclang_rt.asan_osx_dynamic.dylib") + ] + + command += ["OTHER_CFLAGS=" + ' '.join(cflags), "OTHER_LDFLAGS=" + ' '.join(ldflags)] + command_result = run_command(command) print("Build Framework Result: {}".format(command_result)) exit(command_result) @@ -114,6 +155,9 @@ 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('--ble', action=argparse.BooleanOptionalAction) + parser.add_argument('--clang', 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..55227ed2b5330f 100755 --- a/src/darwin/Framework/chip_xcode_build_connector.sh +++ b/src/darwin/Framework/chip_xcode_build_connector.sh @@ -95,6 +95,7 @@ declare -a args=( 'chip_enable_wifi=false' 'chip_log_message_max_size=4096' # might as well allow nice long log messages 'chip_disable_platform_kvs=true' + 'enable_fuzz_test_targets=false' "target_cpu=\"$target_cpu\"" "target_defines=$target_defines" "target_cflags=[$target_cflags]" @@ -123,6 +124,24 @@ declare -a args=( ) } +[[ $CHIP_IS_ASAN == YES ]] && { + args+=( + 'is_asan=true' + ) +} + +[[ $CHIP_IS_CLANG == YES ]] && { + args+=( + 'is_clang=true' + ) +} + +[[ $CHIP_IS_BLE == NO ]] && { + args+=( + 'chip_config_network_layer_ble=false' + ) +} + # search current (or $2) and its parent directories until # a name match is found, which is output on stdout find_in_ancestors() {