Putting asciidocr on My Phone Thanks to WebAssembly (Asciidoc to Word on iOS)
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:
-
Install the wasm "target" via
rustup target add wasm32-wasip1. -
Build to that target via
cargo build --all-features --target wasm32-wasip1 -r. -
Copy the resultant
asciidocr.wasmfile over to my phone. -
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…