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

[flutter_tools] port bash script to use sysctl not uname on macOS #101308

Merged

Conversation

christopherfujino
Copy link
Member

@christopherfujino christopherfujino commented Apr 4, 2022

Fixes #101243

For context, a similar Flutter tool change was made in https://github.com/flutter/flutter/pull/67970/files

To test the bash logic, you can update line 66:

To test sysctl returning exit code 1 on x64 and newer macOS: QUERY="false"

It should log: Downloading Darwin x64 Dart SDK from Flutter engine $ENGINE_VERSION...

To test sysctl returning exit code 0 (success) but printing 0 (arm64 not present) on x64 and older macOS: QUERY="echo 0"

It should log: Downloading Darwin x64 Dart SDK from Flutter engine $ENGINE_VERSION...

To test sysctl returning exit code 0 (success) and printing 1 (arm64 present) on arm64: QUERY="echo 1"

It should log: Downloading Darwin arm64 Dart SDK from Flutter engine $ENGINE_VERSION...

@jmagman
Copy link
Member

jmagman commented Apr 4, 2022

This works on macOS 12.3.1 x64 machine:

$ flutter
Downloading Darwin x64 Dart SDK from Flutter engine 801d8c530fc5b0c102d13d5913dbd98376b99c93...

A macOS 12.1 M1 machine running w/ Rosetta:

$ uname -m
x86_64
flutter$ flutter
Downloading Darwin arm64 Dart SDK from Flutter engine 801d8c530fc5b0c102d13d5913dbd98376b99c93...

Same Mac running w/ Rosetta:

$ uname -m                                            
arm64
flutter$ flutter            
Downloading Darwin arm64 Dart SDK from Flutter engine 801d8c530fc5b0c102d13d5913dbd98376b99c93...

@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.

@christopherfujino christopherfujino changed the title [flutter_tools] port bash script to use sysctl not uname [flutter_tools] port bash script to use sysctl not uname on macOS Apr 4, 2022
# `uname -m` may be running in Rosetta mode, instead query sysctl
if [ "$OS" = 'Darwin' ]; then
ARCH="arm64"
# This will exit 1 if the CPU arch is not ARM64
Copy link
Member

Choose a reason for hiding this comment

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

On x64 it will either exit with a failure code, or it will exit successfully and print 0 (I actually don't see that anymore, but I did see that working on #67970, though it may have been a beta version of macOS):

$ sysctl hw.optional.arm64
sysctl: unknown oid 'hw.optional.arm64'
$ echo $?
1

On arm64 it will print 1 and exit successfully.

Copy link
Member Author

Choose a reason for hiding this comment

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

argh, we need to parse the output then?

Copy link
Member Author

@christopherfujino christopherfujino Apr 4, 2022

Choose a reason for hiding this comment

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

at least it looks like we can do sysctl -n hw.optional.arm64 https://github.com/pytorch/pytorch/blob/e7ca62be08f96b07efc1271baf9b02d4e7be226a/cmake/Modules/FindARM.cmake#L44

It's annoying we have to ALSO check the exit code though

Copy link
Member

Choose a reason for hiding this comment

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

If I recall the last time I looked at this on old versions of macOS it exited 1, on new versions of macOS on x64 it exited successfully and printed 0, and on arm64 it printed 1. However on latest macOS on my x64 machine it's exiting failure with sysctl: unknown oid 'hw.optional.arm64'. So maybe that's not the behavior anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated this to mirror the logic of #67970

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm. This will need manual testing on both x64 and arm64 macs.

bin/internal/update_dart_sdk.sh Outdated Show resolved Hide resolved
bin/internal/update_dart_sdk.sh Outdated Show resolved Hide resolved
@christopherfujino
Copy link
Member Author

I have tested this works on x64 mac.

@jmagman
Copy link
Member

jmagman commented Apr 4, 2022

Confirmed 20f64ac works on x64 (downloads x64), arm64 (downloads arm64), arm64 w/ Rosetta (downloads arm64).

@jmagman
Copy link
Member

jmagman commented Apr 4, 2022

To test, consider an integration test that validates

$ file bin/cache/dart-sdk/bin/dart
bin/cache/dart-sdk/bin/dart: Mach-O 64-bit executable x86_64
$ file bin/cache/dart-sdk/bin/dart
bin/cache/dart-sdk/bin/dart: Mach-O 64-bit executable arm64

similar to

final ProcessResult archs = processManager.runSync(
<String>['file', pluginFrameworkBinary.path],
);
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library x86_64'));
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library arm64'));

We won't get arm64 test coverage until #87508 is done.

@christopherfujino
Copy link
Member Author

To test, consider an integration test that validates

$ file bin/cache/dart-sdk/bin/dart
bin/cache/dart-sdk/bin/dart: Mach-O 64-bit executable x86_64

similar to

final ProcessResult archs = processManager.runSync(
<String>['file', pluginFrameworkBinary.path],
);
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library x86_64'));
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library arm64'));

We won't get arm64 test coverage until #87508 is done.

Good idea, writing this test now

@christopherfujino
Copy link
Member Author

Added an integration test, @jmagman PTAL

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

@@ -14,14 +14,19 @@ import 'test_utils.dart';
final String flutterRootPath = getFlutterRoot();
final Directory flutterRoot = fileSystem.directory(flutterRootPath);

enum MacArches {
Copy link
Member

Choose a reason for hiding this comment

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

nit: there's probably a better name than bash_entrypoint_test for this test file since it's doing more now.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's technically testing the entrypoint, since the entrypoint is responsible for caching the dart SDK, but I'm open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine as-is.

bernard-lee added a commit to bernard-lee/flutter that referenced this pull request Jun 29, 2022
* 'stable' of https://github.com/flutter/flutter: (1203 commits)
  'Update Engine revision to ffe7b86a1e5b5cb63c8385ae1adc759e372ee8f4 for stable release 3.0.3' (flutter#106431)
  [flutter_releases] Removing minor iOS version filter value from ci.yaml (flutter#105059) (flutter#105629)
  [flutter_releases] Flutter stable 3.0.2 Framework Cherrypicks (flutter#105528)
  [framework] ensure ink sparkle is disposed (flutter#104569) (flutter#105144)
  [CP] Fix Flutter doctor crash on Windows caused by bad UTF8 from vswhere.exe (flutter#105153)
  [tool][web] Use 'constructor' instead of 'public field declarations' in flutter.js (Safari 13) (flutter#105162)
  [flutter_releases] Cherrypicks for SliverReorderableList and Slider regressions (flutter#105141)
  'Update Engine revision to caaafc5604ee9172293eb84a381be6aadd660317 for stable release 3.0.1' (flutter#104213)
  [flutter_releases] Flutter stable 2.13.0 Framework Cherrypicks (flutter#103375)
  [flutter_releases] Flutter beta 2.13.0-0.4.pre Framework Cherrypicks (flutter#103101)
  Enforce cpu explicitly for Mac devicelab test beds (flutter#101871) (flutter#102685)
  [flutter_releases] Flutter beta 2.13.0-0.3.pre Framework Cherrypicks (flutter#102620)
  [flutter_releases] Upgrade dwds to 12.1.1 (flutter#101546)
  [flutter_releases] Flutter beta 2.13.0-0.2.pre Framework Cherrypicks (flutter#102193)
  [flutter_releases] Flutter beta 2.12.0-4.1.pre Framework Cherrypicks (flutter#101771)
  [flutter_releases] Cherrypick engine to c341645 (flutter#101608)
  Revert "Refactor `ToggleButtons` (remove `RawMaterialButton`) (flutter#99493)" (flutter#101538)
  [Cherrypick] Partial revert of super params in tools (flutter#101436) (flutter#101527)
  Roll Engine from e7e7ca1 to b48d65e (10 revisions) (flutter#101370)
  [flutter_tools] port bash script to use sysctl not uname on macOS (flutter#101308)
  ...
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.

Apple silicon machine on latest master shows x64 cached Dart version
3 participants