这是indexloc提供的服务,不要输入任何密码
Skip to content

Add support for DarwinArchs when assembling macOS App.framework #81243

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

Merged
merged 12 commits into from
Apr 28, 2021

Conversation

knopp
Copy link
Member

@knopp knopp commented Apr 26, 2021

#81205

This can be used to specify target architectures and produce fat binaries.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 26, 2021
@google-cla google-cla bot added the cla: yes label Apr 26, 2021
@knopp knopp force-pushed the darwin_architectures branch 4 times, most recently from 26454e6 to eebf222 Compare April 27, 2021 13:22
@knopp knopp changed the title WIP: Add support for DarwinArchs when assembling macOS App.framework Add support for DarwinArchs when assembling macOS App.framework Apr 27, 2021
@knopp knopp requested a review from jonahwilliams April 27, 2021 14:13
@knopp knopp force-pushed the darwin_architectures branch from 2fabd56 to 03b23e2 Compare April 27, 2021 14:41
@knopp knopp requested a review from jmagman April 27, 2021 15:38
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

We should have some example unit tests for the iOS lipo you could copy from for the macOS example

@knopp
Copy link
Member Author

knopp commented Apr 27, 2021

I'll look at the tests for lipo. Also debug build only produces x86_64 framework, I'll fix that too.

