~lord/krasovs.ky

d70b9820d137efbb5d27a3b44e60f3d50c1dd233 — Savely Krasovsky 30 days ago 3917498
fix(flipper-zero): update after patches
1 files changed, 21 insertions(+), 26 deletions(-)

M content/blog/flipper-zero-clion.md
M content/blog/flipper-zero-clion.md => content/blog/flipper-zero-clion.md +21 -26
@@ 20,28 20,34 @@ CLion syntax highlighting and autocomplete engine works out of the box only with
[compilation database](https://www.jetbrains.com/help/clion/compilation-database.html), which `fbt` can generate.
So to start:

1. Clone this repo by hand or using CLion.
2. Open it as a project.
3. Go to `File -> Settings -> Build, Execution, Deployment -> Toolchains` and create toolkit:
1. Clone Flipper Zero firmware repo:

    - C Compiler: `toolchain/x86_64-linux/bin/arm-none-eabi-gcc`
    - С++ Compiler: `toolchain/x86_64-linux/bin/arm-none-eabi-g++`
    - Debugger: `toolchain/x86_64-linux/bin/arm-none-eabi-gdb-py`
   ```bash
   git clone --recursive https://github.com/flipperdevices/flipperzero-firmware.git
   ```

4. Build it and generate compilation database:
2. Build firmware, FAPs and create compile database:

   ```shell
   ./fbt
   ./fbt faps
   ./fbt firmware_cdb
   ```

5. Go and find `compile_commands.json` file at `build/latest`, then click right mouse button and choose
3. Copy `compile_commands.json` from `build/latest` to the project root.
4. Open this file with CLion.
5. Go and find `compile_commands.json` file at `build/latest` again, then click right mouse button and choose
   `Load Compilation Database Project`.
6. It should try to sync a project, but probably will fail.
6. Remove `compile_commands.json` from the project root.
7. Go to `File -> Settings -> Build, Execution, Deployment -> Toolchains` and create toolkit:

It will cause inability to index a project, so most features won't work.
    - C Compiler: `toolchain/x86_64-linux/bin/arm-none-eabi-gcc`
    - С++ Compiler: `toolchain/x86_64-linux/bin/arm-none-eabi-g++`
    - Debugger: `toolchain/x86_64-linux/bin/arm-none-eabi-gdb-py`

### Problems and their solutions
8. It should try to sync a project at `Build` tab successfully.

### Possible problems and their solutions

- CLion does not understand `ccache`.



@@ 54,15 60,6 @@ It will cause inability to index a project, so most features won't work.
   sed -i 's/ccache\ //g' compile_commands.json
   ```

- CLion does not understand `arm-none-eabi-as`.

  **Solution:** remove it from compilation database:

   ```shell
   cd build/latest
   jq 'map(select(.command | contains("arm-none-eabi-as") | not))' compile_commands.json > compile_commands.json.tmp && mv compile_commands.json.tmp compile_commands.json
   ```

- CLion cannot find stdlib.

  **Solution 1:** Launch CLion under `fbt` environment:


@@ 85,12 82,6 @@ It will cause inability to index a project, so most features won't work.
   sudo pacman -S arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-newlib  
   ```

- Compilation database contains links to source files that are not presented in the main source tree.

  **Solution 1:** wait a patch of SCons from Flipper team.

  **Solution 2:** remove these links from compilation database file by hand.

After this troubleshooting CLion should work as expected: highlighting and autocompleting your code.

### Setup debugging


@@ 133,3 124,7 @@ After this troubleshooting CLion should work as expected: highlighting and autoc
   block "External tool" to automate step 4.

   ![](/clion_external_tool.png)

**UPD: 10 november 2022**

Guide has been updated after patches from Flipper Devices team! Now it should work with fewer tricks.
\ No newline at end of file