Skip to content

Commit b7e8c0a

Browse files
committed
Update on "[build] Fix flatc"
Fixes #8784 We need to install `build/pip_data_bin_init.py.in` into `<executorch root>/data/bin/__init__.py`. This PR rewrite the logic into a `BuiltFile` so that it works well in editable mode. Since `BuiltFile` by default looks into cmake cache directory, this PR adds a placeholder `%CMAKE_CACHE_DIR%` for those are actually built by CMake and for `build/pip_data_bin_init.py.in` we don't add this placeholder. Test: ``` python -c "from executorch.data.bin import flatc" ``` Will add unit test in next PR. [ghstack-poisoned]
1 parent 64d1900 commit b7e8c0a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

data/bin/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## PLEASE DO NOT REMOVE THIS DIRECTORY!
2+
3+
This directory is used to host binaries installed during pip wheel build time.
4+
5+
## How to add a binary into pip wheel
6+
7+
1. Update `[project.scripts]` section of `pyproject.toml` file. Add the new binary name and it's corresponding module name similar to:
8+
9+
```
10+
flatc = "executorch.data.bin:flatc"
11+
```
12+
13+
For example, `flatc` is built during wheel packaging, we first build `flatc` through CMake and copy the file to `<executorch root>/data/bin/flatc` and ask `setuptools` to generate a commandline wrapper for `flatc`, then route it to `<executorch root>/data/bin/flatc`.
14+
15+
This way after installing `executorch`, a user will be able to call `flatc` directly in commandline and it points to `<executorch root>/data/bin/flatc`
16+
17+
2. Update `setup.py` to include the logic of building the new binary and copying the binary to this directory.
18+
19+
```python
20+
BuiltFile(
21+
src_dir="%CMAKE_CACHE_DIR%/third-party/flatbuffers/%BUILD_TYPE%/",
22+
src_name="flatc",
23+
dst="executorch/data/bin/",
24+
is_executable=True,
25+
),
26+
```
27+
This means find `flatc` in `CMAKE_CACHE_DIR` and copy it to `<executorch root>/data/bin`. Notice that this works for both pip wheel packaging as well as editable mode install.
28+
29+
## Why we can't create this directory at wheel build time?
30+
31+
The reason is without `data/bin/` present in source file, we can't tell `setuptools` to generate a module `executorch.data.bin` in editable mode, partially because we don't have a good top level module `executorch` and have to enumerate all the second level modules, including `executorch.data.bin`.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ flatc = "executorch.data.bin:flatc"
8888
[tool.setuptools.package-dir]
8989
"executorch.backends" = "backends"
9090
"executorch.codegen" = "codegen"
91+
"executorch.data.bin" = "data/bin"
9192
# TODO(mnachin T180504136): Do not put examples/models
9293
# into core pip packages. Refactor out the necessary utils
9394
# or core models files into a separate package.

0 commit comments

Comments
 (0)