@@ -311,7 +311,7 @@ class AOTSnapshotter {
TargetPlatform.android_arm64,
TargetPlatform.android_x64,
TargetPlatform.ios,
TargetPlatform.darwin_x64,
TargetPlatform.darwin,
Copy link
Member

Choose a reason for hiding this comment

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

I agree with you in #81205 (comment)

It does feel a bit off that there is TargetPlatform.ios and --define=IosArchs=... and then TargetPlatform.darwin. But iOS is darwin. It really should be TargetPlatform.macOS and --define=MacOSArchs=....

Just glancing at this I wouldn't be sure which to use (the confusion predates this PR). This also gets hairier when we start targeting iOS apps as native ARM mac apps for the unfortunately named "Mac Designed for iPad" #66184.

I'd be supportive if you wanted to rename this macos instead of darwin.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be supportive if you wanted to rename this macos instead of darwin.

I'll keep that in mind, but I'm not sure I'd want to do it in this PR.

@knopp
Copy link
Member Author

knopp commented Apr 27, 2021

I added lipo tests for both framework thinning and universal binary.

@@ -103,6 +103,14 @@ enum HostArtifact {
pubExecutable,
}

// TODO(knopp): Remove once darwin artifacts are moved out of darwin-x64
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we're going to move darwin artifacts out of darwin-x64. We'll still have different engine builds for darwin-x64 and darwin-arm - the target platform is best though of as a convenience for how the engine builds think of targets that was incorrectly extended to how our users interact with the platforms.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do you need different engine builds? Can you just have universal FlutterMacOS.framework (just like you have universal Flutter.framework for ios)? The PR already implements framework thinning.

I assumed that all the artifacts would be distributed as universal in the end.

Copy link
Contributor

Choose a reason for hiding this comment

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

No better answer than "that is how the engine builds are configured currently".

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, sure, but I assumed that at some point there's going to be work done to build the engine for darwin-x64, darwin-arm64 and lipo them together. Isn't that the whole purpose of not having separate TargetPlatform.darwin_x64 and .darwin_arm64?

Somehow this is done for iOS, why can't it be done for macOS? (plus flutter_tester, font-subset and gen_snapshot).

CachedArtifacts doesn't know about DarwinArchs so I don't quite see how it would choose the right folder if you want to distribute darwin-arm64 build separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could certainly do that work, but there is no point in changing the cache structure in the tool before that is done

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't assume this would happen before having universal artifacts. There's no point in doing that. I'll clarify that in the TODO comment.

Copy link
Member

Choose a reason for hiding this comment

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

Quasi related for distribution but I suggested combining the macOS framework into the iOS Flutter.xcframework #70413 though considering how unfortunately different the two platform projects look, and how manual it was to get the right framework slice out of the iOS xcframework, I'm not now sure if that will be very valuable. In any case, we should distribute a universal macOS framework. But no one has worked on that yet.

Copy link
Member Author

@knopp knopp Apr 27, 2021

Choose a reason for hiding this comment

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

Well, I have no clue how flutter builds work on server side so I'm not sure I can help with that :) However with recent changes landed in buildroot and engine it is now possible to cross compile flutter for darwin-arm64. But it requires manually editing args.gn. I think the next step would be to add darwin cross compilation to flutter/tools/gn. I'll open an issue for it.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM if LG to @jmagman

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @knopp!

@jmagman jmagman merged commit f6726b4 into flutter:master Apr 28, 2021
@zanderso
Copy link
Member

zanderso commented Jan 21, 2022

@knopp @jonahwilliams @jmagman I'm having a bit of trouble following the discussion and determining what the missing pieces are. This PR seems to be making some assumptions about how the arm64 artifacts will be supplied and consumed. Can someone ELI5 what those are for me? (e.g. libflutter.so)

@jonahwilliams
Copy link
Contributor

So IIRC the idea was that we'd change how we were handling architecture - instead of having platform + arch in one enum this changes macos to be more like ios where the platform and arch are separate flags. I don't remember if any additional work was done to support arm64 builds.

@jmagman
Copy link
Member

jmagman commented Jan 21, 2022

Exactly, instead of macOS platform being specified darwin_x64 instead it's darwin + either x86_64 or arm64. It was mostly refactoring for the sake of the enums.

@zanderso I can do the outstanding in the tool to stop using Rosetta once there's an arm FlutterMacOS.framework, if that's what you're exploring. I already had to do it for iOS, and it'll be easier with macOS since it's the same artifact paths, but with an extra architecture lipo'd in.

@knopp
Copy link
Member Author

knopp commented Jan 21, 2022

wing the discussion and determining what the missing pieces are. This PR seems to be making some assumptions about how the arm64 artifacts will be supplied and consumed. Can someone ELI5 what those are for me? (e.g. libflutter.so)

This is similar to how iOS work. Flutter tool can produce fat binaries for App.framework and strip unneeded architectures from FlutterMacOS.framework. IIRC what's left to do is mostly

  • Produce fat binary for FlutterMacOS.framework. We can already cross compile the framework for ARM64, just need script to lipo the framework and other desktop artifacts and add that to Luci.
  • Modify the paths in tool to download and use universal framework
  • Modify the tool to stop using rosetta (don't launch build through arch)

@knopp
Copy link
Member Author

knopp commented Jan 21, 2022

Exactly, instead of macOS platform being specified darwin_x64 instead it's darwin + either x86_64 or arm64. It was mostly refactoring for the sake of the enums.

Actually, it can be both x86_64 and arm64. Tool should build snapshot for all architectures and then lipo them together.

@zanderso
Copy link
Member

How about gen_snapshot? I think the gen_snapshot_arm64 from the ios artifacts will work. Can the desktop build also use that?

@jmagman
Copy link
Member

jmagman commented Jan 22, 2022

Exactly, instead of macOS platform being specified darwin_x64 instead it's darwin + either x86_64 or arm64. It was mostly refactoring for the sake of the enums.

Actually, it can be both x86_64 and arm64. Tool should build snapshot for all architectures and then lipo them together.

Yes, I meant the targeted platform can be described as darwin+x86_64 or darwin+arm64.

@jmagman
Copy link
Member

jmagman commented Jan 22, 2022

How about gen_snapshot? I think the gen_snapshot_arm64 from the ios artifacts will work. Can the desktop build also use that?

If the same gen_snapshot_arm64 works (not sure if it does) then we'd also need to either ship it in the macos artifacts, or update the tool to always require the iOS artifacts to be downloaded. Either way, need tooling work to detect the current arch and choose the appropriate gen_snapshot if they can't be lipo'd together.

@knopp
Copy link
Member Author

knopp commented Jan 22, 2022

How about gen_snapshot? I think the gen_snapshot_arm64 from the ios artifacts will work. Can the desktop build also use that?

If the same gen_snapshot_arm64 works (not sure if it does) then we'd also need to either ship it in the macos artifacts, or update the tool to always require the iOS artifacts to be downloaded. Either way, need tooling work to detect the current arch and choose the appropriate gen_snapshot if they can't be lipo'd together.

Why couldn't gen_snapshot be lipod together?

@knopp knopp deleted the darwin_architectures branch January 22, 2022 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants