Skip to content

Apple Silicon M1 arm cpu #204

Closed
Closed

Description

@hannesa2

Are there any plans to make a release with new M1 cpu ?
I don't want to ask only, because I started to build it with CI action as first step #203
but this cascading git submodules makes it not easier

Activity

  1. hannesa2 commented on Nov 22, 2020

    @hannesa2
    ContributorAuthor

    And I've too less Mac developer experience so I don't know why I don't see an arm target ?

    image

  2. jspiro commented on Nov 17, 2021

    @jspiro
    Member

    What's more concerning is that Homebrew moved to /opt/homebrew from /usr/local on ARM. This is a nightmare because there are hundreds of hard references in the project to /usr/local. I spent an hour trying to work through it but I'm not experienced enough in Xcode or our scripts and dependencies. I suspect we need to update our dependencies to support ARM and then it won't be hard to link against them.

    I spent some time looking at libgit2 and objective-git and neither seems to have any PRs or issues open around this.

    Ultimately, it's unclear what the best practices are for cross platform builds with two "standard" directories now.

  3. jspiro commented on Nov 17, 2021

    @jspiro
    Member

    GitX also won't load on an M1 due to this:

    Termination Reason:    Namespace DYLD, Code 1 Library missing
    Library not loaded: /usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib
    
  4. hannesa2 commented on Nov 17, 2021

    @hannesa2
    ContributorAuthor

    Can you share your (intermediate) work as a pull request ?

  5. jspiro commented on Nov 17, 2021

    @jspiro
    Member

    I ended up throwing away my attempts, it wasn't getting anywhere and I was making a mess of things 🙈

    I have to figure out a way to run GitX on my M1, though. I'm lost without it 😭

  6. simoncozens commented on Nov 25, 2021

    @simoncozens

    I got this working, but it is not easy to rework as a pull request because it requires changes to the external ObjectiveGit framework.

    Here's what I did:

    • brew install openssl
    • In External/objective-git, patch the Xcodeproj file:
    diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj
    index 66b9339a..54a330f8 100644
    --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj
    +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj
    @@ -1687,7 +1687,7 @@
     				INFOPLIST_FILE = Info.plist;
     				LIBRARY_SEARCH_PATHS = (
     					"$(inherited)",
    -					/usr/local/opt/openssl/lib,
    +					"/opt/homebrew/opt/openssl@3/lib",
     					"$(PROJECT_DIR)/External/build/lib",
     				);
     				MODULEMAP_FILE = ObjectiveGit.modulemap;
    @@ -1702,6 +1702,7 @@
     				);
     				PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
     				PRODUCT_NAME = ObjectiveGit;
    +				VALID_ARCHS = "x86_64 arm64";
     				WRAPPER_EXTENSION = framework;
     			};
     			name = Debug;
    @@ -1716,7 +1717,7 @@
     				INFOPLIST_FILE = Info.plist;
     				LIBRARY_SEARCH_PATHS = (
     					"$(inherited)",
    -					/usr/local/opt/openssl/lib,
    +					"/opt/homebrew/opt/openssl@3/lib",
     					"$(PROJECT_DIR)/External/build/lib",
     				);
     				MODULEMAP_FILE = ObjectiveGit.modulemap;
    @@ -1731,6 +1732,7 @@
     				);
     				PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
     				PRODUCT_NAME = ObjectiveGit;
    +				VALID_ARCHS = "x86_64 arm64";
     				WRAPPER_EXTENSION = framework;
     			};
     			name = Release;
    @@ -1956,7 +1958,7 @@
     				INFOPLIST_FILE = Info.plist;
     				LIBRARY_SEARCH_PATHS = (
     					"$(inherited)",
    -					/usr/local/opt/openssl/lib,
    +					"/opt/homebrew/opt/openssl@3/lib",
     					"$(PROJECT_DIR)/External/build/lib",
     				);
     				MODULEMAP_FILE = ObjectiveGit.modulemap;
    @@ -1971,6 +1973,7 @@
     				);
     				PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
     				PRODUCT_NAME = ObjectiveGit;
    +				VALID_ARCHS = "x86_64 arm64";
     				WRAPPER_EXTENSION = framework;
     			};
     			name = Test;
    @@ -2176,7 +2179,7 @@
     				INFOPLIST_FILE = Info.plist;
     				LIBRARY_SEARCH_PATHS = (
     					"$(inherited)",
    -					/usr/local/opt/openssl/lib,
    +                    "/opt/homebrew/opt/openssl@3/lib",
     					"$(PROJECT_DIR)/External/build/lib",
     				);
     				MODULEMAP_FILE = ObjectiveGit.modulemap;
    @@ -2191,6 +2194,7 @@
     				);
     				PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
     				PRODUCT_NAME = ObjectiveGit;
    +				VALID_ARCHS = "x86_64 arm64";
     				WRAPPER_EXTENSION = framework;
     			};
     			name = Profile;
    • In the root patch the GitX codeproj:
    diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj
    index 716b86f7..d9b0ccc2 100644
    --- a/GitX.xcodeproj/project.pbxproj
    +++ b/GitX.xcodeproj/project.pbxproj
    @@ -1731,6 +1731,7 @@
     				MACOSX_DEPLOYMENT_TARGET = 10.11;
     				PRODUCT_BUNDLE_IDENTIFIER = net.phere.GitX;
     				PRODUCT_NAME = GitX;
    +				VALID_ARCHS = "x86_64 arm64";
     				VERSIONING_SYSTEM = "apple-generic";
     				WRAPPER_EXTENSION = app;
     			};
    @@ -1752,6 +1753,7 @@
     				PRODUCT_BUNDLE_IDENTIFIER = net.phere.GitX;
     				PRODUCT_NAME = GitX;
     				STRIP_INSTALLED_PRODUCT = YES;
    +				VALID_ARCHS = "x86_64 arm64";
     				VERSIONING_SYSTEM = "apple-generic";
     				WRAPPER_EXTENSION = app;
     			};
    @@ -1804,7 +1806,7 @@
     				RUN_CLANG_STATIC_ANALYZER = YES;
     				SDKROOT = macosx;
     				STRIP_INSTALLED_PRODUCT = NO;
    -				VALID_ARCHS = x86_64;
    +				VALID_ARCHS = "x86_64 arm64";
     			};
     			name = Debug;
     		};
    @@ -1847,10 +1849,11 @@
     				);
     				LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
     				MACOSX_DEPLOYMENT_TARGET = 10.11;
    +				ONLY_ACTIVE_ARCH = NO;
     				OTHER_CFLAGS = "-Werror=incompatible-pointer-types";
     				RUN_CLANG_STATIC_ANALYZER = YES;
     				SDKROOT = macosx;
    -				VALID_ARCHS = x86_64;
    +				VALID_ARCHS = "x86_64 arm64";
     			};
     			name = Release;
     		};
    • Now run Scripts/build.py. This should give you a debug build. (I couldn't get a release build working).
  7. hannesa2 commented on Nov 25, 2021

    @hannesa2
    ContributorAuthor

    @simoncozens Nice, please don't hesitate to bring the stuff to https://github.com/gitx/objective-git as well as a pull request.
    In the meantime, I try to find a solution to get it merged without an active maintainer there. (I'm only a member there and no maintainer)

  8. jspiro commented on Nov 25, 2021

    @jspiro
    Member

    Nice work!

    So the challenge is how do we support cross compiling, right? Your diff at a glance looks like what I tried to do, but this will only build on ARM, and not macs with intel brew installs.

    I asked in the brew community what the intended solution is to this and they had no real answers. I'm surprised they'd make such a big change without much of a support plan, especially a change that really isn't required with Rosetta 2.

    Am I missing anything? I'll give your instructions a try soon, and we can publish a beta build for M1 users.

  9. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    I gave it a go! I haven't debugged this much, wondering if you encountered this issue?

    λ ./Scripts/build.py debug
    Building scheme GitX (debug), please wait…
    --- xcodebuild: WARNING: Using the first of multiple matching destinations:
    { platform:macOS, arch:arm64, id:00006001-000209380C04801E }
    { platform:macOS, arch:x86_64, id:00006001-000209380C04801E }
    { platform:macOS, name:Any Mac }
    ** BUILD FAILED **
    
    
    The following build commands failed:
    	Ld /Users/jspiro/Coding/Github/gitx/build/Debug/ObjectiveGit.framework/Versions/A/ObjectiveGit normal (in target 'ObjectiveGit-Mac' from project 'ObjectiveGitFramework')
    (1 failure)
    Traceback (most recent call last):
      File "./Scripts/build.py", line 40, in <module>
        args.func(args)
      File "./Scripts/build.py", line 31, in build_cmd
        build(project)
      File "./Scripts/build.py", line 14, in build
        helpers.xcodebuild(project.scheme(), project.workspace(), project.current_build_config(), ["build"], project.build_base_dir())
      File "/Users/jspiro/Coding/Github/gitx/Scripts/helpers.py", line 53, in xcodebuild
        raise BuildError(str(e))
    helpers.BuildError: Command '['xcrun', 'xcodebuild', '-workspace', u'GitX.xcworkspace', '-scheme', u'GitX', '-configuration', 'Debug', 'build', 'BUILD_DIR=/Users/jspiro/Coding/Github/gitx/build']' returned non-zero exit status 65
    

    Not clear what's wrong. I did find more references to /usr in e.g. libgit2 and other places. Any chance there are more patches needed, or other brew packages required?

  10. simoncozens commented on Nov 26, 2021

    @simoncozens

    Can you try running xcrun xcodebuild -workspace GitX.xcworkspace without the build.py wrapper? I can't actually see what the error is from that output.

    Cross-compiling is tricky because you will have to build everything up the dependency chain: Objective-Git, libgit2, libssh2, etc. I'm having to do this currently with pygit2 and it's a pain. Hopefully one day there will be GitHub Apple silicon runners...

  11. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    <rant>Re cross-compiling, I meant moreso it's not clear how to have an xcode project, for example, that can link equally for ARM or X86, given these paths are hard-coded in hundreds of places. I suppose you'd have to duplicate all targets separately for ARM and X86 to have different paths... which is ridiculous, and breaks a decade of open source for Mac. I really don't get why brew did this–they say /usr is for Intel-only... but contextually, on an ARM system, wouldn't it just have ARM code? I'd assume the architecture would be implicit. But I digress.</>

    Ah, cool, that's more useful output. I learned something! I ran this:
    xcrun xcodebuild -workspace ObjectiveGitFramework.xcworkspace -scheme 'ObjectiveGit Mac'

    Attaching the changes I have had to make so far and the build output. It's a linker error with libssh2 not having ARM versions, despite it being ARM-native on Monterey:

    lipo -archs /opt/homebrew/lib/libssh2.a
    arm64
    

    There's probably an Xcode setting I am not familiar with to select the right arch in linking. Search for the word warning and you'll see it.

    diff.txt
    out.txt

    So I'm wondering how it works on your system. Did you, perhaps, migrate from an Intel to M1 from a backup? I am on a new MBP with a clean install, perhaps why I cannot build it.

  12. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    I've noticed that libgit2 is building X86 libraries, perhaps this is related:

    lipo -archs /Users/jspiro/Coding/Github/gitx/External/objective-git/External/libgit2.a
    x86_64
    
  13. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    I figured it out:

    diff --git a/script/update_libgit2 b/script/update_libgit2
    index 15123174..f26927e2 100755
    --- a/script/update_libgit2
    +++ b/script/update_libgit2
    @@ -2,10 +2,10 @@
    
     set -e
    
    -# augment path to help it find cmake installed in /usr/local/bin,
    -# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
    +# augment path to help it find cmake installed by e.g. brew.
    +# Xcode's Run Script phase doesn't seem to honor
     # ~/.MacOSX/environment.plist
    -PATH="/usr/local/bin:$PATH"
    +PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
    
     if [ "External/libgit2.a" -nt "External/libgit2" ]
     then
    

    Not sure if all of the previous diff lines are required, but this definitely is (on my system, since cmake installs into /opt as well).

  14. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    Here is a release build based on the above:
    GitX.app.zip

  15. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    So, what do we think are next steps? Ideally we could do a Universal binary and we'd be golden. Unclear if this would work on GitHub Actions, but it's the first promising lead I found:
    actions/runner-images#2187 (comment)

    We should get someone else with an M1 to try out the changes and test the builds. But then we need an experienced Xcode developer (maybe you!) to guide the right approach for this: we need something that is mergeable without breaking non-ARM builds.

    And it's unclear what we do with ObjectiveGit along the same lines. It might be as simple as adding both /opt and /usr to the library search paths in both projects.

    We can publish an ARM build ahead of that or off a branch to unblock folks moving to M1s.

  16. 1 remaining item

  17. hannesa2 commented on Nov 26, 2021

    @hannesa2
    ContributorAuthor

    Here is a release build based on the above: GitX.app.zip

    ❤️
    Please @jspiro can you make pullrequests/branches to have a chance to follow what you did exactly ?

  18. jspiro commented on Nov 26, 2021

    @jspiro
    Member

    Yep, I am just finding a minimal set of required changes.

  19. jspiro commented on Nov 26, 2021

    @jspiro
    Member
  20. tcurdt commented on Dec 3, 2021

    @tcurdt

    I just tried the above build and got terminated (on 12.0.1)

    Termination Reason:    Namespace DYLD, Code 1 Library missing
    Library not loaded: /opt/homebrew/*/libcrypto.3.dylib
    Referenced from: /Applications/GitX.app/Contents/Frameworks/ObjectiveGit.framework/Versions/A/ObjectiveGit
    Reason: tried: '/opt/homebrew/*/libcrypto.3.dylib' (no such file), '/usr/local/lib/libcrypto.3.dylib' (no such file), '/usr/lib/libcrypto.3.dylib' (no such file)
    (terminated at launch; ignore backtrace)
    

    I assume it fails to find the library that is expected to come from homebrew - but libcrypto is not even mentioned here:

    $ otool -L GitX.app/Contents/MacOS/GitX 
    GitX.app/Contents/MacOS/GitX:
    	@loader_path/../Frameworks/MGScopeBar.framework/Versions/A/MGScopeBar (compatibility version 1.0.0, current version 1.0.0)
    	@rpath/Sparkle.framework/Versions/A/Sparkle (compatibility version 1.6.0, current version 1.24.0)
    	@rpath/ObjectiveGit.framework/ObjectiveGit (compatibility version 1.0.0, current version 1.0.0)
    	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
    	/System/Library/Frameworks/WebKit.framework/Versions/A/WebKit (compatibility version 1.0.0, current version 612.1.29)
    	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 60157.30.13)
    	/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1163.30.6)
    	/System/Library/Frameworks/ScriptingBridge.framework/Versions/A/ScriptingBridge (compatibility version 1.0.0, current version 1.0.0)
    	/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
    	/System/Library/Frameworks/Quartz.framework/Versions/A/Quartz (compatibility version 1.0.0, current version 1.0.0)
    	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1141.1.0)
    	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1853.0.0)
    	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
    	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
    	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2103.13.10)
    	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1853.0.0)
    	/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1557.1.1)
    

    Why that path?

  21. hannesa2 commented on Dec 3, 2021

    @hannesa2
    ContributorAuthor

    @tcurdt Please try this steps #234 (comment) and tell me what you see

  22. tcurdt commented on Dec 3, 2021

    @tcurdt

    @hannesa2 I've added the error to #234. Linking fails for me with those steps.

  23. ronaldtse commented on Dec 16, 2021

    @ronaldtse

    I just tried the above build and got terminated (on 12.0.1)

    FYI my colleague @kwkwan ran into this issue today. Installation of brew OpenSSL is required to run the build provided above as it tries to load /opt/homebrew/*/libcrypto.3.dylib (as per #204 (comment)).

    brew install openssl
  24. hannesa2 commented on Dec 16, 2021

    @hannesa2
    ContributorAuthor

    Just for your info: I already added openssl gitx/objective-git#16 but the M1 branch doesn't include it

    image

  25. ronaldtse commented on Dec 16, 2021

    @ronaldtse

    Thank you @hannesa2 !

  26. hannesa2 commented on Feb 13, 2022

    @hannesa2
    ContributorAuthor

    I applied all changes to recent master and we are able to build with x86 too, but when I try build local on my M1

    xcodebuild -workspace GitX.xcworkspace -scheme GitX -archivePath ./GitX archive ARCHS="arm64"

    image

    @jspiro @ronaldtse @felixpalmer @tcurdt
    Please can you try this ?
    Does someone knows how to get rid of it ?

  27. hannesa2 commented on Feb 13, 2022

    @hannesa2
    ContributorAuthor

    After this #273 the recent master looks like this on my M1

    image

  28. hannesa2 commented on Feb 13, 2022

    @hannesa2
    ContributorAuthor

    It builds now locally with a M1 #275

    Thanks a lot @claytonrcarter !

  29. hannesa2 commented on Feb 13, 2022

    @hannesa2
    ContributorAuthor
  30. ronaldtse commented on Feb 14, 2022

    @ronaldtse

    Thank you @hannesa2 for making this available!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions