Cleanup pkg:wasm

- Fix many lint warnings
- Cleanup readme
- Remove author from pubspec
- Increase length of pubspec description to follow guidlines
- Improve default experience for running bin/setup.dart on MacOS

Change-Id: I586716be06c48db3030c5076b5e65c8995cc6d27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201881
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
diff --git a/pkg/wasm/README.md b/pkg/wasm/README.md
index 1fcab7e..ecf418d 100644
--- a/pkg/wasm/README.md
+++ b/pkg/wasm/README.md
@@ -1,7 +1,6 @@
-# wasm
+Provides utilities for loading and running WASM modules
 
-This package provides utilities for loading and running WASM modules. It is
-built on top of the [Wasmer](https://github.com/wasmerio/wasmer) runtime.
+Built on top of the [Wasmer](https://github.com/wasmerio/wasmer) runtime.
 
 ## Setup
 
diff --git a/pkg/wasm/bin/setup.dart b/pkg/wasm/bin/setup.dart
index ad36423..868c189 100644
--- a/pkg/wasm/bin/setup.dart
+++ b/pkg/wasm/bin/setup.dart
@@ -27,6 +27,12 @@
     return checkedOutSdkDir;
   }
 
+  final homebrewOutSdkDir = exe.resolve('..');
+  final homebrewIncludeDir = homebrewOutSdkDir.resolve('include');
+  if (Directory(homebrewIncludeDir.path).existsSync()) {
+    return homebrewOutSdkDir;
+  }
+
   // If neither returned above, we return the common case:
   return commonSdkDir;
 }
@@ -52,7 +58,7 @@
   return 'libwasmer.so';
 }
 
-getTargetTriple() async {
+Future<String> getTargetTriple() async {
   final process = await Process.start('rustc', ['--print', 'cfg']);
   process.stderr
       .transform(utf8.decoder)
@@ -69,11 +75,14 @@
   String arch = cfg['target_arch'] ?? 'unknown';
   String vendor = cfg['target_vendor'] ?? 'unknown';
   String os = cfg['target_os'] ?? 'unknown';
-  String env = cfg['target_env'] ?? 'unknown';
-  return '$arch-$vendor-$os-$env';
+  if (os == 'macos') os = 'darwin';
+  String? env = cfg['target_env'];
+  return [arch, vendor, os, env]
+      .where((element) => element != null && element.isNotEmpty)
+      .join('-');
 }
 
-run(String exe, List<String> args) async {
+Future<void> run(String exe, List<String> args) async {
   print('\n$exe ${args.join(' ')}\n');
   final process = await Process.start(exe, args);
   process.stdout
@@ -91,13 +100,13 @@
   }
 }
 
-main(List<String> args) async {
+Future<void> main(List<String> args) async {
   if (args.length > 1) {
     print('Usage: dart setup.dart [target-triple]');
     exit(1);
   }
 
-  final target = args.length >= 1 ? args[0] : await getTargetTriple();
+  final target = args.isNotEmpty ? args[0] : await getTargetTriple();
   final sdkDir = getSdkDir();
   final binDir = Platform.script;
   final outDir = getOutDir(binDir);
@@ -121,12 +130,13 @@
     '--release'
   ]);
 
+  final dartApiDlImplFile =
+      File.fromUri(sdkDir.resolve('include/internal/dart_api_dl_impl.h'));
   // Hack around a bug with dart_api_dl_impl.h include path in dart_api_dl.c.
-  if (!File.fromUri(sdkDir.resolve('include/internal/dart_api_dl_impl.h'))
-      .existsSync()) {
+  if (!dartApiDlImplFile.existsSync()) {
     Directory(outDir.resolve('include/internal/').path)
         .createSync(recursive: true);
-    File.fromUri(sdkDir.resolve('include/runtime/dart_api_dl_impl.h'))
+    await dartApiDlImplFile
         .copy(outDir.resolve('include/internal/dart_api_dl_impl.h').path);
   }
 
diff --git a/pkg/wasm/example/brotli.dart b/pkg/wasm/example/brotli.dart
index e9520e3..d8cea14 100644
--- a/pkg/wasm/example/brotli.dart
+++ b/pkg/wasm/example/brotli.dart
@@ -6,9 +6,9 @@
 // library. Usage:
 // dart brotli.dart input.txt
 
-import 'dart:convert';
 import "dart:io";
 import "dart:typed_data";
+
 import "package:wasm/wasm.dart";
 
 // Brotli compression parameters.
diff --git a/pkg/wasm/lib/src/function.dart b/pkg/wasm/lib/src/function.dart
index 8cff328..bc5e44c 100644
--- a/pkg/wasm/lib/src/function.dart
+++ b/pkg/wasm/lib/src/function.dart
@@ -2,10 +2,12 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'dart:ffi';
+
+import 'package:ffi/ffi.dart';
+
 import 'runtime.dart';
 import 'wasmer_api.dart';
-import 'dart:ffi';
-import 'package:ffi/ffi.dart';
 
 /// WasmFunction is a callable function from a WasmInstance.
 class WasmFunction {
@@ -19,7 +21,7 @@
   WasmFunction(this._name, this._func, this._argTypes, this._returnType) {
     _args.ref.length = _argTypes.length;
     _args.ref.data =
-        _argTypes.length == 0 ? nullptr : calloc<WasmerVal>(_argTypes.length);
+        _argTypes.isEmpty ? nullptr : calloc<WasmerVal>(_argTypes.length);
     _results.ref.length = _returnType == WasmerValKindVoid ? 0 : 1;
     _results.ref.data =
         _returnType == WasmerValKindVoid ? nullptr : calloc<WasmerVal>();
diff --git a/pkg/wasm/lib/src/module.dart b/pkg/wasm/lib/src/module.dart
index 305d239..5687b2e 100644
--- a/pkg/wasm/lib/src/module.dart
+++ b/pkg/wasm/lib/src/module.dart
@@ -2,13 +2,15 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'runtime.dart';
-import 'function.dart';
-import 'wasmer_api.dart';
-import 'dart:typed_data';
 import 'dart:ffi';
+import 'dart:typed_data';
+
 import 'package:ffi/ffi.dart';
 
+import 'function.dart';
+import 'runtime.dart';
+import 'wasmer_api.dart';
+
 /// WasmModule is a compiled module that can be instantiated.
 class WasmModule {
   late Pointer<WasmerStore> _store;
@@ -165,7 +167,6 @@
       throw Exception("Import is not a function: $imp");
     }
 
-    var argTypes = runtime.getArgTypes(imp.funcType);
     var returnType = runtime.getReturnType(imp.funcType);
     var wasmFnImport = calloc<_WasmFnImport>();
     wasmFnImport.ref.returnType = returnType;
@@ -241,7 +242,7 @@
         var mem = runtime.externToMemory(e);
         _exportedMemory = mem;
         if (_wasiEnv != nullptr) {
-          runtime.wasiEnvSetMemory(_wasiEnv as Pointer<WasmerWasiEnv>, mem);
+          runtime.wasiEnvSetMemory(_wasiEnv, mem);
         }
       }
     }
diff --git a/pkg/wasm/lib/src/runtime.dart b/pkg/wasm/lib/src/runtime.dart
index b8defab..1db3ef4 100644
--- a/pkg/wasm/lib/src/runtime.dart
+++ b/pkg/wasm/lib/src/runtime.dart
@@ -699,7 +699,7 @@
   Function _reader;
   Pointer<Uint8> _buf = calloc<Uint8>(_bufferLength);
   int _length = 0;
-  _WasiStreamIterator(this._env, this._reader) {}
+  _WasiStreamIterator(this._env, this._reader);
 
   bool moveNext() {
     _length = _reader(_env, _buf, _bufferLength);
@@ -712,7 +712,7 @@
 class _WasiStreamIterable extends Iterable<List<int>> {
   Pointer<WasmerWasiEnv> _env;
   Function _reader;
-  _WasiStreamIterable(this._env, this._reader) {}
+  _WasiStreamIterable(this._env, this._reader);
   @override
   Iterator<List<int>> get iterator => _WasiStreamIterator(_env, _reader);
 }
diff --git a/pkg/wasm/lib/src/tools/runtime_template.dart b/pkg/wasm/lib/src/tools/runtime_template.dart
index 0394c10..2798b90 100644
--- a/pkg/wasm/lib/src/tools/runtime_template.dart
+++ b/pkg/wasm/lib/src/tools/runtime_template.dart
@@ -390,7 +390,7 @@
   Function _reader;
   Pointer<Uint8> _buf = calloc<Uint8>(_bufferLength);
   int _length = 0;
-  _WasiStreamIterator(this._env, this._reader) {}
+  _WasiStreamIterator(this._env, this._reader);
 
   bool moveNext() {
     _length = _reader(_env, _buf, _bufferLength);
@@ -403,7 +403,7 @@
 class _WasiStreamIterable extends Iterable<List<int>> {
   Pointer<WasmerWasiEnv> _env;
   Function _reader;
-  _WasiStreamIterable(this._env, this._reader) {}
+  _WasiStreamIterable(this._env, this._reader);
   @override
   Iterator<List<int>> get iterator => _WasiStreamIterator(_env, _reader);
 }
diff --git a/pkg/wasm/pubspec.yaml b/pkg/wasm/pubspec.yaml
index ef31927..9cd60c7 100644
--- a/pkg/wasm/pubspec.yaml
+++ b/pkg/wasm/pubspec.yaml
@@ -1,7 +1,6 @@
 name: wasm
 version: 0.1.0
-description: Load and run wasm bytecode.
-author: Dart Team <misc@dartlang.org>
+description: Utilities for loading and running WASM modules from Dart code
 homepage: https://github.com/dart-lang/sdk/tree/master/pkg/wasm
 
 environment: