Skip to content

Commit 1bae8b3

Browse files
committed
[darwin] Allow build setting to override the target-arch
1 parent 2c9cd92 commit 1bae8b3

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

build/config/mac/mac_sdk.gni

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ if (current_cpu == "x86") {
1717
target_arch = "i386"
1818
} else if (current_cpu == "x64") {
1919
target_arch = "x86_64"
20-
} else if (current_cpu == "armv7") {
21-
target_arch = "arm"
20+
} else if (current_cpu == "arm") {
21+
target_arch = "armv7"
2222
} else if (current_cpu == "arm64") {
2323
target_arch = "arm64"
2424
}
@@ -40,6 +40,7 @@ if (current_os == "mac") {
4040
declare_args() {
4141
# SDK version to target when compiling.
4242
mac_deployment_target = target_sdk + deployment_target
43+
mac_target_arch = target_arch
4344
}
4445

45-
mac_target_triple = "${target_arch}-apple-${mac_deployment_target}"
46+
mac_target_triple = "${mac_target_arch}-apple-${mac_deployment_target}"

examples/darwin-framework-tool/BUILD.gn

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
1717

1818
import("${chip_root}/build/chip/tools.gni")
19+
import("${chip_root}/build/config/mac/mac_sdk.gni")
1920
import("${chip_root}/examples//chip-tool/chip-tool.gni")
2021

2122
if (config_use_interactive_mode) {
@@ -28,8 +29,10 @@ declare_args() {
2829
chip_codesign = current_os == "ios"
2930
}
3031

32+
sdk = "macosx"
3133
sdk_build_dir_suffix = ""
3234
if (getenv("SDKROOT") != "") {
35+
sdk = getenv("SDKROOT")
3336
sdk_root_parts = string_split(getenv("SDKROOT"), ".")
3437
sdk_build_dir_suffix = "-${sdk_root_parts[0]}"
3538
}
@@ -56,6 +59,15 @@ action("build-darwin-framework") {
5659
rebase_path("${root_build_dir}/darwin_framework_build.log", root_build_dir),
5760
]
5861

62+
if (sdk != "macosx") {
63+
args += [
64+
"--target_sdk",
65+
sdk,
66+
"--target_arch",
67+
mac_target_arch,
68+
]
69+
}
70+
5971
output_name = "Matter.framework"
6072
outputs = [
6173
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}",

scripts/build/build_darwin_framework.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,17 @@ def build_darwin_framework(args):
4242
if not os.path.exists(abs_path):
4343
os.mkdir(abs_path)
4444

45-
sdk = 'macosx' if os.environ.get('SDKROOT') == None else os.environ.get('SDKROOT')
46-
arch = platform.machine() if sdk.startswith('macosx') else 'arm64'
47-
4845
command = [
4946
'xcodebuild',
5047
'-scheme',
5148
args.target,
5249
'-sdk',
53-
sdk,
50+
args.target_sdk,
5451
'-project',
5552
args.project_path,
5653
'-derivedDataPath',
5754
abs_path,
58-
"PLATFORM_PREFERRED_ARCH={}".format(arch),
55+
"PLATFORM_PREFERRED_ARCH={}".format(args.target_arch),
5956
]
6057

6158
if sdk != "macosx":
@@ -89,6 +86,16 @@ def build_darwin_framework(args):
8986
default="Matter",
9087
help="Name of target to build",
9188
required=True)
89+
parser.add_argument("--target_sdk",
90+
default="macosx",
91+
help="Set the target sdk",
92+
required=False,
93+
)
94+
parser.add_argument("--target_arch",
95+
default=platform.machine(),
96+
help="Set the target architecture",
97+
required=False,
98+
)
9299
parser.add_argument("--log_path",
93100
help="Output log file destination",
94101
required=True)

src/darwin/Framework/chip_xcode_build_connector.sh

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ declare -a args=(
105105
'target_cpu="'"$target_cpu"'"'
106106
'target_defines='"$target_defines"
107107
'target_cflags=['"$target_cflags"']'
108+
'mac_target_arch="'"$PLATFORM_PREFERRED_ARCH"'"'
108109
'mac_deployment_target="'"$LLVM_TARGET_TRIPLE_OS_VERSION"''"$LLVM_TARGET_TRIPLE_SUFFIX"'"'
109110
)
110111

0 commit comments

Comments
 (0)