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 building for architectures other than x86_64 on macOS (Apple Silicon) #185

Merged
merged 5 commits into from
Oct 23, 2020

Conversation

liamnichols
Copy link
Contributor

@liamnichols liamnichols commented Jul 31, 2020

Closes #184 (cc @amine2233)

As identified in the linked PR, hardcoding the target when forming the swift build command on macOS has become a limiting factor when supporting Apple Silicon. Thankfully @esteluk already provided a viable work around that preserves some other requirements defined in #58.

I've taken the two suggestions and formed them into a single PR that should hopefully be good to go 🤞

I can confirm that this does the job nicely on Apple Silicon by using Realm's SwiftLint as a test project since your SimplePackage is too simple to throw up any build error in the tests. If it helps I can try and help you to expand that package a bit to reproduce the issue but I'm not sure how important that is.

@esteluk
Copy link

esteluk commented Jul 31, 2020

Ahh thanks Liam!

Comment on lines +4 to +16
final class ProcessInfoExtensionTests: XCTestCase {
#if arch(x86_64)
func testMachineHardwareName_Intel() {
XCTAssertEqual(ProcessInfo.processInfo.machineHardwareName, "x86_64")
}
#endif

#if arch(arm64)
func testMachineHardwareName_AppleSilicone() {
XCTAssertEqual(ProcessInfo.processInfo.machineHardwareName, "arm64")
}
#endif
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there is a better way to test this.. While we only need for machineHardwareName for macOS, it should also work for Linux as well.

I was going to use XCTSkipIf(true, "...") but that's Xcode 11.4+ whereas we need to support Xcode 10.2+.

/// Returns a `String` representing the machine hardware name or nil if there was an error invoking `uname(_:)` or decoding the response.
///
/// Return value is the equivalent to running `$ uname -m` in shell.
var machineHardwareName: String? {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if I am being too strict here? Could this be non-optional and either just force unwrap or return an empty string in the (unlikely) event of a failure?

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

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

This is great, thank you @liamnichols. Sorry for the delay on this.
I'll assume this is ready to go even if it's in a draft state

@yonaskolb yonaskolb marked this pull request as ready for review October 23, 2020 10:44
@yonaskolb yonaskolb merged commit 06f3914 into yonaskolb:master Oct 23, 2020
@liamnichols
Copy link
Contributor Author

Yep this was good to go @yonaskolb although I did have a question here: #184 (comment)

Basically, do we still need the deployment target workaround that causes us to have to specify this target in the first place?


In addition, you might also want to update the Makefile to support distributing a universal binary

https://github.com/yonaskolb/XcodeGen/blob/9fdc194771168c9128bf7833edbf16391b1b848d/Makefile#L22

The above would become the following:

swift build --disable-sandbox -c release --arch arm64 --arch x86_64

(see https://liamnichols.github.io/2020/08/01/building-swift-packages-as-a-universal-binary.html)

This will likely be required when creating a Homebrew Bottle for Big Sur, but will require Xcode 12 so I'm not sure what implications that has as I think the project supposedly still supports Xcode 10.2?

Maybe I can move this discussion into a new issue if it requires a bit more thinking though

@liamnichols liamnichols deleted the ln/apple-silicon branch October 23, 2020 10:51
@yonaskolb
Copy link
Owner

In terms of requiring the deployment target, I would say technically we don't need it, but practically it might be useful. Many package authors haven't specified their deployment targets, and in this case adding it will fix issues. I may be wrong there though?

In regards to the universal binary, thanks for the heads up. Do you think it will be ok to make the brew formula require 12 but keep the package itself at 10.2? I'm happy to update the whole package as well if needed. As you say a new issue is best.

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.

3 participants