Skip to content

Commit cdf5a3c

Browse files
committed
feat(iSH): add build and header synchronization scripts for iSH integration
Signed-off-by: 7HR4IZ3 <90985774+7HR4IZ3@users.noreply.github.com>
1 parent 0948b01 commit cdf5a3c

7 files changed

Lines changed: 195 additions & 0 deletions

File tree

scripts/build-ish.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ "$(uname -s)" != "Darwin" ]]; then
5+
echo "This script is intended for macOS with Xcode installed."
6+
exit 1
7+
fi
8+
9+
if ! command -v xcodebuild >/dev/null 2>&1; then
10+
echo "xcodebuild not found. Install Xcode and Command Line Tools."
11+
exit 1
12+
fi
13+
14+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
15+
ISH_DIR="$ROOT_DIR/third_party/ish"
16+
OUTPUT_DIR="$ROOT_DIR/third_party/ish/build"
17+
18+
if [[ ! -d "$ISH_DIR" ]]; then
19+
echo "iSH source not found at $ISH_DIR"
20+
exit 1
21+
fi
22+
23+
mkdir -p "$OUTPUT_DIR"
24+
25+
# NOTE: You need to identify the correct scheme/target from iSH.xcodeproj.
26+
# Run: xcodebuild -list -project third_party/ish/iSH.xcodeproj
27+
# Then update SCHEME below.
28+
SCHEME="iSHLinux"
29+
30+
xcodebuild \
31+
-project "$ISH_DIR/iSH.xcodeproj" \
32+
-scheme "$SCHEME" \
33+
-configuration Release \
34+
-sdk iphoneos \
35+
BUILD_DIR="$OUTPUT_DIR" \
36+
build
37+
38+
echo "Build complete. Locate lib outputs under $OUTPUT_DIR"

scripts/sync-ish-headers.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
ISH_DIR="$ROOT_DIR/third_party/ish"
6+
DEST_DIR="$ROOT_DIR/src/plugins/terminal/src/ios/ish/include"
7+
8+
mkdir -p "$DEST_DIR"
9+
10+
cp "$ISH_DIR/app/LinuxInterop.h" "$DEST_DIR/"
11+
cp "$ISH_DIR/app/Terminal.h" "$DEST_DIR/"
12+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "IshRootfs.h"
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
static char *ish_root_path = NULL;
6+
7+
void IshSetRootPath(const char *path) {
8+
if (!path) {
9+
return;
10+
}
11+
free(ish_root_path);
12+
ish_root_path = strdup(path);
13+
}
14+
15+
__attribute__((weak)) const char *DefaultRootPath(void) {
16+
return ish_root_path ? ish_root_path : "";
17+
}
18+
19+
__attribute__((weak)) void ReportPanic(const char *message) {
20+
(void)message;
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <Foundation/Foundation.h>
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
void IshSetRootPath(const char *path);
8+
9+
#ifdef __cplusplus
10+
}
11+
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// LinuxInterop.h
3+
// iSH
4+
//
5+
// Created by Theodore Dubois on 7/3/21.
6+
//
7+
8+
#ifndef LinuxInterop_h
9+
#define LinuxInterop_h
10+
11+
#ifndef __KERNEL__
12+
#include <sys/types.h>
13+
#else
14+
#include <linux/types.h>
15+
#include <linux/fs.h>
16+
#endif
17+
18+
void async_do_in_irq(void (^block)(void));
19+
void async_do_in_workqueue(void (^block)(void));
20+
void async_do_in_ios(void (^block)(void));
21+
void sync_do_in_workqueue(void (^block)(void (^done)(void)));
22+
23+
// call into ios from kernel:
24+
25+
void actuate_kernel(const char *cmdline);
26+
27+
void ReportPanic(const char *message);
28+
void ConsoleLog(const char *data, unsigned len);
29+
const char *DefaultRootPath(void);
30+
31+
typedef const void *nsobj_t;
32+
nsobj_t objc_get(nsobj_t object);
33+
void objc_put(nsobj_t object);
34+
35+
struct linux_tty {
36+
struct linux_tty_callbacks *ops;
37+
};
38+
struct linux_tty_callbacks {
39+
void (*can_output)(struct linux_tty *tty);
40+
void (*send_input)(struct linux_tty *tty, const char *data, size_t length);
41+
void (*resize)(struct linux_tty *tty, int cols, int rows);
42+
void (*hangup)(struct linux_tty *tty);
43+
};
44+
45+
#ifdef __KERNEL__
46+
struct file *ios_pty_open(nsobj_t *terminal_out);
47+
#endif
48+
49+
nsobj_t Terminal_terminalWithType_number(int type, int number);
50+
void Terminal_setLinuxTTY(nsobj_t _self, struct linux_tty *tty);
51+
int Terminal_sendOutput_length(nsobj_t _self, const char *data, int size);
52+
int Terminal_roomForOutput(nsobj_t _self);
53+
54+
nsobj_t UIPasteboard_get(void);
55+
long UIPasteboard_changeCount(void);
56+
void UIPasteboard_set(const char *data, size_t len);
57+
size_t NSData_length(nsobj_t data);
58+
const void *NSData_bytes(nsobj_t data);
59+
60+
// call into kernel from ios:
61+
62+
typedef void (^StartSessionDoneBlock)(int retval, int pid, nsobj_t terminal);
63+
void linux_start_session(const char *exe, const char *const *argv, const char *const *envp, StartSessionDoneBlock done);
64+
65+
void linux_sethostname(const char *hostname);
66+
67+
ssize_t linux_read_file(const char *path, char *buf, size_t size);
68+
ssize_t linux_write_file(const char *path, const char *buf, size_t size);
69+
int linux_remove_directory(const char *path);
70+
71+
#endif /* LinuxInterop_h */
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Terminal.h
3+
// iSH
4+
//
5+
// Created by Theodore Dubois on 10/18/17.
6+
//
7+
8+
#import <UIKit/UIKit.h>
9+
#import <WebKit/WebKit.h>
10+
11+
struct tty;
12+
13+
@interface Terminal : NSObject
14+
15+
+ (Terminal *)terminalWithType:(int)type number:(int)number;
16+
#if !ISH_LINUX
17+
// Returns a strong struct tty and a Terminal that has a weak reference to the same tty
18+
+ (Terminal *)createPseudoTerminal:(struct tty **)tty;
19+
#endif
20+
21+
+ (Terminal *)terminalWithUUID:(NSUUID *)uuid;
22+
@property (readonly) NSUUID *uuid;
23+
24+
+ (void)convertCommand:(NSArray<NSString *> *)command toArgs:(char *)argv limitSize:(size_t)maxSize;
25+
26+
- (int)sendOutput:(const void *)buf length:(int)len;
27+
- (void)sendInput:(NSData *)input;
28+
29+
- (NSString *)arrow:(char)direction;
30+
31+
// Make this terminal no longer be the singleton terminal with its type and number. Will happen eventually if all references go away, but sometimes you want it to happen now.
32+
- (void)destroy;
33+
34+
@property (readonly) WKWebView *webView;
35+
@property (nonatomic) BOOL enableVoiceOverAnnounce;
36+
// Use KVO on this
37+
@property (readonly) BOOL loaded;
38+
39+
@end
40+
41+
extern struct tty_driver ios_console_driver;

third_party/ish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5534d5ac5358574049311fb247fe92bfb808134a

0 commit comments

Comments
 (0)