Completed: ICDevs.org - Bounty #34 - Wasmer Motoko - $10,000

Wasmer Motoko - #34

Current Status: Discussion

  • Discussion (01/09/2023)
  • Ratification: (01/09/2023)
  • Open for application: (01/09/2023)
  • Assigned
  • In Review
  • Closed

Official Link

Bounty Details

  • Bounty Amount: $10,000 USD of ICP at award date
  • ICDevs.org Bounty Acceleration: For each 1 ICP sent to edaa35657e696ec3ca92fc45edf8f7204139adea348d3f3fa17a26dffce8493b, ICDevs.org will add .25 ICP to this issue and .75 ICP to fund other ICDevs.org initiatives.
  • Project Type: Team
  • Opened: 01/09/2023
  • Time Commitment: Weeks
  • Project Type: Library
  • Experience Type: Advanced - Motoko; Advanced - OCaml

Description

In order to popularize the motoko programing language we need to enable it to run and perform operations outside of the IC. The strong typing and async model of programming lend itself nicely to a number of modern computing challenges.

Wasmer is a set of tools that let you load wasm modules into other languages and interact with those modules across a range of environments and operating systems.

This bounty asks the user to create a Hello World motoko application that can be accessed from a number of Operating Systems and asks the developer to create sample projects for those integrations.

Create a simple motoko program that takes a string input - x - and returns “Hello, {x}”. It should also have state storage that stores the last message returned.

Call this program from:

  • A C# application that runs on windows. Upon clicking a button, the application should take input from the user and then show a windows modal with result of the motoko function. Another button should show the last message created using the the hello world function.
  • A Swift application that runs on MacOs. Upon clicking a button, the application should take input from the user and then show a MacOS modal with result of the motoko function. Another button should show the last message created using the the hello world function. You may need to bridge to a rust implementation as described here: Cacao: Building macOS (and iOS) Apps in Rust | Ryan McGrath as a swift wasmer implementation does not exist yet.
  • A React-native application that runs on iOS and Android. Upon clicking a button, the application should take input from the user and then show a iOS/android modal with result of the motoko function. Another button should show the last message created using the the hello world function.
  • A Dart application that runs on android/iOS. Upon clicking a button, the application should take input from the user and then show a android/iOS modal with result of the motoko function. Another button should show the last message created using the the hello world function.

See GitHub - wasmerio/wasmer: 🚀 The leading WebAssembly Runtime supporting WASI and Emscripten for available languages and other documentation

This bounty gives the opportunity to

  • learn rust
  • learn swift
  • learn motoko
  • learn c#
  • learn wasmer
  • learn about OS integrations
  • learn about the motoko compiler

At this point, we don’t expect things like async to work from the motoko wasm. We are looking for basic functionality and the ability to push data into and get data out of motoko libraries.

Completion of this bounty will qualify the dev for future bounties where we look to enable the async programming model inside of a motoko wasm program and the ability of a running motoko wasm module to send events/signals to its running program.

To apply for this bounty you should:

  • Include links to previous work writing tutorials and any other open-source contributions(ie. your github).
  • Include a brief overview of how you will complete the task. This can include things like which dependencies you will use, how you will make it self-contained, the sacrifices you would have to make to achieve that, or how you will make it simple. Anything that can convince us you are taking a thoughtful and expert approach to this design.
  • Give an estimated timeline on completing the task.
  • Post your application text to the Bounty Thread

Selection Process

The ICDevs.org developer’s advisors will propose a vote to award the bounty and the Developer Advisors will vote.

Bounty Completion

Please keep your ongoing code in a public repository(fork or branch is ok). Please provide regular (at least weekly) updates. Code commits count as updates if you link to your branch/fork from the bounty thread. We just need to be able to see that you are making progress.

The balance of the bounty will be paid out at completion.

Once you have finished, please alert the dev forum thread that you have completed work and where we can find that work. We will review and award the bounty reward if the terms have been met. If there is any coordination work(like a pull request) or additional documentation needed we will inform you of what is needed before we can award the reward.

Bounty Abandonment and Re-awarding

If you cease work on the bounty for a prolonged(at the Developer Advisory Board’s discretion) or if the quality of work degrades to the point that we think someone else should be working on the bounty we may re-award it. We will be transparent about this and try to work with you to push through and complete the project, but sometimes, it may be necessary to move on or to augment your contribution with another resource which would result in a split bounty.

Funding

The bounty was generously funded by the DFINITY Foundation. If you would like to turbocharge this bounty you can seed additional donations of ICP to edaa35657e696ec3ca92fc45edf8f7204139adea348d3f3fa17a26dffce8493b. ICDevs will match the bounty $40:1 ICP for the first 125 ICP out of the DFINITY grant and then 0.25:1. All donations will be tax deductible for US Citizens and Corporations. If you send a donation and need a donation receipt, please email the hash of your donation transaction, physical address, and name to donations@icdevs.org. More information about how you can contribute can be found at our donations page.

FYI: General Bounty Process

Discussion

The draft bounty is posted to the DFINITY developer’s forum for discussion

Ratification: (01/09/2023)

The developer advisor’s board will propose a bounty be ratified and a vote will take place to ratify the bounty. Until a bounty is ratified by the Dev it hasn’t been officially adopted. Please take this into consideration if you are considering starting early.

Open for application

Developers can submit applications to the Dev Forum post. The council will consider these as they come in and propose a vote to award the bounty to one of the applicants. If you would like to apply anonymously you can send an email to austin at icdevs dot org or sending a PM on the dev forum.

Assigned

A developer is currently working on this bounty, you are free to contribute, but any splitting of the award will need to be discussed with the currently assigned developer.

In Review

The Dev Council is reviewing the submission

Awarded

The award has been given and the bounty is closed.

Other ICDevs.org Bounties

2 Likes

In case anyone wants to start playing around with running Motoko via Wasmer in Node.js / React Native, here is some example code using the motoko npm package:

4 Likes

I also learned about this repo that is just at its beginning, but may lead some interesting use cases: GitHub - dfinity/motoko.rs: Motoko concrete syntax parser in Rust.

2 Likes

Interesting you can reply here but you have ignored my comments.

Hello, @skilesare, I would like to work on this bounty.

Some considerations though:

  1. Wasmer doesn’t work in React Native due WebAssembly not been supported by JavaScriptCore (I tried to switch to react-native-v8 but it couldn’t run either). Instead, I can create a native Android app using Kotlin and a native iOS app using Swift (this one only if item 2 is solved)
  2. As you said, there’s no official/finished Wasmer package for Swift. I also don’t own a Mac at moment (although if this bounty get assigned to me, I’ll build a hackintosh PC). Due those constraints, would it be OK to try a alternative solution like wasm3 (GitHub - shareup/wasm-interpreter-apple)?
  3. The dart apps will need to be implemented using flutter. At moment only Android is supported by (wasm/README.md at main · dart-lang/wasm · GitHub) and the library is marked as
    experimental (GitHub - dart-lang/wasm: Utilities for loading and running WASM modules from Dart code). There’s no dart version of wasm3, so the item 2 alternative can’t be used here.

At the moment I’m implementing the nodejs and c# versions and they are working great.

Some of my active motoko projects: GitHub - av1ctor/mo-table: Motoko database with support for B+trees and Suffix trees to allow fast indexing , GitHub - av1ctor/metamob: A decentralized web3 app, running 100% on-chain on the Internet Computer, that lets any user start mobilizations by creating campaigns of four different kinds: donations, votes, signatures and fundraising

1 Like
  1. I wonder if this is fixed now/if there is a workaround? I know that @kpeacock did some work on the agent to get it to work with react native…but maybe it was a bit hacky and won’t work with wasmer: Agent-JS 0.15.0

  2. The goal is to have a simple way to run motoko on all platforms, so if it is simple to integrate then I think it would work fine.

  3. We may need a multi-strategy here.

I’ve submitted you to the dev board and I expect it to be approved.

1 Like

React Native now works with Agent-JS without any hacky patches. This involves both bigint and wasm for the BLS verification, so it should theoretically work here.

Check out examples/react-native-starter at master · dfinity/examples · GitHub for the setup we have tested

1 Like

@skilesare and @kpeacock

According to this thread (WebAssembly support? · Issue #113 · react-native-community/jsc-android-buildscripts · GitHub), WebAssembly was supported on iOS 14 but it’s not on iOS 15 (I don’t have a iPhone to test, could someone check if its true?). Also some say it works on the iOS simulator/emulator, but not in the real hardware.

React Native on iOS uses v8, that supports WebAssembly. Now the Android version still using JavaScriptCore, that doesn’t have support for wasm. I tried to switch RN to react-native-v8 on Android, but wasmer failed right at the init() method.

I ended up using wasm2js from Binaryen (GitHub - WebAssembly/binaryen: Optimizer and compiler/toolchain library for WebAssembly). It worked fine with React Native on Android. Gotta test it later on iOS when I get my hackintosh up and running.

The process is pretty straightforward: the same script that generates the proper “a-motoko-lib.wasm” file, will generate the “a-motoko-lib.js” also.

2 Likes

Hi @skilesare, looks like the time to vote is getting close to expire and there’s not enough votes.

Half the implementation is already done and I ordered the pc parts do build a hackintosh to write and test the Mac OS version using Swift and test the React native version on the iOS emulator.

If there’s something else I need to do to convince the board that I’m capable to complete this bounty, please let me know. Thanks!

1 Like

You are fine…I’m only worried about no votes and I don’t think anyone has any issues. I’ll repropose if it fails.

3 Likes

Alright, thanks! I’ll keep working on it. I’m going to post the repository’s link soon. Cheers!

2 Likes

Here’s the repository: https://github.com/av1ctor/icdevs-wasmer

At the moment I’m working on the hardest part: the Swift version. As there’s no working Wasmer wrapper for it, the C-API will have to be used directly.

2 Likes

It may be worth poking around their slack and seeing if anyone else has worked on this:

1 Like

Hello @skilesare, it took much longer than I predicted, but it’s done!

On MacOS (Swift), I had to use the Wasmer C-API directly (because there’s no Wasmer wrapper for Swift), but the Motoko helper class makes it really simple to be used by end users (more details at icdevs-wasmer/swift at master · av1ctor/icdevs-wasmer · GitHub).

For iOS, I had to create a Wasm3 Flutter plugin (that works on Android too!). While it took literally days to get XCode to build it, it’s working fine now (it was tested only on the iPhone simulator because I don’t have the real hardware to try).

The React Native version works on both iOS and Android (wasm2js was needed, due the lack of WebAssembly support on both platforms).

The C# version was the easiest one to implement. Tested on Windows 10.

I also created a nodejs version to show how interact with Motoko at server-side.

Everything is at GitHub - av1ctor/icdevs-wasmer: ICDevs bounty #34: Wasmer

There are also releases with the binaries and APK’s there (I couldn’t create the iOS app’s because I’ve no Apple dev account and there’s no free option).

I think that covers all features listed for this bounty. Please let me know if everything is ok.

Thanks in advance!

3 Likes

@skilesare, how is the review stage going? Is there anything I should change or implement? Thanks!

1 Like

Submitted for approval:

@icme, @aiv, @quint, @mparikh, please vote :slight_smile:

3 Likes