From c37a04e2e43cb076b9997cc6105d38b7c8dfd60d Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Sun, 27 Jun 2021 21:41:58 -0700 Subject: [PATCH] now I can build and run the app and build but not run linux in the same xcode project --- app/App.xcconfig | 1 + app/AppDelegate.m | 8 +- app/Linux.xcconfig | 4 + app/MesonLinux.xcconfig | 2 - app/NotLinux.xcconfig | 1 + app/Project.xcconfig | 2 +- app/ProjectDebug.xcconfig | 1 + app/ProjectDebugLinux.xcconfig | 3 + app/ProjectRelease.xcconfig | 1 + app/ProjectReleaseLinux.xcconfig | 3 + app/Roots.m | 11 ++ app/Terminal.m | 22 +++ app/TerminalViewController.m | 4 + deps/linux-build.sh | 9 +- iSH.xcodeproj/project.pbxproj | 268 +++++++++++++++++++------------ meson.build | 25 ++- tools/staticdefine.sh | 2 +- 17 files changed, 244 insertions(+), 123 deletions(-) create mode 100644 app/Linux.xcconfig delete mode 100644 app/MesonLinux.xcconfig create mode 100644 app/NotLinux.xcconfig create mode 100644 app/ProjectDebugLinux.xcconfig create mode 100644 app/ProjectReleaseLinux.xcconfig diff --git a/app/App.xcconfig b/app/App.xcconfig index 1d462456..61ae69c7 100644 --- a/app/App.xcconfig +++ b/app/App.xcconfig @@ -11,3 +11,4 @@ CODE_SIGN_ENTITLEMENTS = app/iSH.entitlements ENABLE_ON_DEMAND_RESOURCES = NO HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT) $(SRCROOT)/deps/libarchive/libarchive +OTHER_LDFLAGS = -ObjC diff --git a/app/AppDelegate.m b/app/AppDelegate.m index ebf30fc4..f0778a35 100644 --- a/app/AppDelegate.m +++ b/app/AppDelegate.m @@ -66,6 +66,7 @@ static NSString *const kSkipStartupMessage = @"Skip Startup Message"; @implementation AppDelegate - (int)boot { +#if !ISH_LINUX NSURL *root = [[Roots.instance rootUrl:Roots.instance.defaultRoot] URLByAppendingPathComponent:@"data"]; int err = mount_root(&fakefs, root.fileSystemRepresentation); if (err < 0) @@ -182,11 +183,13 @@ static NSString *const kSkipStartupMessage = @"Skip Startup Message"; if (err < 0) return err; task_start(current); +#endif return 0; } - (void)configureDns { +#if !ISH_LINUX struct __res_state res; if (EXIT_SUCCESS != res_ninit(&res)) { exit(2); @@ -218,6 +221,7 @@ static NSString *const kSkipStartupMessage = @"Skip Startup Message"; fd->ops->write(fd, resolvConf.UTF8String, [resolvConf lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); fd_close(fd); } +#endif } + (int)bootError { @@ -269,7 +273,8 @@ void NetworkReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach if ([NSUserDefaults.standardUserDefaults boolForKey:@"FASTLANE_SNAPSHOT"]) [UIView setAnimationsEnabled:NO]; - + +#if !ISH_LINUX self.unameVersion = [NSString stringWithFormat:@"iSH %@ (%@)", [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [NSBundle.mainBundle objectForInfoDictionaryKey:(NSString *) kCFBundleVersionKey]]; @@ -279,6 +284,7 @@ void NetworkReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach self.unameHostname = [NSUserDefaults.standardUserDefaults stringForKey:@"hostnameOverride"]; extern const char *uname_hostname_override; uname_hostname_override = self.unameHostname.UTF8String; +#endif [UserPreferences.shared observe:@[@"shouldDisableDimming"] options:NSKeyValueObservingOptionInitial owner:self usingBlock:^(typeof(self) self) { diff --git a/app/Linux.xcconfig b/app/Linux.xcconfig new file mode 100644 index 00000000..afc4b2f0 --- /dev/null +++ b/app/Linux.xcconfig @@ -0,0 +1,4 @@ +ISH_KERNEL = linux +NINJA_TARGETS = deps/liblinux.a libfakefs.a libish_emu.a +LINUX_HOSTCC = env -u SDKROOT -u IPHONEOS_DEPLOYMENT_TARGET xcrun clang +GCC_PREPROCESSOR_DEFINITIONS = ISH_LINUX=1 diff --git a/app/MesonLinux.xcconfig b/app/MesonLinux.xcconfig deleted file mode 100644 index 199f1a06..00000000 --- a/app/MesonLinux.xcconfig +++ /dev/null @@ -1,2 +0,0 @@ -ISH_KERNEL = linux -NINJA_TARGETS = liblinux.a libish_emu.a diff --git a/app/NotLinux.xcconfig b/app/NotLinux.xcconfig new file mode 100644 index 00000000..c586ed45 --- /dev/null +++ b/app/NotLinux.xcconfig @@ -0,0 +1 @@ +NINJA_TARGETS = libish.a libish_emu.a libfakefs.a diff --git a/app/Project.xcconfig b/app/Project.xcconfig index b1a31c95..308b74fe 100644 --- a/app/Project.xcconfig +++ b/app/Project.xcconfig @@ -10,6 +10,6 @@ VERSIONING_SYSTEM = apple-generic MESON_BUILD_DIR = $(CONFIGURATION_BUILD_DIR)/meson NINJA = /usr/local/bin/ninja -NINJA_TARGETS = libish.a libish_emu.a +NINJA_TARGETS = libish.a libish_emu.a libfakefs.a SUPPORTED_PLATFORMS = iphonesimulator iphoneos macosx diff --git a/app/ProjectDebug.xcconfig b/app/ProjectDebug.xcconfig index 4f985904..3c20beb3 100644 --- a/app/ProjectDebug.xcconfig +++ b/app/ProjectDebug.xcconfig @@ -1,2 +1,3 @@ #include "XcodeDebug.xcconfig" #include "Project.xcconfig" +#include "NotLinux.xcconfig" diff --git a/app/ProjectDebugLinux.xcconfig b/app/ProjectDebugLinux.xcconfig new file mode 100644 index 00000000..c7b83451 --- /dev/null +++ b/app/ProjectDebugLinux.xcconfig @@ -0,0 +1,3 @@ +#include "XcodeDebug.xcconfig" +#include "Project.xcconfig" +#include "Linux.xcconfig" diff --git a/app/ProjectRelease.xcconfig b/app/ProjectRelease.xcconfig index 85d5c49b..0f9589b9 100644 --- a/app/ProjectRelease.xcconfig +++ b/app/ProjectRelease.xcconfig @@ -1,2 +1,3 @@ #include "XcodeRelease.xcconfig" #include "Project.xcconfig" +#include "NotLinux.xcconfig" diff --git a/app/ProjectReleaseLinux.xcconfig b/app/ProjectReleaseLinux.xcconfig new file mode 100644 index 00000000..bf844e2c --- /dev/null +++ b/app/ProjectReleaseLinux.xcconfig @@ -0,0 +1,3 @@ +#include "XcodeRelease.xcconfig" +#include "Project.xcconfig" +#include "Linux.xcconfig" diff --git a/app/Roots.m b/app/Roots.m index 51a6e1d0..34505b31 100644 --- a/app/Roots.m +++ b/app/Roots.m @@ -25,6 +25,17 @@ static NSURL *RootsDir() { return rootsDir; } +#if ISH_LINUX + +bool fakefs_export(const char *fs, const char *archive_path, struct fakefsify_error *err_out, struct progress progress) { + return false; +} +bool fakefs_import(const char *archive_path, const char *fs, struct fakefsify_error *err_out, struct progress progress) { + return false; +} + +#endif + static NSString *kDefaultRoot = @"Default Root"; @interface Roots () diff --git a/app/Terminal.m b/app/Terminal.m index 0e6adf80..63cc1308 100644 --- a/app/Terminal.m +++ b/app/Terminal.m @@ -15,13 +15,17 @@ extern struct tty_driver ios_pty_driver; @interface Terminal () { +#if !ISH_LINUX lock_t _dataLock; cond_t _dataConsumed; +#endif } @property WKWebView *webView; @property BOOL loaded; +#if !ISH_LINUX @property (nonatomic) struct tty *tty; +#endif @property (nonatomic) NSMutableData *pendingData; @property (nonatomic) BOOL processingPendingData; @@ -68,8 +72,10 @@ static NSMapTable *terminalsByUUID; self.pendingData = [NSMutableData new]; self.refreshTask = [[DelayedUITask alloc] initWithTarget:self action:@selector(refresh)]; self.scrollToBottomTask = [[DelayedUITask alloc] initWithTarget:self action:@selector(scrollToBottom)]; +#if !ISH_LINUX lock_init(&_dataLock); cond_init(&_dataConsumed); +#endif WKWebViewConfiguration *config = [WKWebViewConfiguration new]; [config.userContentController addScriptMessageHandler:self name:@"load"]; @@ -91,19 +97,23 @@ static NSMapTable *terminalsByUUID; return self; } +#if !ISH_LINUX + (Terminal *)createPseudoTerminal:(struct tty **)tty { *tty = pty_open_fake(&ios_pty_driver); if (IS_ERR(*tty)) return nil; return (__bridge Terminal *) (*tty)->data; } +#endif +#if !ISH_LINUX - (void)setTty:(struct tty *)tty { _tty = tty; dispatch_async(dispatch_get_main_queue(), ^{ [self syncWindowSize]; }); } +#endif - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message { if ([message.name isEqualToString:@"load"]) { @@ -124,6 +134,7 @@ static NSMapTable *terminalsByUUID; } - (void)syncWindowSize { +#if !ISH_LINUX [self.webView evaluateJavaScript:@"exports.getSize()" completionHandler:^(NSArray *dimensions, NSError *error) { if (self.tty == NULL) { return; @@ -134,6 +145,7 @@ static NSMapTable *terminalsByUUID; tty_set_winsize(self.tty, (struct winsize_) {.col = cols, .row = rows}); unlock(&self.tty->lock); }]; +#endif } - (void)setEnableVoiceOverAnnounce:(BOOL)enableVoiceOverAnnounce { @@ -144,6 +156,7 @@ static NSMapTable *terminalsByUUID; } - (int)write:(const void *)buf length:(size_t)len { +#if !ISH_LINUX lock(&_dataLock); if (!NSThread.isMainThread) { // The main thread is the only one that can unblock this, so sleeping here would be a deadlock. @@ -154,15 +167,18 @@ static NSMapTable *terminalsByUUID; [self.pendingData appendData:[NSData dataWithBytes:buf length:len]]; [self.refreshTask schedule]; unlock(&_dataLock); +#endif return 0; } - (void)sendInput:(const char *)buf length:(size_t)len { +#if !ISH_LINUX if (self.tty == NULL) return; tty_input(self.tty, buf, len, 0); [self.webView evaluateJavaScript:@"exports.setUserGesture()" completionHandler:nil]; [self.scrollToBottomTask schedule]; +#endif } - (void)scrollToBottom { @@ -177,6 +193,7 @@ static NSMapTable *terminalsByUUID; if (!self.loaded) return; +#if !ISH_LINUX lock(&_dataLock); if (_processingPendingData) { unlock(&_dataLock); @@ -205,6 +222,7 @@ static NSMapTable *terminalsByUUID; return; } }]; +#endif } + (void)convertCommand:(NSArray *)command toArgs:(char *)argv limitSize:(size_t)maxSize { @@ -230,12 +248,14 @@ static NSMapTable *terminalsByUUID; } - (void)destroy { +#if !ISH_LINUX struct tty *tty = self.tty; if (tty != NULL) { lock(&tty->lock); tty_hangup(tty); unlock(&tty->lock); } +#endif [terminals removeObjectForKey:self.terminalsKey]; } @@ -246,6 +266,7 @@ static NSMapTable *terminalsByUUID; @end +#if !ISH_LINUX static int ios_tty_init(struct tty *tty) { // This is called with ttys_lock but that results in deadlock since the main thread can also acquire ttys_lock. So release it. unlock(&ttys_lock); @@ -281,3 +302,4 @@ struct tty_driver_ops ios_tty_ops = { }; DEFINE_TTY_DRIVER(ios_console_driver, &ios_tty_ops, TTY_CONSOLE_MAJOR, 64); struct tty_driver ios_pty_driver = {.ops = &ios_tty_ops}; +#endif diff --git a/app/TerminalViewController.m b/app/TerminalViewController.m index 9a3b4e2c..dc5655a2 100644 --- a/app/TerminalViewController.m +++ b/app/TerminalViewController.m @@ -146,6 +146,7 @@ } - (int)startSession { +#if !ISH_LINUX int err = become_new_init_child(); if (err < 0) return err; @@ -173,6 +174,7 @@ return err; self.sessionPid = current->pid; task_start(current); +#endif return 0; } @@ -195,7 +197,9 @@ return; } } +#if !ISH_LINUX current = NULL; // it's been freed +#endif [self startNewSession]; } diff --git a/deps/linux-build.sh b/deps/linux-build.sh index 8aa4bfce..1edb1579 100755 --- a/deps/linux-build.sh +++ b/deps/linux-build.sh @@ -7,6 +7,11 @@ export ISH_CFLAGS="$5" export LIB_ISH_EMU="$6" export ARCH=ish +makeargs=() +if [[ -n "$LINUX_HOSTCC" ]]; then + makeargs+="HOSTCC=$LINUX_HOSTCC" +fi + mkdir -p "$objtree" export ISH_MESON_VARS="$(realpath "$objtree/meson_vars.mk")" cat >"$ISH_MESON_VARS" <