Skip to content

Commit d01c0a5

Browse files
committed
[executorch] Add android-arm64 execution platform in shim & plumb it to extract_sources.py
Pull Request resolved: #5369 We need to tell Buck when we're building for Android, otherwise it will use the host configuration. ghstack-source-id: 242555491 @exported-using-ghexport Differential Revision: [D62671809](https://our.internmc.facebook.com/intern/diff/D62671809/)
1 parent 3450ecc commit d01c0a5

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

build/Utils.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,18 @@ function(extract_sources sources_file)
184184
set(executorch_root ${CMAKE_CURRENT_SOURCE_DIR})
185185
endif()
186186

187+
if(ANDROID_ABI)
188+
if("${ANDROID_ABI}" STREQUAL "arm64-v8a")
189+
set(target_platforms_arg "--target-platforms=shim//:android-arm64")
190+
else()
191+
message(FATAL_ERROR "Unsupported ANDROID_ABI setting ${ANDROID_ABI}. Please add it here!")
192+
endif()
193+
endif()
187194
execute_process(
188195
COMMAND
189196
${PYTHON_EXECUTABLE} ${executorch_root}/build/extract_sources.py
190197
--config=${executorch_root}/build/cmake_deps.toml --out=${sources_file}
191-
--buck2=${BUCK2}
198+
--buck2=${BUCK2} ${target_platforms_arg}
192199
OUTPUT_VARIABLE gen_srcs_output
193200
ERROR_VARIABLE gen_srcs_error
194201
RESULT_VARIABLE gen_srcs_exit_code

build/extract_sources.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212

1313
from enum import Enum
14-
from typing import Any, Optional, Sequence
14+
from typing import Any, List, Optional, Sequence
1515

1616
from buck_util import Buck2Runner
1717

@@ -96,7 +96,12 @@ def __init__(
9696
else:
9797
self._config[k] = v
9898

99-
def get_sources(self, graph: "Graph", runner: Buck2Runner) -> frozenset[str]:
99+
def get_sources(
100+
self, graph: "Graph", runner: Buck2Runner, buck_args: Optional[List[str]]
101+
) -> frozenset[str]:
102+
if buck_args is None:
103+
buck_args = []
104+
100105
if self._state == Target._InitState.READY:
101106
return self._sources
102107
# Detect cycles.
@@ -113,7 +118,7 @@ def get_sources(self, graph: "Graph", runner: Buck2Runner) -> frozenset[str]:
113118
)
114119

115120
# Get the complete list of source files that this target depends on.
116-
sources: set[str] = set(runner.run(["cquery", query]))
121+
sources: set[str] = set(runner.run(["cquery", query] + buck_args))
117122

118123
# Keep entries that match all of the filters.
119124
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]:
128133
# its deps. Remove entries that are already covered by the transitive
129134
# set of dependencies.
130135
for dep in self._config.get("deps", []):
131-
sources.difference_update(graph.by_name[dep].get_sources(graph, runner))
136+
sources.difference_update(
137+
graph.by_name[dep].get_sources(graph, runner, buck_args)
138+
)
132139

133140
self._sources = frozenset(sources)
134141
self._state = Target._InitState.READY
@@ -173,6 +180,9 @@ def parse_args() -> argparse.Namespace:
173180
metavar="file",
174181
help="Path to the file to generate.",
175182
)
183+
parser.add_argument(
184+
"--target-platforms", help="--target-platforms to pass to buck cquery, if any."
185+
)
176186
return parser.parse_args()
177187

178188

@@ -199,6 +209,10 @@ def main():
199209
# Run the queries and get the lists of source files.
200210
target_to_srcs: dict[str, list[str]] = {}
201211
runner: Buck2Runner = Buck2Runner(args.buck2)
212+
buck_args = []
213+
if args.target_platforms:
214+
buck_args = ["--target-platforms"]
215+
buck_args.append(args.target_platforms)
202216
for name, target in graph.by_name.items():
203217
target_to_srcs[name] = sorted(target.get_sources(graph, runner))
204218

shim/BUCK

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@prelude//platforms:defs.bzl", "execution_platform")
12
load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain")
23
load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain")
34
load("@prelude//toolchains:go.bzl", "system_go_toolchain")
@@ -55,3 +56,12 @@ remote_test_execution_toolchain(
5556
name = "remote_test_execution",
5657
visibility = ["PUBLIC"],
5758
)
59+
60+
execution_platform(
61+
name = "android-arm64",
62+
cpu_configuration = "prelude//cpu:arm64",
63+
os_configuration = "prelude//os:android",
64+
# REVIEW: not sure if this is correct
65+
use_windows_path_separators = host_info().os.is_windows,
66+
visibility = ["PUBLIC"],
67+
)

0 commit comments

Comments
 (0)