Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darwin: Disable static destructors in Matter.framework #32745

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
matrix:
options: # We don't need a full matrix
- flavor: macos-release-availability
arguments: -sdk macosx -configuration Release OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-unguarded-availability-new'
arguments: -sdk macosx -configuration Release WARNING_CFLAGS='${inherited} -Werror -Wconversion -Wno-unguarded-availability-new'
- flavor: ios-release
arguments: -sdk iphoneos -configuration Release OTHER_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
arguments: -sdk iphoneos -configuration Release WARNING_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
- flavor: ios-debug
arguments: -sdk iphoneos -configuration Debug OTHER_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
arguments: -sdk iphoneos -configuration Debug WARNING_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
- flavor: tvos-debug
arguments: -sdk appletvos -configuration Debug OTHER_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
arguments: -sdk appletvos -configuration Debug WARNING_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
- flavor: watchos-debug
arguments: -sdk watchos -configuration Debug OTHER_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
arguments: -sdk watchos -configuration Debug WARNING_CFLAGS='${inherited} -Werror -Wconversion' GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
3 changes: 0 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@
static NSString * const kErrorPairingInit = @"Init failure while creating a pairing delegate";
static NSString * const kErrorPartialDacVerifierInit = @"Init failure while creating a partial DAC verifier";
static NSString * const kErrorPairDevice = @"Failure while pairing the device";
static NSString * const kErrorUnpairDevice = @"Failure while unpairing the device";
static NSString * const kErrorStopPairing = @"Failure while trying to stop the pairing process";
static NSString * const kErrorPreWarmCommissioning = @"Failure while trying to pre-warm the commissioning process";
static NSString * const kErrorOpenPairingWindow = @"Open Pairing Window failed";
static NSString * const kErrorGetPairedDevice = @"Failure while trying to retrieve a paired device";
static NSString * const kErrorNotRunning = @"Controller is not running. Call startup first.";
static NSString * const kInfoStackShutdown = @"Shutting down the Matter Stack";
static NSString * const kErrorSetupCodeGen = @"Generating Manual Pairing Code failed";
static NSString * const kErrorGenerateNOC = @"Generating operational certificate failed";
static NSString * const kErrorKeyAllocation = @"Generating new operational key failed";
Expand Down
8 changes: 8 additions & 0 deletions src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LIBRARY_SEARCH_PATHS = "$(TEMP_DIR)/out/lib";
OTHER_CFLAGS = "-fmacro-prefix-map=$(SRCROOT)/CHIP/=";
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-fno-c++-static-destructors",
);
OTHER_LDFLAGS = "";
"OTHER_LDFLAGS[sdk=*]" = (
"-framework",
Expand Down Expand Up @@ -2429,6 +2433,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LIBRARY_SEARCH_PATHS = "$(TEMP_DIR)/out/lib";
OTHER_CFLAGS = "-fmacro-prefix-map=$(SRCROOT)/CHIP/=";
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-fno-c++-static-destructors",
);
OTHER_LDFLAGS = "";
"OTHER_LDFLAGS[sdk=*]" = (
"-framework",
Expand Down
80 changes: 46 additions & 34 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash -e

#
# Copyright (c) 2020 Project CHIP Authors
Expand Down Expand Up @@ -27,37 +27,51 @@

CHIP_ROOT=$(cd "$(dirname "$0")/../../.." && pwd)

# lotsa debug output :-)
set -ex
function format_gn_str() {
local val="$1"
val="${val//\\/\\\\}" # escape '\'
val="${val//\$/\\\$}" # escape '$'
echo -n "\"${val//\"/\\\"}\"" # escape '"'
}

function format_gn_list() {
local val sep=
echo -n "["
for val in "$@"; do
echo -n "$sep"
format_gn_str "$val"
sep=", "
done
echo "]"
}

# We only have work to do for the `installapi` and `build` phases
[[ "$ACTION" == installhdrs ]] && exit 0

# helpful debugging, save off environment that Xcode gives us, can source it to
# retry/repro failures from a bash terminal
mkdir -p "$TEMP_DIR"
export >"$TEMP_DIR/env.sh"

declare -a defines=()
# lots of environment variables passed by Xcode to this script
read -r -a defines <<<"$GCC_PREPROCESSOR_DEFINITIONS"

declare target_defines=
for define in "${defines[@]}"; do
# For debugging, save off environment that Xcode gives us, can source it to
# retry/repro failures from a bash terminal
#export >"$TEMP_DIR/env.sh"
#set -x

# Forward defines from Xcode (GCC_PREPROCESSOR_DEFINITIONS)
declare -a target_defines=()
read -r -a xcode_defines <<<"$GCC_PREPROCESSOR_DEFINITIONS"
for define in "${xcode_defines[@]}"; do
# skip over those that GN does for us
case "$define" in
CHIP_HAVE_CONFIG_H)
continue
;;
CHIP_HAVE_CONFIG_H) continue ;;
esac
target_defines+=,\"${define//\"/\\\"}\"
target_defines+=("$define")
done
[[ $CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES == YES ]] && {
target_defines+=,\"CHIP_CONFIG_IM_ENABLE_ENCODING_SENTINEL_ENUM_VALUES=1\"
}
target_defines=[${target_defines:1}]

