|
| 1 | +# cotg ndk: On-Device C++ Compiler for Code on the Go |
| 2 | + |
| 3 | +`cotg ndk` is a native C++ build environment that runs on the device. It installs an Android |
| 4 | +NDK, discovers the Clang toolchain and sysroot, provisions missing Android platform libraries, |
| 5 | +configures the active project's `app/src/main/cpp` with CMake, compiles for `arm64-v8a`, and |
| 6 | +writes the resulting `.so` into `app/src/main/jniLibs/arm64-v8a`. |
| 7 | + |
| 8 | +The plugin surfaces as a **"COTG C++ Engine"** sidebar item and a **"C++ Compiler"** editor tab |
| 9 | +that hosts a build console. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +### Core plugin capabilities |
| 14 | +- **Sidebar navigation**: `NavigationItem` ("COTG C++ Engine") in the `plugins` group |
| 15 | +- **Main editor tab**: `EditorTabItem` ("C++ Compiler") hosting the compiler console |
| 16 | +- **Themed UI**: fragment inflated through `PluginFragmentHelper.getPluginInflater` |
| 17 | +- **Service integration**: environment and project services, plus native `sh` commands |
| 18 | + |
| 19 | +### Plugin interfaces implemented |
| 20 | +- `IPlugin`: core plugin lifecycle |
| 21 | +- `UIExtension`: sidebar contribution |
| 22 | +- `EditorTabExtension`: main editor tab contribution |
| 23 | + |
| 24 | +### Compiler engine |
| 25 | +- **NDK detection**: finds an installed NDK at `$ANDROID_HOME/cotgx_ultimate_ndk`, or the |
| 26 | + `cotgx-ndk-ultimate.tar.gz` archive in the device `Download` folder |
| 27 | +- **Archive extraction**: extracts the NDK with the native `tar` command on first build |
| 28 | +- **Toolchain discovery**: locates `clang`/`clang++`, sysroot, JNI headers, the C++ STL |
| 29 | + (`c++/v1`), and `libc++`; targets `aarch64-linux-android21` |
| 30 | +- **Sysroot self-healing**: back-fills missing platform libraries (`liblog`, `libandroid`, |
| 31 | + `libEGL`, `libvulkan`, and others) from `/system/lib64` into the sysroot, with a warning when |
| 32 | + `liblog` cannot be resolved |
| 33 | +- **CMake and make build**: configures with a manual toolchain (`Unix Makefiles`, `Release`) |
| 34 | + and builds with `-j4` (parallel) or `-j1` (safe) |
| 35 | +- **Output**: copies built `*.so` into `jniLibs/arm64-v8a`, optionally exporting |
| 36 | + `libc++_shared.so` |
| 37 | +- **Live console**: streams build output, auto-scrolls, and copies logs to the clipboard |
| 38 | + |
| 39 | +## Architecture |
| 40 | + |
| 41 | +``` |
| 42 | +cotg-ndk/ |
| 43 | +├── build.gradle.kts # Build configuration (plugin API via ../libs) |
| 44 | +├── settings.gradle.kts # Buildscript classpath (shared ../libs) |
| 45 | +├── proguard-rules.pro # ProGuard keep rules |
| 46 | +├── cotg-ndk-documentation.html # Full plugin documentation |
| 47 | +├── src/main/ |
| 48 | +│ ├── AndroidManifest.xml # Plugin metadata, permissions, icons |
| 49 | +│ ├── kotlin/com/cotg/cotgndk/ |
| 50 | +│ │ ├── cotgndk.kt # Main plugin class (sidebar and tab contributions) |
| 51 | +│ │ └── fragments/ |
| 52 | +│ │ └── cotgndkFragment.kt # Compiler console and build engine |
| 53 | +│ ├── res/ |
| 54 | +│ │ ├── drawable/ic_plugin.xml # Monochrome "> C++" sidebar/tab icon |
| 55 | +│ │ ├── layout/fragment_main.xml |
| 56 | +│ │ └── values{,-night}/ # Material 3 teal-green theme |
| 57 | +│ └── assets/ |
| 58 | +│ ├── icon_day.png # "> C++" plugin badge (day) |
| 59 | +│ └── icon_night.png # "> C++" plugin badge (night) |
| 60 | +└── README.md |
| 61 | +``` |
| 62 | + |
| 63 | +### Plugin metadata (AndroidManifest.xml) |
| 64 | +- **plugin.id**: `com.cotg.cotgndk` |
| 65 | +- **plugin.name**: `cotg ndk` |
| 66 | +- **plugin.description**: Advanced C++ Compiler and NDK Installer |
| 67 | +- **plugin.author**: App Dev for All |
| 68 | +- **plugin.main_class**: `com.cotg.cotgndk.cotgndk` |
| 69 | +- **plugin.permissions**: `filesystem.read`, `filesystem.write`, `project.structure`, |
| 70 | + `system.commands`, `ide.environment.write` |
| 71 | +- **plugin.icon_day / plugin.icon_night**: `assets/icon_day.png` / `assets/icon_night.png` |
| 72 | + |
| 73 | +### Service integration |
| 74 | +- `IdeEnvironmentService`: `getAndroidHomeDirectory()` for NDK install and sysroot work |
| 75 | +- `IdeProjectService`: `getCurrentProject().rootDir` to locate the project to compile |
| 76 | +- `IdeEditorTabService`: `selectPluginTab()` to open the compiler tab from the sidebar |
| 77 | + |
| 78 | +## Building the plugin |
| 79 | + |
| 80 | +```bash |
| 81 | +# Build release plugin |
| 82 | +./gradlew assemblePlugin |
| 83 | + |
| 84 | +# Build debug plugin |
| 85 | +./gradlew assemblePluginDebug |
| 86 | +``` |
| 87 | + |
| 88 | +### Build output |
| 89 | +- Release: `build/plugin/cotgndk.cgp` |
| 90 | +- Debug: `build/plugin/cotgndk-debug.cgp` |
| 91 | + |
| 92 | +### Installation |
| 93 | +1. Import the `.cgp` file through Code on the Go's plugin manager. |
| 94 | +2. The IDE discovers `com.cotg.cotgndk.cotgndk` from the manifest metadata and loads it. |
| 95 | +3. Open **COTG C++ Engine** from the sidebar, or the **C++ Compiler** tab. |
| 96 | + |
| 97 | +## Usage |
| 98 | + |
| 99 | +1. Open a project that contains `app/src/main/cpp/CMakeLists.txt`. |
| 100 | +2. Open the **C++ Compiler** tab. |
| 101 | +3. If the NDK is not installed, tap **Download NDK** and place |
| 102 | + `cotgx-ndk-ultimate.tar.gz` in your `Download` folder, then reopen the tab. |
| 103 | +4. Optionally enable **Export libc++_shared.so** and Parallel mode. |
| 104 | +5. Tap **Compile**. The built `.so` is written to `app/src/main/jniLibs/arm64-v8a/`. |
| 105 | + |
| 106 | +## Dependencies |
| 107 | +- `plugin-api`: Code on the Go Plugin API (`compileOnly`, shared `../libs/plugin-api.jar`) |
| 108 | +- `androidx.fragment`, `androidx.appcompat`, `material`: UI |
| 109 | +- `kotlinx-coroutines-core` / `-android`: background build pipeline |
| 110 | + |
| 111 | +### Requirements |
| 112 | +- Android API 26+ (Android 8.0) |
| 113 | +- Minimum IDE version: 1.0.0 |
| 114 | +- Target ABI: `arm64-v8a` |
| 115 | +- Network once, to download the NDK archive |
| 116 | + |
| 117 | +## License |
| 118 | + |
| 119 | +Provided as-is for educational and development purposes. Use it as a foundation for your own |
| 120 | +Code on the Go plugins. |
0 commit comments