Skip to content

Commit

Permalink
Fix arch handling in chip_xcode_build_connector (project-chip#23272)
Browse files Browse the repository at this point in the history
* Set target_cpu and mac_target_arch based on first arch in ARCHS.

This makes Xcode builds for "My Mac" work on M1 Macs. Also set is_debug correctly and tweak some project / scheme settings.

* restyle

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and adbridge committed Nov 18, 2022
1 parent 978797c commit 0c9a7cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
9 changes: 5 additions & 4 deletions src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -571,7 +571,7 @@
isa = PBXNativeTarget;
buildConfigurationList = B20252A12459E34F00F97062 /* Build configuration list for PBXNativeTarget "Matter" */;
buildPhases = (
0C40A67D246C9AC700885C81 /* Run Script */,
0C40A67D246C9AC700885C81 /* Run GN Build (chip_xcode_build_connector) */,
B20252882459E34F00F97062 /* Headers */,
B20252892459E34F00F97062 /* Sources */,
B202528A2459E34F00F97062 /* Frameworks */,
Expand Down Expand Up @@ -659,16 +659,17 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0C40A67D246C9AC700885C81 /* Run Script */ = {
0C40A67D246C9AC700885C81 /* Run GN Build (chip_xcode_build_connector) */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script";
name = "Run GN Build (chip_xcode_build_connector)";
outputFileListPaths = (
);
outputPaths = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B20252952459E34F00F97062"
BuildableName = "MatterTests.xctest"
BlueprintName = "MatterTests"
ReferencedContainer = "container:Matter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
49 changes: 19 additions & 30 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,19 @@ for define in "${defines[@]}"; do
done
target_defines=[${target_defines:1}]

declare target_arch=
declare target_cpu=
case $PLATFORM_PREFERRED_ARCH in
i386)
target_cpu=x86
;;
x86_64)
target_cpu=x64
;;
armv7)
target_cpu=arm
;;
arm64)
target_cpu=arm64
;;
*)
echo >&2
;;
esac

declare target_cflags=""
declare target_cflags=

read -r -a archs <<<"$ARCHS"

for arch in "${archs[@]}"; do
if [ -z "$target_arch"] ]; then
target_arch="$arch"
case "$arch" in
x86_64) target_cpu="x64" ;;
*) target_cpu="$arch" ;;
esac
fi
if [ -n "$target_cflags" ]; then
target_cflags+=','
fi
Expand All @@ -102,14 +91,14 @@ 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'
'target_cpu="'"$target_cpu"'"'
'target_defines='"$target_defines"
'target_cflags=['"$target_cflags"']'
'mac_target_arch="'"$PLATFORM_PREFERRED_ARCH"'"'
'mac_deployment_target="'"$LLVM_TARGET_TRIPLE_OS_VERSION"''"$LLVM_TARGET_TRIPLE_SUFFIX"'"'
"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\""
)

[[ $CONFIGURATION != Debug* ]] && args+='is_debug=true'
[[ $CONFIGURATION == Debug ]] && args+=('is_debug=true')

[[ $PLATFORM_FAMILY_NAME != macOS ]] && {
args+=(
Expand Down Expand Up @@ -142,7 +131,7 @@ find_in_ancestors() {
}

# actual build stuff
(
{
cd "$CHIP_ROOT" # pushd and popd because we need the env vars from activate

if ENV=$(find_in_ancestors chip_xcode_build_connector_env.sh 2>/dev/null); then
Expand All @@ -163,7 +152,7 @@ find_in_ancestors() {
# put build intermediates in TEMP_DIR
cd "$TEMP_DIR"

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

0 comments on commit 0c9a7cc

Please sign in to comment.