# Forward C/C++ flags (OTHER_C*FLAGS)
declare -a target_cflags=()
read -r -a target_cflags_c <<<"$OTHER_CFLAGS"
read -r -a target_cflags_cc <<<"$OTHER_CPLUSPLUSFLAGS"

# Handle target OS and arch
declare target_arch=
declare target_cpu=
declare target_cflags=
Expand All @@ -72,18 +86,12 @@ for arch in "${archs[@]}"; do
*) target_cpu="$arch" ;;
esac
fi
if [ -n "$target_cflags" ]; then
target_cflags+=','
fi
target_cflags+='"-arch","'"$arch"'"'
target_cflags+=(-arch "$arch")
done

[[ $ENABLE_BITCODE == YES ]] && {
if [ -n "$target_cflags" ]; then
target_cflags+=','
fi
target_cflags+='"-flto"'
}
# Translate other options
[[ $CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES == YES ]] && target_defines+=("CHIP_CONFIG_IM_ENABLE_ENCODING_SENTINEL_ENUM_VALUES=1")
[[ $ENABLE_BITCODE == YES ]] && target_cflags+=("-flto")

declare -a args=(
'default_configs_cosmetic=[]' # suppress colorization
Expand All @@ -98,10 +106,12 @@ declare -a args=(
'chip_disable_platform_kvs=true'
'enable_fuzz_test_targets=false'
"target_cpu=\"$target_cpu\""
"target_defines=$target_defines"
"target_cflags=[$target_cflags]"
"mac_target_arch=\"$target_arch\""
"mac_deployment_target=\"$LLVM_TARGET_TRIPLE_OS_VERSION$LLVM_TARGET_TRIPLE_SUFFIX\""
"target_defines=$(format_gn_list "${target_defines[@]}")"
"target_cflags=$(format_gn_list "${target_cflags[@]}")"
"target_cflags_c=$(format_gn_list "${target_cflags_c[@]}")"
"target_cflags_cc=$(format_gn_list "${target_cflags_cc[@]}")"
)

case "$CONFIGURATION" in
Expand Down Expand Up @@ -197,16 +207,18 @@ find_in_ancestors() {
if [[ -z $CHIP_NO_ACTIVATE ]]; then
# first run bootstrap/activate in an external env to build everything
env -i PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 bash -c '. scripts/activate.sh'
set +ex
# now source activate for env vars
opts="$(set +o)"
set +ex
PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 . scripts/activate.sh
set -ex
eval "$opts"
fi

# put build intermediates in TEMP_DIR
cd "$TEMP_DIR"

# generate and build
set -x
gn --root="$CHIP_ROOT" gen --check out --args="${args[*]}"
exec ninja -v -C out
}
Loading