Skip to content

Commit

Permalink
[darwin-framework-tool] Add is_asan proper supports (#26014)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 12, 2023
1 parent 6d4f3f9 commit 10e0e0a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
25 changes: 24 additions & 1 deletion examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
}
}

Expand Down Expand Up @@ -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}",
Expand Down
60 changes: 52 additions & 8 deletions scripts/build/build_darwin_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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''
Expand Down Expand Up @@ -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":
Expand All @@ -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)

Expand Down Expand Up @@ -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)
19 changes: 19 additions & 0 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 10e0e0a

Please sign in to comment.