Skip to content

Commit e866987

Browse files
authored
Merge pull request #19 from appdevforall/ADFA-3596
ADFA-3596: Add C++ compiler plugin
2 parents 2877f0e + 9763c33 commit e866987

22 files changed

Lines changed: 1918 additions & 16 deletions

.github/workflows/build-plugins.yml

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,37 @@ jobs:
4242
CODEONTHEGO_REF: ${{ github.event.inputs.codeonthego_ref }}
4343
run: ./scripts/update-libs.sh --ref "$CODEONTHEGO_REF"
4444

45-
- name: Stage .cgp files with website filenames
45+
- name: Stage built .cgp artifacts
4646
run: |
4747
mkdir -p deploy-staging
48-
declare -A MAP=(
49-
["apk-viewer"]="apk-analyzer.cgp"
50-
["Beepy"]="beepy.cgp"
51-
["keystore-generator"]="keystore-generator.cgp"
52-
["markdown-preview"]="markdown-previewer.cgp"
53-
["ndk-installer-plugin"]="ndk-installer.cgp"
54-
["random-xkcd"]="random-xkcd.cgp"
55-
["snippets"]="snippets.cgp"
56-
["icons-repository"]="icons-repository.cgp"
57-
)
58-
for module in "${!MAP[@]}"; do
59-
src=$(ls "${module}/build/plugin/"*.cgp 2>/dev/null | head -n1)
48+
49+
# Discover every plugin module the same way scripts/update-libs.sh does
50+
# (a sibling dir whose build.gradle.kts applies the plugin-builder Gradle
51+
# plugin), then stage each plugin's built .cgp under its own name. The
52+
# plugin-builder already names the artifact, so there is no rename map —
53+
# new plugins are picked up automatically.
54+
staged=0
55+
for build_file in */build.gradle.kts; do
56+
[ -f "$build_file" ] || continue
57+
grep -qF "com.itsaky.androidide.plugins.build" "$build_file" || continue
58+
module="$(dirname "$build_file")"
59+
src="$(ls "${module}/build/plugin/"*.cgp 2>/dev/null | grep -v -- '-debug\.cgp$' | head -n1)"
6060
if [ -z "$src" ]; then
61-
echo "ERROR: no .cgp found under ${module}/build/plugin/"
61+
echo "ERROR: no release .cgp found under ${module}/build/plugin/ (did assemblePlugin run?)"
6262
exit 1
6363
fi
64-
cp "$src" "deploy-staging/${MAP[$module]}"
65-
echo "Staged $src -> deploy-staging/${MAP[$module]}"
64+
cp "$src" "deploy-staging/$(basename "$src")"
65+
echo "Staged $src -> deploy-staging/$(basename "$src")"
66+
staged=$((staged + 1))
6667
done
68+
69+
if [ "$staged" -eq 0 ]; then
70+
echo "ERROR: no plugin modules discovered under */build.gradle.kts"
71+
exit 1
72+
fi
73+
74+
echo ""
75+
echo "Staged ${staged} plugin artifact(s)."
6776
ls -la deploy-staging/
6877
6978
- name: Upload .cgp artifacts

cotg-ndk/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.

cotg-ndk/build.gradle.kts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
3+
plugins {
4+
id("com.android.application")
5+
id("org.jetbrains.kotlin.android")
6+
id("com.itsaky.androidide.plugins.build")
7+
}
8+
9+
pluginBuilder {
10+
pluginName = "cotgndk"
11+
}
12+
13+
android {
14+
namespace = "com.cotg.cotgndk"
15+
compileSdk = 34
16+
17+
defaultConfig {
18+
applicationId = "com.cotg.cotgndk"
19+
minSdk = 26
20+
targetSdk = 34
21+
versionCode = 6
22+
versionName = "6.0.0"
23+
}
24+
25+
buildTypes {
26+
release {
27+
isMinifyEnabled = false
28+
proguardFiles(
29+
getDefaultProguardFile("proguard-android-optimize.txt"),
30+
"proguard-rules.pro"
31+
)
32+
}
33+
}
34+
35+
compileOptions {
36+
sourceCompatibility = JavaVersion.VERSION_17
37+
targetCompatibility = JavaVersion.VERSION_17
38+
}
39+
40+
packaging {
41+
resources {
42+
excludes += setOf(
43+
"META-INF/versions/9/OSGI-INF/MANIFEST.MF",
44+
"META-INF/DEPENDENCIES",
45+
"META-INF/LICENSE",
46+
"META-INF/LICENSE.txt",
47+
"META-INF/NOTICE",
48+
"META-INF/NOTICE.txt"
49+
)
50+
}
51+
}
52+
}
53+
54+
kotlin {
55+
compilerOptions {
56+
jvmTarget.set(JvmTarget.JVM_17)
57+
}
58+
}
59+
60+
dependencies {
61+
compileOnly(files("../libs/plugin-api.jar"))
62+
63+
implementation("androidx.appcompat:appcompat:1.6.1")
64+
implementation("com.google.android.material:material:1.10.0")
65+
implementation("androidx.fragment:fragment-ktx:1.8.8")
66+
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.1.21")
67+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
68+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")
69+
}
70+
71+
tasks.wrapper {
72+
gradleVersion = "8.14.3"
73+
distributionType = Wrapper.DistributionType.BIN
74+
}
75+
76+
tasks.matching {
77+
it.name.contains("checkDebugAarMetadata") ||
78+
it.name.contains("checkReleaseAarMetadata")
79+
}.configureEach {
80+
enabled = false
81+
}

0 commit comments

Comments
 (0)