Skip to content

Commit

Permalink
[darwin] Update the build scripts to not override some user defined s…
Browse files Browse the repository at this point in the history
…ettings (#23008)
  • Loading branch information
vivien-apple authored and pull[bot] committed Feb 22, 2024
1 parent 3ff2dc5 commit 1129922
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 34 deletions.
6 changes: 2 additions & 4 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import("${build_root}/config/compiler/compiler.gni")
import("${build_root}/config/sysroot.gni")
import("${build_root}/config/target.gni")

if (current_os == "mac") {
if (current_os == "mac" || current_os == "ios") {
import("${build_root}/config/mac/mac_sdk.gni")
}

Expand Down Expand Up @@ -49,13 +49,11 @@ config("debug_default") {

config("abi_default") {
cflags = []
if (current_os == "mac") {
if (current_os == "mac" || current_os == "ios") {
cflags += [
"-target",
mac_target_triple,
]
} else if (current_os == "ios") {
# iOS ABI currently set by chip_xcode_build_connector.sh
}

if (current_os != "mac" && current_os != "ios") {
Expand Down
35 changes: 24 additions & 11 deletions build/config/mac/mac_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

_mac_deployment_target = "10.15"

if (current_cpu == "arm64") {
_mac_deployment_target = "11.0"
target_arch = current_cpu
if (current_cpu == "x86") {
target_arch = "i386"
} else if (current_cpu == "x64") {
target_arch = "x86_64"
} else if (current_cpu == "armv7") {
target_arch = "arm"
} else if (current_cpu == "arm64") {
target_arch = "arm64"
}

declare_args() {
# OS X version to target when compiling.
mac_deployment_target = _mac_deployment_target
target_sdk = "macos"
if (current_os != "mac") {
target_sdk = current_os
}

if (current_cpu == "x64") {
mac_target_arch = "x86_64"
deployment_target = "10.15"
if (current_os == "mac") {
if (current_cpu == "arm64") {
deployment_target = "11.0"
}
} else {
mac_target_arch = current_cpu
deployment_target = "13.4"
}

declare_args() {
# SDK version to target when compiling.
mac_deployment_target = target_sdk + deployment_target
}

mac_target_triple = "${mac_target_arch}-apple-macos${mac_deployment_target}"
mac_target_triple = "${target_arch}-apple-${mac_deployment_target}"
4 changes: 3 additions & 1 deletion build_overrides/boringssl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

declare_args() {
# Root directory for BoringSSL
boringssl_root = "//third_party/boringssl/repo"
boringssl_root = "${chip_root}/third_party/boringssl/repo"
}
38 changes: 33 additions & 5 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ if (config_use_interactive_mode) {

assert(chip_build_tools)

declare_args() {
chip_codesign = current_os == "ios"
}

if (current_os == "ios") {
output_sdk_type = "Debug-iphoneos"
} else {
output_sdk_type = "Debug"
}

action("build-darwin-framework") {
script = "${chip_root}/scripts/build/build_darwin_framework.py"

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

output_name = "Matter.framework"
outputs = [
"${root_out_dir}/macos_framework_output/Build/Products/Debug/${output_name}",
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}",
"${root_build_dir}/darwin_framework_build.log",
"${root_out_dir}/macos_framework_output/ModuleCache.noindex/",
"${root_out_dir}/macos_framework_output/Logs",
Expand All @@ -64,11 +74,12 @@ config("config") {
"${chip_root}/zzz_generated/controller-clusters",
"${chip_root}/examples/chip-tool",
"${chip_root}/zzz_generated/chip-tool",
"${root_out_dir}/macos_framework_output/Build/Products/Debug/",
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/",
]

framework_dirs =
[ "${root_out_dir}/macos_framework_output/Build/Products/Debug/" ]
framework_dirs = [
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/",
]

defines = [
"CONFIG_ENABLE_YAML_TESTS=${config_enable_yaml_tests}",
Expand Down Expand Up @@ -139,7 +150,7 @@ executable("darwin-framework-tool") {

ldflags = [
"-rpath",
"@executable_path/macos_framework_output/Build/Products/Debug/",
"@executable_path/macos_framework_output/Build/Products/${output_sdk_type}/",
]

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

output_dir = root_out_dir
}

if (chip_codesign) {
action("codesign") {
script = "entitlements/codesign.py"
public_deps = [ ":darwin-framework-tool" ]

args = [
"--target_path",
rebase_path("${root_build_dir}/darwin-framework-tool", root_build_dir),
"--log_path",
rebase_path("${root_build_dir}/codesign_log.txt", root_build_dir),
]

output_name = "codesign_log.txt"
outputs = [ "${root_build_dir}/${output_name}" ]
}
}
2 changes: 2 additions & 0 deletions examples/darwin-framework-tool/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
import("//build_overrides/chip.gni")

import("${chip_root}/config/standalone/args.gni")

chip_crypto = "boringssl"
5 changes: 1 addition & 4 deletions examples/darwin-framework-tool/entitlements/codesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def get_identity():


def codesign(args):
command = "codesign --force -d --sign {identity} --entitlements {entitlement} {target}".format(
command = "codesign --force -d --sign {identity} {target}".format(
identity=get_identity(),
entitlement=args.entitlements_path,
target=args.target_path)
command_result = run_command(command)

Expand All @@ -59,8 +58,6 @@ def codesign(args):
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Codesign the darwin-framework-tool binary')
parser.add_argument('--entitlements_path', default='entitlements/darwin-framework-tool.entitlements',
help='Set the entitlements for codesign', required=True)
parser.add_argument(
'--log_path', help='Output log file destination', required=True)
parser.add_argument('--target_path', help='Binary to sign', required=True)
Expand Down
14 changes: 12 additions & 2 deletions scripts/build/build_darwin_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,28 @@ def build_darwin_framework(args):
if not os.path.exists(abs_path):
os.mkdir(abs_path)

sdk = 'macosx' if os.environ.get('SDKROOT') == None else os.environ.get('SDKROOT')
arch = platform.machine() if sdk.startswith('macosx') else 'arm64'

command = [
'xcodebuild',
'-scheme',
args.target,
'-sdk',
'macosx',
sdk,
'-project',
args.project_path,
'-derivedDataPath',
abs_path,
"PLATFORM_PREFERRED_ARCH={}".format(platform.machine())
"PLATFORM_PREFERRED_ARCH={}".format(arch),
]

if sdk != "macosx":
command += [
# Build Matter.framework as a static library
"SUPPORTS_TEXT_BASED_API=NO",
"MACH_O_TYPE=staticlib",
]
command_result = run_command(command)

print("Build Framework Result: {}".format(command_result))
Expand Down
6 changes: 4 additions & 2 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ chip_python_wheel_action("chip-core") {
}

if (current_os == "mac") {
py_platform_tag =
"macosx_" + string_replace(mac_deployment_target, ".", "_")
py_platform_tag = string_replace(
string_replace(mac_deployment_target, "macos", "macosx."),
".",
"_")
} else {
py_platform_tag = current_os
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if (chip_crypto == "openssl") {
public_deps = [ ":public_headers" ]
}
} else if (chip_crypto == "boringssl") {
import("//build_overrides/boringssl.gni")
import("${chip_root}/build_overrides/boringssl.gni")

source_set("cryptopal_boringssl") {
# BoringSSL is close enough to OpenSSL that it uses same PAL, with minor #ifdef differences
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/CHIPTool/CHIPTool.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -602,6 +603,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -611,6 +613,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = CHIPToolTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -630,6 +633,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = CHIPToolTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
17 changes: 16 additions & 1 deletion src/darwin/CHIPTool/CHIPTool/CHIPTool.entitlements
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.bluetooth</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.matter.CHIPTool</string>
</array>
</dict>
</plist>
9 changes: 7 additions & 2 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ case $PLATFORM_PREFERRED_ARCH in
;;
esac

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

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

for arch in "${archs[@]}"; do
target_cflags+=',"-arch","'"$arch"'"'
if [ -n "$target_cflags" ]; then
target_cflags+=','
fi
target_cflags+='"-arch","'"$arch"'"'
done

[[ $ENABLE_BITCODE == YES ]] && {
Expand All @@ -96,11 +99,13 @@ declare -a args=(
'chip_crypto="boringssl"'
'chip_build_tools=false'
'chip_build_tests=false'
'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_deployment_target="'"$LLVM_TARGET_TRIPLE_OS_VERSION"''"$LLVM_TARGET_TRIPLE_SUFFIX"'"'
)

[[ $CONFIGURATION != Debug* ]] && args+='is_debug=true'
Expand Down
5 changes: 4 additions & 1 deletion src/pybindings/pycontroller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ pw_python_action("pycontroller") {
}

if (current_os == "mac") {
platform_tag = "macosx_" + string_replace(mac_deployment_target, ".", "_")
platform_tag = string_replace(
string_replace(mac_deployment_target, "macos", "macosx."),
".",
"_")
} else {
platform_tag = current_os
}
Expand Down
2 changes: 2 additions & 0 deletions third_party/boringssl/repo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import("BUILD.generated.gni")
config("boringssl_config") {
include_dirs = [ "src/include" ]

cflags = [ "-Wno-unused-variable" ]

# We want the basic crypto impl with no asm primitives until we hook-up platform-based
# support to the build later.
defines = [ "OPENSSL_NO_ASM=1" ]
Expand Down

0 comments on commit 1129922

Please sign in to comment.