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

Support ARM64 macOS builds #86

Merged
merged 2 commits into from
Jul 28, 2020

Conversation

DarkDust
Copy link
Contributor

This provides basic support for building OpenSSL on macOS for ARM64 as well.

This pull request needs to make a number of changes:

  • First, a check whether to actually compile for macOS ARM64 is made, based on the SDK version.
    • This is not completely correct right now as Apple provides two Xcode 12 betas, one with macOS ARM64 support and one without. But the final Xcode release is going to be just one Xcode build which supports everything.
  • The build directories and logs, which previously were only differentiated by architecture, now also include the OS in their names (e.g. 1.0.2u-MacOSX-arm64.build.log) since there are now two (or three) OSs which build for ARM64.
  • While I was at it, I also split up the log files into .config. and .build. so that the later doesn't overwrite the former any more.
  • There's no darwin64-arm64-cc target in OpenSSL, but iphone-cross seems to work just fine when given the macOS SDK.
  • The macOS build process has been moved into build() and that function was refactored a bit.
  • build()'s second argument is now repurposed (and renamed) to OS as the SDK wasn't needed at that point any more, but OS was.
  • I needed to introduce a config file for Xcode, OpenSSL.xcconfig, to work around a current limitation in Xcode 12 beta (see below).

Known issues/limitations

  • Xcode 12 beta does not support building iPhoneSimulator for ARM64 yet.
    • The build script has a dedicated variable BUILD_IPHONESIMULATOR_ARM64 because of that. It's currently never set, once Xcode does support building iPhoneSimulator for ARM64 we can set it.
    • However, we would need to solve a conflict in the headers between iOS ARM64 and iPhoneSimulator ARM64 then. Haven't bothered to do this yet since it's possible Apple never support iPhoneSimulator ARM64 since ARM-based Macs are going to be able to run iOS apps natively.
    • Xcode needs to be told not to try to link iPhoneSimulator ARM64. That's what the OpenSSL.xcconfig is for.
  • In my builds, the iOS libcrypto.a and libssl.a contain the armv7s architecture, but the final OpenSSL.framework does not. I don't know why, yet.
  • Xcode 12 only supports minimum deployment targets of iOS 9.0 (IIRC) and macOS 10.9. The binaries do contain the entries for iOS 8.0 and macOS 10.8 but it might be a good idea to raise the deployment targets in the project and podspec.

@DarkDust
Copy link
Contributor Author

Correction: The frameworks produced with Xcode 12 beta do have the minimum deployment targets set to iOS 8.0 and macOS 10.9, even though iOS 6.0 and macOS 10.8 were passed to the compiler (which, funnily enough, is visible inside the final binaries).

@krzyzanowskim
Copy link
Owner

this is fantastic! I'll back to it ASAP

@krzyzanowskim
Copy link
Owner

@DarkDust just to clarify. With these changes, does it still build with Xcode 11?

@krzyzanowskim
Copy link
Owner

Something is off with result. After I run the script, macos result is missing

./build.sh
Building for iPhoneSimulator i386
Configuring for iPhoneSimulator.platform i386
Building /var/folders/2_/tt78sncj6p9fbmkn7808254h0000gn/T/tmp.2dMv5WRe/1.0.2u-iPhoneSimulator-i386.build.log
Building for iPhoneSimulator x86_64
Configuring for iPhoneSimulator.platform x86_64
Building /var/folders/2_/tt78sncj6p9fbmkn7808254h0000gn/T/tmp.2dMv5WRe/1.0.2u-iPhoneSimulator-x86_64.build.log
Building for iPhoneOS armv7
Configuring for iPhoneOS.platform armv7
Building /var/folders/2_/tt78sncj6p9fbmkn7808254h0000gn/T/tmp.2dMv5WRe/1.0.2u-iPhoneOS-armv7.build.log
Building for iPhoneOS armv7s
Configuring for iPhoneOS.platform armv7s
Building /var/folders/2_/tt78sncj6p9fbmkn7808254h0000gn/T/tmp.2dMv5WRe/1.0.2u-iPhoneOS-armv7s.build.log
Building for iPhoneOS arm64
Configuring for iPhoneOS.platform arm64
Building /var/folders/2_/tt78sncj6p9fbmkn7808254h0000gn/T/tmp.2dMv5WRe/1.0.2u-iPhoneOS-arm64.build.log
Building for MacOSX x86_64
Configuring for MacOSX.platform x86_64
Building /var/folders/2_/tt78sncj6p9fbmkn7808254h0000gn/T/tmp.iHj3nIE5/1.0.2u-MacOSX-x86_64.build.log

Screenshot 2020-07-13 at 22 38 36

@DarkDust
Copy link
Contributor Author

Oh, sorry, I‘ll look into this tomorrow.

We can't just build it using the SDK version and other information, as the reported version may be different from the SDK path (e.g. 10.15.4 for the version, but the actual SDK path has just 10.15).
@DarkDust
Copy link
Contributor Author

I found the problem: even though the SDK version is 10.15.4, the SDK path is .../Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk (note the missing .4). I've changed the derivation of CROSS_TOP and CROSS_SDK (used by the OpenSSL configure/makefile) to derive it from the actual SDK path instead.

This means we don't need the *_SDK_VERSION and *_PLATFORM variables any more (except for OSX_SDK_VERSION to decide whether to build for ARM64).

The updated version now builds both with Xcode 11 and 12 beta.

9F4A2707223BD900005CB63A /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F4A2705223BD900005CB63A /* libssl.a */; };
9F4A2708223BD900005CB63A /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F4A2706223BD900005CB63A /* libcrypto.a */; };
9F4A2707223BD900005CB63A /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F4A2705223BD900005CB63A /* libssl.a */; platformFilter = ios; };
9F4A2708223BD900005CB63A /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F4A2706223BD900005CB63A /* libcrypto.a */; platformFilter = ios; };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it till build macOS version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krzyzanowskim It seems to be something Xcode 11 and above is setting. I don't know what effect this has, but I was able to build for macOS with Xcode 11.4.

@krzyzanowskim krzyzanowskim merged commit 6c7cf83 into krzyzanowskim:master Jul 28, 2020
@krzyzanowskim
Copy link
Owner

@DarkDust thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants