Skip to content

Conversation

@pbo-linaro
Copy link
Contributor

@pbo-linaro pbo-linaro commented Oct 24, 2022

This PR adds Windows on Arm as a known platform,
and an option --target-plaftorm to "build windows" command, similar to what exists for build-linux.

Default behavior was not changed. See commits for details.

Tested by building https://github.com/flutter/gallery with this.

Issue: #62597

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 this 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 Oct 24, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@pbo-linaro
Copy link
Contributor Author

As a native Windows on Arm system is needed to test this, I'm not sure it's possible to add automated test. If I'm wrong with it, don't hesitate to say!

@pbo-linaro
Copy link
Contributor Author

@cbracken @stuartmorgan Polite ping for this MR, as it's needed to enable Windows on Arm support. Does the approach sounds good to you?

@loic-sharma loic-sharma added platform-windows Building on or for Windows specifically a: desktop Running on desktop labels Nov 4, 2022
@loic-sharma
Copy link
Member

/cc @christopherfujino as this affects the Flutter tool

Copy link
Member

Choose a reason for hiding this comment

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

Please add unit tests to /packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart that verify this option works as expected

@loic-sharma
Copy link
Member

As a native Windows on Arm system is needed to test this, I'm not sure it's possible to add automated test. If I'm wrong with it, don't hesitate to say!

We won't be able to add integration tests for this yet, but, you should be able to unit test this change under the /packages/flutter_tools/test/ directory.

@codecov-commenter
Copy link

Codecov Report

Merging #113928 (9f6090c) into master (4c6251a) will decrease coverage by 0.65%.
The diff coverage is 89.53%.

❗ Current head 9f6090c differs from pull request most recent head bd79b48. Consider uploading reports for the commit bd79b48 to get more accurate results

@@             Coverage Diff             @@
##           master   #113928      +/-   ##
===========================================
- Coverage   91.46%    90.81%   -0.66%     
===========================================
  Files         523       531       +8     
  Lines       94569     95506     +937     
===========================================
+ Hits        86498     86730     +232     
- Misses       8071      8776     +705     
Impacted Files Coverage Δ
packages/flutter/lib/src/material/action_chip.dart 55.93% <ø> (ø)
...ib/src/material/animated_icons/animated_icons.dart 90.47% <ø> (ø)
...c/material/animated_icons/animated_icons_data.dart 100.00% <ø> (ø)
...ackages/flutter/lib/src/material/bottom_sheet.dart 91.57% <ø> (ø)
packages/flutter/lib/src/material/card.dart 100.00% <ø> (ø)
packages/flutter/lib/src/material/checkbox.dart 90.97% <ø> (ø)
packages/flutter/lib/src/material/chip.dart 93.67% <ø> (ø)
packages/flutter/lib/src/material/choice_chip.dart 54.66% <ø> (ø)
packages/flutter/lib/src/material/dialog.dart 96.96% <ø> (ø)
packages/flutter/lib/src/material/divider.dart 92.15% <ø> (ø)
... and 147 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pbo-linaro
Copy link
Contributor Author

@loic-sharma Thanks for your review. I'll integrate those changes, add test, and come back.

Copy link
Contributor

@yaakovschectman yaakovschectman left a comment

Choose a reason for hiding this comment

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

LGTM mod pending comments and test failures.

@pbo-linaro
Copy link
Contributor Author

I just rebased and pushed a new version. 2 tests (for items opened) still needs to be added.

@pbo-linaro
Copy link
Contributor Author

@loic-sharma Is there a way to simply format only changes? (like git clang-format). I tried to use flutter format but it results in a lot of differences alas.

@pbo-linaro
Copy link
Contributor Author

pbo-linaro commented Nov 15, 2022

@loic-sharma Could you help about current CI failures? I can't reproduce those on my side alas. (analyze command fails with lots of errors related to "dynamic calls")

@loic-sharma
Copy link
Member

Is there a way to simply format only changes? (like git clang-format). I tried to use flutter format but it results in a lot of differences alas.

See: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#formatting

The Flutter repo has to be formatted manually. Please refer to the guide above for formatting guidelines. We will likely call out lots of little style nits - please don't be discouraged by that!

Could you help about current CI failures? I can't reproduce those on my side alas. (analyze command fails with lots of errors related to "dynamic calls")

See: https://github.com/flutter/flutter/wiki/Using-the-Dart-analyzer

You'll want to run flutter update-packages before you run flutter analyze --flutter-repo.

@pbo-linaro
Copy link
Contributor Author

pbo-linaro commented Nov 16, 2022

Thanks for your help :) I'm now fixing issues reported by analyze command.

Out of curiosity, why flutter itself does not use its own format command? If you need specifics, maybe a --flutter-repo option could be added there too.

On this PR, could you make nit comments after the PR content is fully accepted (and tests are ok)? That limits noise with issues reported.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused; why are you returning x64 artifacts when targeting ARM? If there aren't ARM artifacts yet, then this shouldn't land. The order should be to update the engine repo to build and upload the necessary artifacts, then upload the tool to use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, on arm64, it should behave like x64 (because artifacts are not available). As mentioned in the commit message, you need a prebuilt arm64 flutter engine (built by hand) to create an arm64 app.

I'd love to have arm64 artifacts available from today, but I wanted first to show that a full app can be built with "vanilla" flutter. Kind of chicken and egg problem here.

If you think we should do it the other way, who can implement this for flutter? (build and upload engine)

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in the commit message, you need a prebuilt arm64 flutter engine (built by hand) to create an arm64 app.

I'm not sure what message you are referring to; the PR description just says that it adds an option to build for Windows ARM. This doesn't actually do that though; it adds a flag that doesn't work. That's extremely likely to confuse people who will, reasonably, assume that if there's a flag that says to target Windows ARM, that's what it will do.

Kind of chicken and egg problem here.

Having it locally working end to end is useful, and having branch in your fork to point people to can be helpful in some cases, but there's no chicken-and-egg problem when it comes to actually creating/landing production PRs; this is a layered system, with the tool depending on the engine artifacts, but not the reverse. There's nothing about landing a (non-functional) flag in the tool that would make landing the engine changes easier.

If you think we should do it the other way, who can implement this for flutter? (build and upload engine)

What's the current state of engine support for ARM? If you can cross-compile the Windows ARM engine from an x64 machine, then anyone can make the PRs to add it to the recipes. If not, then nobody can do it until/unless we have Windows ARM infra. (This is discussed in the issue referenced in your PR description.)

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'm a bit disappointed, as this PR was opened two weeks ago, mainly to get those kind of comments "Hey, we won't do it this way, thanks". At least, now it's clearer about the way to integrate this.

I agree this flag does not work, except if you build your own engine (as stated in the commit message).

So from there, how can we advance concretely on this?
Cross compile Windows ARM engine is the first step?
If that works, are you willing to help on making it available as an official artifact? What will be needed in more?

Copy link
Contributor Author

@pbo-linaro pbo-linaro Nov 16, 2022

Choose a reason for hiding this comment

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

#62597 (comment)

In this specific comment, you mentioned having a native arm64 build would be enough. Did things changed since? If we have a dedicated Windows on Arm machine that could be used, would that be enough for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit disappointed, as this PR was opened two weeks ago, mainly to get those kind of comments "Hey, we won't do it this way, thanks".

I'm sorry I wasn't able to review earlier; I have a very deep review queue at the moment.

However, what I'm saying here isn't any different than what I said in the issue months ago. I clearly said in the issue that having engine artifacts was a pre-requisite for tool changes.

I agree this flag does not work, except if you build your own engine (as stated in the commit message).

Oh, generally nobody is looking at the commit messages for individual commits in a PR. Important information needs to be in the PR description.

So from there, how can we advance concretely on this? Cross compile Windows ARM engine is the first step? [...] What will be needed in more?

@cbraken laid out a pretty detailed list in the issue: #62597 (comment)

If that works, are you willing to help on making it available as an official artifact?

I'm no longer actively working on desktop, so would not be involved in setting up artifact recipes.

#62597 (comment)

In this specific comment, you mentioned having a native arm64 build would be enough. Did things changed since?

Nothing has changed since, that's just not what I said. Bolding the important missing part:

The first goal though would be to get the engine cross-compiling (x64->arm64), or compiling natively on arm64, or both. (And if only the later, a CI solution for creating engine artifacts).

Having only a native arm64 build without also having ARM CI doesn't address the need for engine artifacts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I understand you were busy.

I'll continue discussion on original issue #62597.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this PR about host, or target, or both? The PR description currently sounds like it's only about the target, but this is changing host.

Copy link
Contributor Author

@pbo-linaro pbo-linaro Nov 16, 2022

Choose a reason for hiding this comment

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

Initially, I wanted to upstream everything to prepare arm64 support.
Basically, the option --target-platform could use this new Host Platform to derive automatically default target.

This code won't be used right now though, as the --target-platform flag has a windows-x64 default value. If you think it's not worth it (it will have to be committed at some point), I can drop it.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the supported set of host/target combinations for Windows? That's something that needs to be clearly addressed (ideally in a design document, but failing that in detail in the PR description) before I could offer an opinion about the value of each piece in isolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, only native workflows have been tried (x64 -> x64, arm64 -> arm64). Doing cross compilation implies work with gen_snapshot, which I didn't start to look into.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g Nov 16, 2022

Choose a reason for hiding this comment

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

I would strongly recommend a design document for any tool changes related to this; it doesn't really make sense to decide what the tool commands, output, etc. should look like without a discussion of whether cross-compilation will be supported. If same-arch builds are the only option then it doesn't seem like we even need a target flag.

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'll focus on getting flutter engine built and uploaded for windows-arm64 for now. Then, we can reopen that discussion.

It allows to build an app for x64 or arm64.

By default, build for x64. For now, a local engine build is needed to
get an arm64 build.

From an Windows on Arm machine:
$ fetch flutter
$ cd src
$ python3 ./flutter/tools/gn --no-prebuilt-dart-sdk --no-goma --windows-cpu arm64 --target-dir host_debug
$ ninja -C out/host_debug
$ cd C:/to/your/app
$ flutter.bat build windows --target-platform windows-arm64 --local-engine-src-path=C:/path/to/flutter/src --local-engine host_debug

You'll then have native arm64 app available!

This commits adds platform windows-arm64.
For now, artifacts are not available for it, so fallback to x64 when
downloading them.
@pbo-linaro
Copy link
Contributor Author

For now, this PR is closed, as artifacts for this new platform should be available before considering to add an option targeting it (see latest discussions for details).

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

Labels

a: desktop Running on desktop platform-windows Building on or for Windows specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants