From ccde4167e0b150bbbb43f0e566c0986d1bbce484 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 13 Sep 2024 16:43:00 -0700 Subject: [PATCH 1/2] [executorch] Add android-arm64 execution platform in shim & plumb it to extract_sources.py We need to tell Buck when we're building for Android, otherwise it will use the host configuration. Differential Revision: [D62671809](https://our.internmc.facebook.com/intern/diff/D62671809/) [ghstack-poisoned] --- build/Utils.cmake | 9 ++++++++- build/extract_sources.py | 22 ++++++++++++++++++---- shim/BUCK | 10 ++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/build/Utils.cmake b/build/Utils.cmake index d9811c8313e..ce7315e5b39 100644 --- a/build/Utils.cmake +++ b/build/Utils.cmake @@ -184,11 +184,18 @@ function(extract_sources sources_file) set(executorch_root ${CMAKE_CURRENT_SOURCE_DIR}) endif() + if(ANDROID_ABI) + if(STREQUAL "${ANDROID_ABI}" "arm64-v8a") + set(target_platforms_arg "--target_platforms=shim//:android-arm64") + else() + message(FATAL_ERROR "Unsupported ANDROID_ABI setting ${ANDROID_ABI}. Please add it here!") + endif() + endif() execute_process( COMMAND ${PYTHON_EXECUTABLE} ${executorch_root}/build/extract_sources.py --config=${executorch_root}/build/cmake_deps.toml --out=${sources_file} - --buck2=${BUCK2} + --buck2=${BUCK2} ${target_platforms_arg} OUTPUT_VARIABLE gen_srcs_output ERROR_VARIABLE gen_srcs_error RESULT_VARIABLE gen_srcs_exit_code diff --git a/build/extract_sources.py b/build/extract_sources.py index ce8b3de9812..a2b8156db46 100755 --- a/build/extract_sources.py +++ b/build/extract_sources.py @@ -11,7 +11,7 @@ import re from enum import Enum -from typing import Any, Optional, Sequence +from typing import Any, List, Optional, Sequence from buck_util import Buck2Runner @@ -96,7 +96,12 @@ def __init__( else: self._config[k] = v - def get_sources(self, graph: "Graph", runner: Buck2Runner) -> frozenset[str]: + def get_sources( + self, graph: "Graph", runner: Buck2Runner, buck_args: Optional[List[str]] + ) -> frozenset[str]: + if buck_args is None: + buck_args = [] + if self._state == Target._InitState.READY: return self._sources # Detect cycles. @@ -113,7 +118,7 @@ def get_sources(self, graph: "Graph", runner: Buck2Runner) -> frozenset[str]: ) # Get the complete list of source files that this target depends on. - sources: set[str] = set(runner.run(["cquery", query])) + sources: set[str] = set(runner.run(["cquery", query] + buck_args)) # Keep entries that match all of the filters. filters = [re.compile(p) for p in self._config.get("filters", [])] @@ -128,7 +133,9 @@ def get_sources(self, graph: "Graph", runner: Buck2Runner) -> frozenset[str]: # its deps. Remove entries that are already covered by the transitive # set of dependencies. for dep in self._config.get("deps", []): - sources.difference_update(graph.by_name[dep].get_sources(graph, runner)) + sources.difference_update( + graph.by_name[dep].get_sources(graph, runner, buck_args) + ) self._sources = frozenset(sources) self._state = Target._InitState.READY @@ -173,6 +180,9 @@ def parse_args() -> argparse.Namespace: metavar="file", help="Path to the file to generate.", ) + parser.add_argument( + "--target-platforms", help="--target-platforms to pass to buck cquery, if any." + ) return parser.parse_args() @@ -199,6 +209,10 @@ def main(): # Run the queries and get the lists of source files. target_to_srcs: dict[str, list[str]] = {} runner: Buck2Runner = Buck2Runner(args.buck2) + buck_args = [] + if args.target_platforms: + buck_args = ["--target-platforms"] + buck_args.append(args.target_platforms) for name, target in graph.by_name.items(): target_to_srcs[name] = sorted(target.get_sources(graph, runner)) diff --git a/shim/BUCK b/shim/BUCK index 56fe035920b..cf6b8e79d1b 100644 --- a/shim/BUCK +++ b/shim/BUCK @@ -1,3 +1,4 @@ +load("@prelude//platforms:defs.bzl", "execution_platform") load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain") load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain") load("@prelude//toolchains:go.bzl", "system_go_toolchain") @@ -55,3 +56,12 @@ remote_test_execution_toolchain( name = "remote_test_execution", visibility = ["PUBLIC"], ) + +execution_platform( + name = "android-arm64", + cpu_configuration = "prelude//cpu:arm64", + os_configuration = "prelude//os:android", + # REVIEW: not sure if this is correct + use_windows_path_separators = host_info().os.is_windows, + visibility = ["PUBLIC"], +) From 919d1b8cb3b02004251b74f8d5538dd3c6b1bbef Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 13 Sep 2024 21:55:01 -0700 Subject: [PATCH 2/2] Update on "[executorch] Add android-arm64 execution platform in shim & plumb it to extract_sources.py" We need to tell Buck when we're building for Android, otherwise it will use the host configuration. Differential Revision: [D62671809](https://our.internmc.facebook.com/intern/diff/D62671809/) [ghstack-poisoned] --- build/Utils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Utils.cmake b/build/Utils.cmake index ce7315e5b39..baa87998485 100644 --- a/build/Utils.cmake +++ b/build/Utils.cmake @@ -185,7 +185,7 @@ function(extract_sources sources_file) endif() if(ANDROID_ABI) - if(STREQUAL "${ANDROID_ABI}" "arm64-v8a") + if("${ANDROID_ABI}" STREQUAL "arm64-v8a") set(target_platforms_arg "--target_platforms=shim//:android-arm64") else() message(FATAL_ERROR "Unsupported ANDROID_ABI setting ${ANDROID_ABI}. Please add it here!")