J2ObjC with Apple M1

234 views
Skip to first unread message

Fraser Kettle

unread,
Feb 23, 2021, 11:52:44 AMFeb 23
to j2objc-discuss
Hello!

I've recently switched from an Intel, x86_64 Macbook Pro to an M1, arm64 Macbook Pro. I'm now unable to run tests for my project using the iOS simulator:

In /Users/fraser/Library/j2objc/j2objc-2.7/lib/libjre_emul.a(ErrnoException.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/fraser/Library/j2objc/j2objc-2.7/lib/libjre_emul.a' for architecture arm64

I've tried various fixes, such as Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 - Stack Overflow, so far unscucessfully.

I wonder if you've encountered this before? Is a change is required in J2ObjC, or do you believe that there is nothing about J2ObjC which would be affected by the switch from an Intel to an M1 chip?

Many thanks!
Fraser

Tom Ball

unread,
Feb 23, 2021, 12:36:28 PMFeb 23
to j2objc-discuss
First, congratulations on the M1! Google has so many iOS engineers queued up for an upgrade that I'll probably retire before I ever see one. :-)

Are you using the last distribution bundle, j2objc-2.7? It was released right before Apple released Xcode 12, and so doesn't include the arm64 architecture slice for Macs. That can be built from j2objc latest source, which automatically includes macosx64 unless you define a J2OBJC_ARCHS subset as an environment variable (if so, just add macosx64 to that list). 

FYI, there's no reason to be concerned about using a source build instead of a release distribution. Google's iOS apps always build with j2objc's HEAD commit, so there's no quality difference -- our distribution bundles are just to make things a little easier for new j2objc users.

If you're building with the latest source and have added the arm64 arch to the Excluded Architectures->Any iOS Simulator SDK lists, then I'm out of ideas. Since we don't have M1s, support for them has come from external contributions from developers (like this one). If you find a solution, please let us know, and if you need any help with our maze of twisty little make passages, don't hesitate to ask.



--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/560e464e-13ff-4379-9e8e-297b4fe83cean%40googlegroups.com.

Fraser Kettle

unread,
Feb 25, 2021, 12:45:25 PMFeb 25
to j2objc-discuss
Hi Tom,

Thanks so much for the speedy and detailed reply! I was using 2.7 so have given building from source a go (3fed4d2). Unfortunately I'm getting a build error on the M1 which I can't find an example of on the discussion group or the GitHub issues:

  j2objc git:(master) make all_dist WARNINGS=-Wno-unsequenced
Locale: en_GB.UTF-8
Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64
Xcode 12.4 Build version 12D4e
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Environment:
COMMAND_MODE=unix2003
J2OBJC_ARCHS=iphone64 simulator64 macosx64
JAVA_HOME=/opt/homebrew/Cellar/openjdk@11/11.0.9/libexec/openjdk.jdk/Contents/Home
LANG=en_GB.UTF-8
MAKEFLAGS=WARNINGS=-Wno-unsequenced
MAKELEVEL=1
MAKEOVERRIDES=${-*-command-variables-*-}
PROTOBUF_ROOT_DIR=/opt/homebrew
WARNINGS=-Wno-unsequenced
...
/opt/homebrew/bin/protoc --plugin=protoc-gen-j2objc=../../dist/j2objc_protoc_plugin --proto_path=/opt/homebrew/include --j2objc_out=/Users/fraser/source/j2objc/protobuf/runtime/build_result/objc /opt/homebrew/include/google/protobuf/descriptor.proto
compiling src/com/google/protobuf/AbstractMessage.m
compiling src/com/google/protobuf/AbstractMessageLite.m
compiling src/com/google/protobuf/ByteString.m
compiling src/com/google/protobuf/CodedInputStream.mm
error: invalid argument '--std=c17' not allowed with 'Objective-C++'
make[1]: *** [/Users/fraser/source/j2objc/protobuf/runtime/build_result/objs-iphone64/com/google/protobuf/CodedInputStream.o] Error 1
make: *** [protobuf_runtime_dist] Error 2

(hopefully that's enough context).

Note that I wasn't able to install prot...@3.11.1 through homebrew, as specified here, due to cask not found, again I think related to being on an M1. I plumped for what homebrew gave me, which was 13.4.0. I'm willing to believe this as a cause of the issue (the error occurs when compiling protobuf code), but thought I'd check here anyway.

Kind regards,
Fraser

Tom Ball

unread,
Feb 25, 2021, 7:59:14 PMFeb 25
to j2objc-discuss
Oh, sorry, I broke that last week when updating the j2objcc script. Do a git pull and your build should finish successfully.

That previous commit supported the script accepting the --std=nnnn flag, defaulting to --std=c17. That unfortunately only worked for .mm files if the command also contained "-x objective-c++"; clang compiles .mm files as Objective-C++ if that flag isn't specified, so j2objcc told clang to compile an Objective-C++ file using the c17 standard.

Harri Hohteri

unread,
May 17, 2021, 3:26:55 PMMay 17
to j2objc-discuss
Hi Tom,

I know arm64-ios-simulator and arm64-maccatalyst are not yet supported (or what I glanced at the source) but I found https://github.com/google/j2objc/issues/1516 and the according PR https://github.com/google/j2objc/pull/1517. My question is as this is not included in the 2.8 distribution version, is that a deliberate move? As we pretty much use GitHub releases for development so I'd like to understand if it would be part of the framework build eventually. I also find it interesting that static library distribution is a fat file and frameworks one isn't (see below).

As both arm64-ios-simulator and arm64-maccatalyst inside a xcframework need to be fat-binaries with their x86_64 counterparts, otherwise you'll get an xcode error, did you follow up with that commit as requested in https://github.com/google/j2objc/issues/1516

$ lipo -info /usr/local/j2objc-2.8/lib/macosx/libjre_emul.a 

Architectures in the fat file: /usr/local/j2objc-2.8/lib/macosx/libjre_emul.a are: x86_64 

$ lipo -info /usr/local/j2objc-2.8/frameworks/JRE.xcframework/macos-x86_64/libjre_emul.a 

Non-fat file: /usr/local/j2objc-2.8/frameworks/JRE.xcframework/macos-x86_64/libjre_emul.a is architecture: x86_64

Thanks,
Harri

Tom Ball

unread,
May 17, 2021, 3:48:38 PMMay 17
to j2objc-...@googlegroups.com
Yes, this should be addressed in https://github.com/google/j2objc/issues/1567, fixed last week. I still don't have access to M1 hardware, but was able to verify the build problem independently and then fix it.

To get this change, clone the j2objc repository (https://github.com/google/j2objc), then build normally (https://developers.google.com/j2objc/guides/building-j2objc).

Harri Hohteri

unread,
May 18, 2021, 4:39:38 PMMay 18
to j2objc-discuss
Here is the PR (https://github.com/google/j2objc/pull/1685), it has two features (and one side effect):

1) Fixing building on M1 Mac (one note here, protobuf 3.11.1 doesn't exist for arm64, I used the latest in brew 3.15.8)
2) Adding arm64 simulator
3) Removing i386 simulator. Due to the way xcframeworks are build I renamed x86_64 to simulator and arm64 to simulator64. Alternatively you could keep them all and always build i386 as well.

Harri

P.S. I only tested with J2OBJC_ARCHS="iphone64 simulator simulator64" make framework as building takes ages.

Harri Hohteri

unread,
May 18, 2021, 4:43:36 PMMay 18
to j2objc-discuss
And you might also want to remove simulator from dist lib folder...

Tom Ball

unread,
May 24, 2021, 1:20:51 PMMay 24
to j2objc-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages