diff --git a/build/Utils.cmake b/build/Utils.cmake index d9811c8313e..2df51a2ae77 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("${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!") + 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..5004fe0c508 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,8 +209,12 @@ 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)) + target_to_srcs[name] = sorted(target.get_sources(graph, runner, buck_args)) # Generate the requested format. output: bytes 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"], +)