Skip to content

Commit 7301ecf

Browse files
authored
[darwin] Update the build scripts to not override some user defined settings (project-chip#23008)
1 parent 7455a55 commit 7301ecf

File tree

14 files changed

+115
-34
lines changed

14 files changed

+115
-34
lines changed

build/config/compiler/BUILD.gn

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import("${build_root}/config/compiler/compiler.gni")
1919
import("${build_root}/config/sysroot.gni")
2020
import("${build_root}/config/target.gni")
2121

22-
if (current_os == "mac") {
22+
if (current_os == "mac" || current_os == "ios") {
2323
import("${build_root}/config/mac/mac_sdk.gni")
2424
}
2525

@@ -49,13 +49,11 @@ config("debug_default") {
4949

5050
config("abi_default") {
5151
cflags = []
52-
if (current_os == "mac") {
52+
if (current_os == "mac" || current_os == "ios") {
5353
cflags += [
5454
"-target",
5555
mac_target_triple,
5656
]
57-
} else if (current_os == "ios") {
58-
# iOS ABI currently set by chip_xcode_build_connector.sh
5957
}
6058

6159
if (current_os != "mac" && current_os != "ios") {

build/config/mac/mac_sdk.gni

+24-11
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
_mac_deployment_target = "10.15"
16-
17-
if (current_cpu == "arm64") {
18-
_mac_deployment_target = "11.0"
15+
target_arch = current_cpu
16+
if (current_cpu == "x86") {
17+
target_arch = "i386"
18+
} else if (current_cpu == "x64") {
19+
target_arch = "x86_64"
20+
} else if (current_cpu == "armv7") {
21+
target_arch = "arm"
22+
} else if (current_cpu == "arm64") {
23+
target_arch = "arm64"
1924
}
2025

21-
declare_args() {
22-
# OS X version to target when compiling.
23-
mac_deployment_target = _mac_deployment_target
26+
target_sdk = "macos"
27+
if (current_os != "mac") {
28+
target_sdk = current_os
2429
}
2530

26-
if (current_cpu == "x64") {
27-
mac_target_arch = "x86_64"
31+
deployment_target = "10.15"
32+
if (current_os == "mac") {
33+
if (current_cpu == "arm64") {
34+
deployment_target = "11.0"
35+
}
2836
} else {
29-
mac_target_arch = current_cpu
37+
deployment_target = "13.4"
38+
}
39+
40+
declare_args() {
41+
# SDK version to target when compiling.
42+
mac_deployment_target = target_sdk + deployment_target
3043
}
3144

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

build_overrides/boringssl.gni

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import("//build_overrides/chip.gni")
17+
1618
declare_args() {
1719
# Root directory for BoringSSL
18-
boringssl_root = "//third_party/boringssl/repo"
20+
boringssl_root = "${chip_root}/third_party/boringssl/repo"
1921
}

examples/darwin-framework-tool/BUILD.gn

+33-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ if (config_use_interactive_mode) {
2424

2525
assert(chip_build_tools)
2626

27+
declare_args() {
28+
chip_codesign = current_os == "ios"
29+
}
30+
31+
if (current_os == "ios") {
32+
output_sdk_type = "Debug-iphoneos"
33+
} else {
34+
output_sdk_type = "Debug"
35+
}
36+
2737
action("build-darwin-framework") {
2838
script = "${chip_root}/scripts/build/build_darwin_framework.py"
2939

@@ -47,7 +57,7 @@ action("build-darwin-framework") {
4757

4858
output_name = "Matter.framework"
4959
outputs = [
50-
"${root_out_dir}/macos_framework_output/Build/Products/Debug/${output_name}",
60+
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}",
5161
"${root_build_dir}/darwin_framework_build.log",
5262
"${root_out_dir}/macos_framework_output/ModuleCache.noindex/",
5363
"${root_out_dir}/macos_framework_output/Logs",
@@ -64,11 +74,12 @@ config("config") {
6474
"${chip_root}/zzz_generated/controller-clusters",
6575
"${chip_root}/examples/chip-tool",
6676
"${chip_root}/zzz_generated/chip-tool",
67-
"${root_out_dir}/macos_framework_output/Build/Products/Debug/",
77+
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/",
6878
]
6979

70-
framework_dirs =
71-
[ "${root_out_dir}/macos_framework_output/Build/Products/Debug/" ]
80+
framework_dirs = [
81+
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/",
82+
]
7283

7384
defines = [
7485
"CONFIG_ENABLE_YAML_TESTS=${config_enable_yaml_tests}",
@@ -139,7 +150,7 @@ executable("darwin-framework-tool") {
139150

140151
ldflags = [
141152
"-rpath",
142-
"@executable_path/macos_framework_output/Build/Products/Debug/",
153+
"@executable_path/macos_framework_output/Build/Products/${output_sdk_type}/",
143154
]
144155

145156
frameworks = [
@@ -151,3 +162,20 @@ executable("darwin-framework-tool") {
151162

152163
output_dir = root_out_dir
153164
}
165+
166+
if (chip_codesign) {
167+
action("codesign") {
168+
script = "entitlements/codesign.py"
169+
public_deps = [ ":darwin-framework-tool" ]
170+
171+
args = [
172+
"--target_path",
173+
rebase_path("${root_build_dir}/darwin-framework-tool", root_build_dir),
174+
"--log_path",
175+
rebase_path("${root_build_dir}/codesign_log.txt", root_build_dir),
176+
]
177+
178+
output_name = "codesign_log.txt"
179+
outputs = [ "${root_build_dir}/${output_name}" ]
180+
}
181+
}

examples/darwin-framework-tool/args.gni

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
import("//build_overrides/chip.gni")
1616

1717
import("${chip_root}/config/standalone/args.gni")
18+
19+
chip_crypto = "boringssl"

examples/darwin-framework-tool/entitlements/codesign.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ def get_identity():
4545

4646

4747
def codesign(args):
48-
command = "codesign --force -d --sign {identity} --entitlements {entitlement} {target}".format(
48+
command = "codesign --force -d --sign {identity} {target}".format(
4949
identity=get_identity(),
50-
entitlement=args.entitlements_path,
5150
target=args.target_path)
5251
command_result = run_command(command)
5352

@@ -59,8 +58,6 @@ def codesign(args):
5958
if __name__ == '__main__':
6059
parser = argparse.ArgumentParser(
6160
description='Codesign the darwin-framework-tool binary')
62-
parser.add_argument('--entitlements_path', default='entitlements/darwin-framework-tool.entitlements',
63-
help='Set the entitlements for codesign', required=True)
6461
parser.add_argument(
6562
'--log_path', help='Output log file destination', required=True)
6663
parser.add_argument('--target_path', help='Binary to sign', required=True)

scripts/build/build_darwin_framework.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,28 @@ 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+
4548
command = [
4649
'xcodebuild',
4750
'-scheme',
4851
args.target,
4952
'-sdk',
50-
'macosx',
53+
sdk,
5154
'-project',
5255
args.project_path,
5356
'-derivedDataPath',
5457
abs_path,
55-
"PLATFORM_PREFERRED_ARCH={}".format(platform.machine())
58+
"PLATFORM_PREFERRED_ARCH={}".format(arch),
5659
]
60+
61+
if sdk != "macosx":
62+
command += [
63+
# Build Matter.framework as a static library
64+
"SUPPORTS_TEXT_BASED_API=NO",
65+
"MACH_O_TYPE=staticlib",
66+
]
5767
command_result = run_command(command)
5868

5969
print("Build Framework Result: {}".format(command_result))

src/controller/python/BUILD.gn

+4-2
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,10 @@ chip_python_wheel_action("chip-core") {
314314
}
315315

316316
if (current_os == "mac") {
317-
py_platform_tag =
318-
"macosx_" + string_replace(mac_deployment_target, ".", "_")
317+
py_platform_tag = string_replace(
318+
string_replace(mac_deployment_target, "macos", "macosx."),
319+
".",
320+
"_")
319321
} else {
320322
py_platform_tag = current_os
321323
}

src/crypto/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ if (chip_crypto == "openssl") {
9292
public_deps = [ ":public_headers" ]
9393
}
9494
} else if (chip_crypto == "boringssl") {
95-
import("//build_overrides/boringssl.gni")
95+
import("${chip_root}/build_overrides/boringssl.gni")
9696

9797
source_set("cryptopal_boringssl") {
9898
# BoringSSL is close enough to OpenSSL that it uses same PAL, with minor #ifdef differences

src/darwin/CHIPTool/CHIPTool.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@
579579
PRODUCT_NAME = "$(TARGET_NAME)";
580580
PROVISIONING_PROFILE_SPECIFIER = "";
581581
SDKROOT = iphoneos;
582+
SUPPORTS_MACCATALYST = YES;
582583
TARGETED_DEVICE_FAMILY = "1,2";
583584
};
584585
name = Debug;
@@ -602,6 +603,7 @@
602603
PRODUCT_NAME = "$(TARGET_NAME)";
603604
PROVISIONING_PROFILE_SPECIFIER = "";
604605
SDKROOT = iphoneos;
606+
SUPPORTS_MACCATALYST = YES;
605607
TARGETED_DEVICE_FAMILY = "1,2";
606608
};
607609
name = Release;
@@ -611,6 +613,7 @@
611613
buildSettings = {
612614
BUNDLE_LOADER = "$(TEST_HOST)";
613615
CODE_SIGN_STYLE = Automatic;
616+
DEVELOPMENT_TEAM = "";
614617
INFOPLIST_FILE = CHIPToolTests/Info.plist;
615618
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
616619
LD_RUNPATH_SEARCH_PATHS = (
@@ -630,6 +633,7 @@
630633
buildSettings = {
631634
BUNDLE_LOADER = "$(TEST_HOST)";
632635
CODE_SIGN_STYLE = Automatic;
636+
DEVELOPMENT_TEAM = "";
633637
INFOPLIST_FILE = CHIPToolTests/Info.plist;
634638
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
635639
LD_RUNPATH_SEARCH_PATHS = (
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict/>
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.device.bluetooth</key>
8+
<true/>
9+
<key>com.apple.security.device.camera</key>
10+
<true/>
11+
<key>com.apple.security.network.client</key>
12+
<true/>
13+
<key>com.apple.security.network.server</key>
14+
<true/>
15+
<key>keychain-access-groups</key>
16+
<array>
17+
<string>$(AppIdentifierPrefix)com.matter.CHIPTool</string>
18+
</array>
19+
</dict>
520
</plist>

src/darwin/Framework/chip_xcode_build_connector.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ case $PLATFORM_PREFERRED_ARCH in
7979
;;
8080
esac
8181

82-
declare target_cflags='"-target","'"$PLATFORM_PREFERRED_ARCH"'-'"$LLVM_TARGET_TRIPLE_VENDOR"'-'"$LLVM_TARGET_TRIPLE_OS_VERSION"'"'
82+
declare target_cflags=""
8383

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

8686
for arch in "${archs[@]}"; do
87-
target_cflags+=',"-arch","'"$arch"'"'
87+
if [ -n "$target_cflags" ]; then
88+
target_cflags+=','
89+
fi
90+
target_cflags+='"-arch","'"$arch"'"'
8891
done
8992

9093
[[ $ENABLE_BITCODE == YES ]] && {
@@ -96,11 +99,13 @@ declare -a args=(
9699
'chip_crypto="boringssl"'
97100
'chip_build_tools=false'
98101
'chip_build_tests=false'
102+
'chip_enable_wifi=false'
99103
'chip_log_message_max_size=4096' # might as well allow nice long log messages
100104
'chip_disable_platform_kvs=true'
101105
'target_cpu="'"$target_cpu"'"'
102106
'target_defines='"$target_defines"
103107
'target_cflags=['"$target_cflags"']'
108+
'mac_deployment_target="'"$LLVM_TARGET_TRIPLE_OS_VERSION"''"$LLVM_TARGET_TRIPLE_SUFFIX"'"'
104109
)
105110

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

src/pybindings/pycontroller/BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ pw_python_action("pycontroller") {
132132
}
133133

134134
if (current_os == "mac") {
135-
platform_tag = "macosx_" + string_replace(mac_deployment_target, ".", "_")
135+
platform_tag = string_replace(
136+
string_replace(mac_deployment_target, "macos", "macosx."),
137+
".",
138+
"_")
136139
} else {
137140
platform_tag = current_os
138141
}

third_party/boringssl/repo/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import("BUILD.generated.gni")
1717
config("boringssl_config") {
1818
include_dirs = [ "src/include" ]
1919

20+
cflags = [ "-Wno-unused-variable" ]
21+
2022
# We want the basic crypto impl with no asm primitives until we hook-up platform-based
2123
# support to the build later.
2224
defines = [ "OPENSSL_NO_ASM=1" ]

0 commit comments

Comments
 (0)