Skip to content

Commit

Permalink
small docs and compilation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
juancastillo0 committed Jun 17, 2023
1 parent f78f848 commit 314628f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/wasm_packages/image_rs/example/image_rs_example.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:image_rs/image_rs.dart';
// import 'package:image_rs/image_rs.dart';

void main() {
var awesome = Awesome();
print('awesome: ${awesome.isAwesome}');
// var awesome = Awesome();
// print('awesome: ${awesome.isAwesome}');
}
45 changes: 41 additions & 4 deletions packages/wasm_packages/image_rs/lib/src/image_rs_base.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
// TODO: Put public facing types in this file.
import 'package:wasm_run/load_module.dart';
import 'package:wasm_run/wasm_run.dart';
import 'package:image_rs/src/image_rs_wit.gen.dart';

/// Checks if you are awesome. Spoiler: you are.
class Awesome {
bool get isAwesome => true;
export 'package:image_rs/src/image_rs_wit.gen.dart';

/// Creates a [ImageRsWorld] with the given [wasiConfig].
/// It setsUp the dynamic library for wasm_run in native platforms and
/// loads the image_rs WASM module from the file system or
/// from the url pointing to 'lib/image_rs_wasm.wasm'.
///
/// If [loadModule] is provided, it will be used to load the WASM module.
/// This can be useful if you want to provide a different configuration
/// or implementation, or you are loading it from Flutter assets or
/// from a different HTTP endpoint. By default, it will load the WASM module
/// from the file system in `lib/image_rs_wasm.wasm` either reading it directly
/// in native platforms or with a GET request for Dart web.
Future<ImageRsWorld> createImageRs({
required WasiConfig wasiConfig,
Future<WasmModule> Function()? loadModule,
WorkersConfig? workersConfig,
}) async {
await WasmRunLibrary.setUp(override: false);

final WasmModule module;
if (loadModule != null) {
module = await loadModule();
} else {
final uri = await WasmFileUris.uriForPackage(
package: 'image_rs',
libPath: 'image_rs_wasm.wasm',
envVariable: 'IMAGE_RS_WASM_PATH',
);
final uris = WasmFileUris(uri: uri);
module = await uris.loadModule();
}
final builder = module.builder(
wasiConfig: wasiConfig,
workersConfig: workersConfig,
);

return ImageRsWorld.init(builder, imports: const ImageRsWorldImports());
}
6 changes: 3 additions & 3 deletions packages/wasm_packages/image_rs/test/image_rs_test.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:image_rs/image_rs.dart';
// import 'package:image_rs/image_rs.dart';
import 'package:test/test.dart';

void main() {
group('A group of tests', () {
final awesome = Awesome();
// final awesome = Awesome();

setUp(() {
// Additional setup goes here.
});

test('First Test', () {
expect(awesome.isAwesome, isTrue);
// expect(awesome.isAwesome, isTrue);
});
});
}
2 changes: 1 addition & 1 deletion packages/wasm_packages/rust_crypto/lib/rust_crypto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export 'package:wasm_run/wasm_run.dart';

const _isWeb = identical(0, 0.0);

/// Creates a [DartWitGeneratorWorld] from for the given [wasiConfig].
/// Creates a [RustCryptoWorld] with the given [wasiConfig].
/// It setsUp the dynamic library for wasm_run for native platforms and
/// loads the dart_wit_component WASM module from the file system or
/// from the releases of wasm_run repository.
Expand Down
6 changes: 5 additions & 1 deletion packages/wasm_run/lib/src/wasm_bindings/wasm_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export 'package:wasm_run/src/int64_bigint/int64_bigint.dart';
abstract class WasmModule {
/// A builder that creates a new [WasmInstance] from this module.
/// It configures the imports and definitions of the instance.
/// [wasiConfig] is not supported in the browser executor.
/// [wasiConfig] is used to configure WASI imports, environment variables,
/// arguments and the file system access.
/// [workersConfig] is used to configure the number of workers and the
/// web worker script url. The module should support atomics, threads and
/// shared memory to be able to use workers.
WasmInstanceBuilder builder({
WasiConfig? wasiConfig,
WorkersConfig? workersConfig,
Expand Down

0 comments on commit 314628f

Please sign in to comment.