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] Allow build setting to override the target-arch #23177

Merged
merged 1 commit into from
Oct 18, 2022
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
7 changes: 4 additions & 3 deletions build/config/mac/mac_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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 == "arm") {
target_arch = "armv7"
} else if (current_cpu == "arm64") {
target_arch = "arm64"
}
Expand All @@ -40,6 +40,7 @@ if (current_os == "mac") {
declare_args() {
# SDK version to target when compiling.
mac_deployment_target = target_sdk + deployment_target
mac_target_arch = target_arch
}

mac_target_triple = "${target_arch}-apple-${mac_deployment_target}"
mac_target_triple = "${mac_target_arch}-apple-${mac_deployment_target}"
12 changes: 12 additions & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

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

if (config_use_interactive_mode) {
Expand All @@ -28,8 +29,10 @@ declare_args() {
chip_codesign = current_os == "ios"
}

sdk = "macosx"
sdk_build_dir_suffix = ""
if (getenv("SDKROOT") != "") {
sdk = getenv("SDKROOT")
sdk_root_parts = string_split(getenv("SDKROOT"), ".")
sdk_build_dir_suffix = "-${sdk_root_parts[0]}"
}
Expand All @@ -56,6 +59,15 @@ action("build-darwin-framework") {
rebase_path("${root_build_dir}/darwin_framework_build.log", root_build_dir),
]

if (sdk != "macosx") {
args += [
"--target_sdk",
sdk,
"--target_arch",
mac_target_arch,
]
}

output_name = "Matter.framework"
outputs = [
"${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}",
Expand Down
19 changes: 13 additions & 6 deletions scripts/build/build_darwin_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,20 @@ 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',
sdk,
args.target_sdk,
'-project',
args.project_path,
'-derivedDataPath',
abs_path,
"PLATFORM_PREFERRED_ARCH={}".format(arch),
"PLATFORM_PREFERRED_ARCH={}".format(args.target_arch),
]

if sdk != "macosx":
if args.target_sdk != "macosx":
command += [
# Build Matter.framework as a static library
"SUPPORTS_TEXT_BASED_API=NO",
Expand Down Expand Up @@ -89,6 +86,16 @@ def build_darwin_framework(args):
default="Matter",
help="Name of target to build",
required=True)
parser.add_argument("--target_sdk",
default="macosx",
help="Set the target sdk",
required=False,
)
parser.add_argument("--target_arch",
default=platform.machine(),
help="Set the target architecture",
required=False,
)
parser.add_argument("--log_path",
help="Output log file destination",
required=True)
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/chip_xcode_build_connector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ declare -a args=(
'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"'"'
)

Expand Down