There are good reasons why you might want to be able to run asciidocr on your phone. Or rather: there are good reasons why I want to be able to run asciidocr on my phone. Specifically, I want to keep an appropriate separation of concerns between my personal and work computers; I do not want to have to bring a personal computer when traveling for work. I can write on my phone just fine (more on this in a moment), but previously, were I want to share what I had written, well: little bit harder.

Because I am a crazy person and insist on using vim if possible,[1] I’ve been able to write just fine on my phone if I have a keyboard[2] using a program called a-Shell. But were I to need to, say, send my weekly pages to my accountability-buddy while traveling, I would either need to write or otherwise convert the text into Markdown and export a docx via another app, or… I don’t know. I guess I could have used the old Python asciidoc converter (as a-Shell supports Python out-of-the-box) and then pipe that into the html to docx converter I wrote a while back, but, you know… that’s more work than I would want to do. And sure I could script it, but still.

Could I not make asciidocr work?

I had some vague awareness that a-Shell supported WebAssembly, which is basically a way to run code inside a "portable runtime," i.e., usually a browser, without writing "native" code (i.e., JavaScript, in the case of a browser). It’s kind of like what Java’s JVM was meant to be, except, you know, modern, nicer, etc., etc. Anyway, since asciidocr is written in Rust, and since Rust has good support for WebAssembly, it should work, right?

It does.

It was a lot easier than I had thought it would be.

You see, there’s a whole other asciidoc project — or, well, there was, but it seems like they’ve changed lanes — that was explicitly targeting WebAssembly (hereafter I’m just going to refer to it as "wasm"), so I had thought that doing a wasm version was some special thing. This turned out not to be the case. All I had to do to get this working was:

  1. Install the wasm "target" via rustup target add wasm32-wasip1.

  2. Build to that target via cargo build --all-features --target wasm32-wasip1 -r.

  3. Copy the resultant asciidocr.wasm file over to my phone.

  4. Run the program via wasm: wasm asciidocr.wasm my_file.adoc.

For added convenience, I aliased it in the .profile file in a-Shell:

alias asciidocr='wasm ~/Documents/wasm-bin/asciidocr.wasm'

The surprise was that it output a docx file just fine! I had expected HTML output to work, since, you know, that’s pretty simple and just templates, but I wasn’t sure if the docx crate I rely on didn’t have some dependency that would cause problems. But no: at least so far, so good.[3]

So now, though there are certainly still things I’d want a personal laptop for while traveling (e.g., working on asciidocr), but, you know, the "main" thing, writing, very possible and easy already, is now shareable. I mean it’s not like folks are knocking down my door to get the works-in-progress. But this was a minor inconvenience that now has been solved. Trivially. This was trivial to solve. Thanks Rust, thanks a-Shell, thanks WebAssembly, thanks all the folks much smarter than I who make these things not only possible, but easy.

Maybe I should do my dinky little task tracker tool too…


1. It’s just so much nicer to move around a document once you’ve learned it. But when it’s not possible, i.e., when I do not have a keyboard, such as on a bus, iA Writer does a perfectly good job.
2. While I am still deeply suspicious of portable or foldable keyboards, I have one that mostly seems to work (it works better now that it’s not being crushed inside a backpack overstuffed for winter bike commuting).
3. We’ll have an opportunity to really test-drive this soon; if it’s worth reporting back I’ll report back. As a complete aside, the new company (or at least the sales org) likes to use the phrase "drinking our own champagne" for a process I’m more familiar hearing as "dogfooding", so: that’s kind of nice. The Wikipedia page implies that this was coined elsewhere (of course!) and has been around for a while, but it’s new to me. I kind of like it. That being said, what I am making here is certainly more akin to a cheap canned lager than champagne. It’ll get the job done, but.