Skip to content

Commit fbb017f

Browse files
committed
feat(iSH): add hooks for iOS rootfs integration and library linking
Signed-off-by: 7HR4IZ3 <90985774+7HR4IZ3@users.noreply.github.com>
1 parent cdf5a3c commit fbb017f

6 files changed

Lines changed: 130 additions & 1 deletion

File tree

docs/ISH_INTEGRATION.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Goal: provide an iSH-style x86 Alpine environment on iOS and bridge it to the ex
99
- Output streaming is hooked by swizzling `Terminal sendOutput:length:` and forwarding to Cordova callbacks.
1010
- Rootfs bootstrap copies `ish-rootfs` from app bundle to `Documents/ish-rootfs` if present.
1111
- Rootfs path is provided via `DefaultRootPath()` (weak symbol in `IshRootfs.c`).
12+
- Hooks copy `src/ios/ish-rootfs` into the iOS app bundle after prepare.
1213

1314
## Key iSH entry points
1415

@@ -50,9 +51,13 @@ Goal: provide an iSH-style x86 Alpine environment on iOS and bridge it to the ex
5051
Scripts:
5152
- `scripts/build-ish.sh` for building iSH (macOS + Xcode).
5253
- `scripts/sync-ish-headers.sh` for syncing required headers.
54+
- `scripts/prepare-ish-rootfs.sh` to extract an Alpine rootfs into `src/ios/ish-rootfs`.
55+
Scripts:
56+
- `scripts/build-ish.sh` for building iSH (macOS + Xcode).
57+
- `scripts/sync-ish-headers.sh` for syncing required headers.
5358

5459
## Next TODOs
5560

5661
- Bundle Alpine rootfs under `ish-rootfs` and validate `/bin/sh`.
57-
- Link iSH static lib into Cordova build.
62+
- Link iSH static lib into Cordova build (hooks added, requires `xcode` npm package).
5863
- Add exit event callbacks when sessions terminate.

hooks/ios/add-ish-lib.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
4+
const fs = require("fs");
5+
const path = require("path");
6+
7+
function findXcodeProj(platformsPath) {
8+
if (!fs.existsSync(platformsPath)) return null;
9+
const entries = fs.readdirSync(platformsPath).filter((name) => name.endsWith(".xcodeproj"));
10+
if (!entries.length) return null;
11+
return path.join(platformsPath, entries[0], "project.pbxproj");
12+
}
13+
14+
function main() {
15+
const projectRoot = process.cwd();
16+
const iosPath = path.join(projectRoot, "platforms", "ios");
17+
const pbxprojPath = findXcodeProj(iosPath);
18+
if (!pbxprojPath) {
19+
console.log("iSH hook: no iOS Xcode project found, skipping.");
20+
return;
21+
}
22+
23+
let xcode;
24+
try {
25+
xcode = require("xcode");
26+
} catch (err) {
27+
console.log("iSH hook: npm package 'xcode' not installed. Skipping auto-link.\n" +
28+
"Install dev dependency or link libiSH manually in Xcode.");
29+
return;
30+
}
31+
32+
const libPath = path.join(projectRoot, "third_party", "ish", "build", "Release-iphoneos", "libiSHLinux.a");
33+
if (!fs.existsSync(libPath)) {
34+
console.log("iSH hook: libiSHLinux.a not found at", libPath);
35+
console.log("Build iSH first (scripts/build-ish.sh) or adjust hook path.");
36+
return;
37+
}
38+
39+
const project = xcode.project(pbxprojPath);
40+
project.parseSync();
41+
42+
const target = project.getFirstTarget().uuid;
43+
project.addFile(libPath, "Frameworks", target);
44+
project.addFramework(libPath, { customFramework: true, embed: false });
45+
46+
fs.writeFileSync(pbxprojPath, project.writeSync());
47+
console.log("iSH hook: linked libiSHLinux.a");
48+
}
49+
50+
main();

hooks/ios/add-ish-rootfs.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
4+
const fs = require("fs");
5+
const path = require("path");
6+
7+
function copyDir(src, dest) {
8+
if (!fs.existsSync(src)) return;
9+
fs.mkdirSync(dest, { recursive: true });
10+
for (const entry of fs.readdirSync(src)) {
11+
const srcPath = path.join(src, entry);
12+
const destPath = path.join(dest, entry);
13+
const stat = fs.statSync(srcPath);
14+
if (stat.isDirectory()) {
15+
copyDir(srcPath, destPath);
16+
} else {
17+
fs.copyFileSync(srcPath, destPath);
18+
}
19+
}
20+
}
21+
22+
function main() {
23+
const projectRoot = process.cwd();
24+
const iosPath = path.join(projectRoot, "platforms", "ios");
25+
if (!fs.existsSync(iosPath)) {
26+
console.log("iSH rootfs hook: no iOS platform found, skipping.");
27+
return;
28+
}
29+
30+
const appDir = fs.readdirSync(iosPath).find((name) => name.endsWith(".xcodeproj"));
31+
if (!appDir) {
32+
console.log("iSH rootfs hook: no Xcode project found, skipping.");
33+
return;
34+
}
35+
36+
const appName = appDir.replace(/\.xcodeproj$/, "");
37+
const srcRootfs = path.join(projectRoot, "src", "ios", "ish-rootfs");
38+
const destRootfs = path.join(iosPath, appName, "ish-rootfs");
39+
40+
if (!fs.existsSync(srcRootfs)) {
41+
console.log("iSH rootfs hook: src/ios/ish-rootfs not found, skipping.");
42+
return;
43+
}
44+
45+
copyDir(srcRootfs, destRootfs);
46+
console.log("iSH rootfs hook: copied rootfs to", destRootfs);
47+
}
48+
49+
main();

scripts/prepare-ish-rootfs.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
DEST="$ROOT_DIR/src/ios/ish-rootfs"
6+
ARCHIVE="${1:-}"
7+
8+
if [[ -z "$ARCHIVE" ]]; then
9+
echo "Usage: $0 /path/to/alpine-rootfs.tar.gz"
10+
exit 1
11+
fi
12+
13+
if [[ ! -f "$ARCHIVE" ]]; then
14+
echo "Archive not found: $ARCHIVE"
15+
exit 1
16+
fi
17+
18+
rm -rf "$DEST"
19+
mkdir -p "$DEST"
20+
21+
tar -xzf "$ARCHIVE" -C "$DEST"
22+
23+
echo "Rootfs extracted to $DEST"

src/ios/ish-rootfs/.gitkeep

Whitespace-only changes.

src/plugins/terminal/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,7 @@
9292
<source-file src="src/ios/IshRootfs.c" />
9393
<header-file src="src/ios/ish/include/LinuxInterop.h" />
9494
<header-file src="src/ios/ish/include/Terminal.h" />
95+
<hook type="after_prepare" src="hooks/ios/add-ish-lib.js" />
96+
<hook type="after_prepare" src="hooks/ios/add-ish-rootfs.js" />
9597
</platform>
9698
</plugin>

0 commit comments

Comments
 (0)