Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-isysroot missing #8811

Closed
pfgithub opened this issue May 18, 2021 · 8 comments
Closed

-isysroot missing #8811

pfgithub opened this issue May 18, 2021 · 8 comments
Labels
Milestone

Comments

@pfgithub
Copy link
Contributor

I'm trying to make an iOS app. To cross-compile from macOS to iOS, -isysroot needs to be specified to find frameworks.

The clang build command clang -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path) -framework Foundation -framework UIKit -framework QuartzCore -lobjc main.c can't be run using zig cc or zig build-exe because -isysroot is missing and without it, frameworks are not found.

Sample objective-c file that should be possible to compile with zig cc/zig build-exe:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(id)options {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
    self.window = [[UIWindow alloc]  initWithFrame:mainScreenBounds];
    UIViewController *viewController = [[UIViewController alloc] init];
    viewController.view.backgroundColor = [UIColor whiteColor];
    viewController.view.frame = mainScreenBounds;
    self.window.rootViewController = viewController;

    CAShapeLayer *circleLayer = [CAShapeLayer layer];
    [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 100)] CGPath]];
    [circleLayer setStrokeColor:[[UIColor redColor] CGColor]];
    [circleLayer setFillColor:[[UIColor clearColor] CGColor]];
    [[viewController.view layer] addSublayer:circleLayer];

    return YES;
}

@end

int main(int argc, char *argv[]) {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    NSLog(@"%s", "Application Launched!");
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
@kubkon kubkon added this to the 0.9.0 milestone May 18, 2021
@kubkon
Copy link
Member

kubkon commented May 18, 2021

I just wanted to add here that cross-compiling to iOS is untested waters plus the linker zig ld cannot link frameworks yet, nor can it disambiguate which target platform we are aiming for, i.e., macOS or iOS, etc.

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@kubkon
Copy link
Member

kubkon commented Jun 29, 2021

sysroot flag was added in #9202, so closing the issue.

@kubkon kubkon closed this as completed Jun 29, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.9.0 Jun 29, 2021
@jmrico01
Copy link
Sponsor

jmrico01 commented Jul 3, 2021

@kubkon Not sure if I'm missing something, but even after passing -isysroot, zig cc isn't able to find the headers for the UIKit framework when cross-compiling for iOS. Maybe I misunderstood, and your comment about "cannot link frameworks" still applies, though I've seen some good progress very recently around this (#9229) so I decided to give it a shot.

I have the following minimal main.m file:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)options
{
    CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
    self.window = [[UIWindow alloc] initWithFrame:mainScreenBounds];

    UIViewController *viewController = [[UIViewController alloc] init];
    viewController.view.backgroundColor = [UIColor whiteColor];
    viewController.view.frame = mainScreenBounds;  UILabel *label = [[UILabel alloc] initWithFrame:mainScreenBounds];
    [label setText:@"Hello world!"];
    [viewController.view addSubview: label];  self.window.rootViewController = viewController;  [self.window makeKeyAndVisible];

    return YES;
}

@end

int main(int argc, char *argv[])
{
    NSString * appDelegateClassName;
    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
    }
    return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}

Then, with zig version 0.9.0-dev.347+628f490c5, I run pretty much exactly what OP posted but with zig cc instead of clang (tried with --target aarch64-ios too)

zig cc -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path) -framework Foundation -framework UIKit main.m

and I get the following:

./src/main.m:1:9: fatal error: 'UIKit/UIKit.h' file not found
#import <UIKit/UIKit.h>
        ^~~~~~~~~~~~~~~
1 error generated.

@kubkon
Copy link
Member

kubkon commented Jul 3, 2021

@kubkon Not sure if I'm missing something, but even after passing -isysroot, zig cc isn't able to find the headers for the UIKit framework when cross-compiling for iOS. Maybe I misunderstood, and your comment about "cannot link frameworks" still applies, though I've seen some good progress very recently around this (#9229) so I decided to give it a shot.

I have the following minimal main.m file:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)options
{
    CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
    self.window = [[UIWindow alloc] initWithFrame:mainScreenBounds];

    UIViewController *viewController = [[UIViewController alloc] init];
    viewController.view.backgroundColor = [UIColor whiteColor];
    viewController.view.frame = mainScreenBounds;  UILabel *label = [[UILabel alloc] initWithFrame:mainScreenBounds];
    [label setText:@"Hello world!"];
    [viewController.view addSubview: label];  self.window.rootViewController = viewController;  [self.window makeKeyAndVisible];

    return YES;
}

@end

int main(int argc, char *argv[])
{
    NSString * appDelegateClassName;
    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
    }
    return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}

Then, with zig version 0.9.0-dev.347+628f490c5, I run pretty much exactly what OP posted but with zig cc instead of clang (tried with --target aarch64-ios too)

zig cc -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path) -framework Foundation -framework UIKit main.m

and I get the following:

./src/main.m:1:9: fatal error: 'UIKit/UIKit.h' file not found
#import <UIKit/UIKit.h>
        ^~~~~~~~~~~~~~~
1 error generated.

You'll definitely need to pass --target amd try passing --sysroot instead of -isysroot.

@jmrico01
Copy link
Sponsor

jmrico01 commented Jul 3, 2021

No luck, just tried --sysroot, still can't find the UIKit header. I also added #import <Foundation/Foundation.h> just to see what happens, and it can't find that either (not that there's anything special about the Foundation framework, I guess).

I'm passing --target=aarch64-ios, and tried both -isysroot and --sysroot, with both iphonesimulator and iphoneos for the sdk.

@kubkon
Copy link
Member

kubkon commented Jul 3, 2021

Cool, thanks for the report! I'll reopen the issue then.

@kubkon kubkon reopened this Jul 3, 2021
@jmrico01
Copy link
Sponsor

@kubkon I think this can be closed now that #9532 is merged

@kubkon
Copy link
Member

kubkon commented Aug 14, 2021

Excellent point @jmrico01, closing!

@kubkon kubkon closed this as completed Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants