Further adventures in iPad coding
Wed, Dec 23, 2020

Coding on an iOS device (in my case, a 9.7 inch iPad Pro) can be frustrating, but I’ve found some tricks to get things done. For Advent of Code I have been working in rust, and while home for the holidays, I am developing from an iPad. As such my requirements for development are as follows:

  • An iPad based text editor
  • A way to build rust code
  • A way to quickly test rust code and see the results
  • Ideally auto-completion for rust code

While iPad code editing apps exist, as well as some capable IDEs (looking at you Pythonista), you usually are confined to writing your own code in the app and using a few standard libraries. However the advent of iSH and its new package manager feature starts to unlock the iPads potential. iSH is an usermode x86 Linux emulator that can install a variety of software. The software comes from the alpine Linux distribution and skirts around Apple restrictions on downloadable executables by including them as on-demand resources that can be downloaded with the app. As git and gcc\clang work, in theory any software can be downloaded, compiled and run.

The reality is a little more complex as not every x86 instruction is emulated (the SSE2 supplementary instruction set specifically), and not all software will work, including the rust compiler. To get around this the best option is to use a remote server and sync files there to run build commands. There are a few arrangements to let you do this, but I ended up having a copy of my project in Working Copy and mounting that in iSH. You can use the command mount -t ios src <destination> to do this. I then wrote a short script to rsync my current folder to a server, and run a command there.

#! /bin/bash
echo "running script"

LAST_SEGMENT=`dirs +0 | sed "s/~\///"`
echo $LAST_SEGMENT

rsync -rdtvP . rsync://ec2-user@XX.XX.XX.XX/ftp/$LAST_SEGMENT

ssh ec2-user@XX.XX.XX.XX << EOF
    cd ~/ftp/$LAST_SEGMENT
    $@
EOF

I then made a bash function called rr to call the script. This lets me prefix a command like cargo test with rr to easily remotely run code on the server. However I would eventually like to see rust support come more natively (or as natively as x86 emulation can get it) to iSH so builds can be done locally.

I did look into some alternatives to this approach, but I found some issues with each one.

  • Working Copy has a very similar workflow called ‘SSH Command’ but I had some trouble making it work with a shortcut. That made repeated use unwieldy.
  • Textastic also has an SSH terminal, but doesn’t have an easy way (as far as I can tell) to keep a whole folder synced to a remote server, preferring FTP for sending individual files back and forth.
  • Another option is mounting the server’s file system as a remote file system via the Files app. This does work, but it is slow, and difficult to know when the files have finished syncing, making build commands on the remote server unreliable.
  • A final option is to go full remote, and just SSH into the remote machine, and use vim, but I’m not that great at vim and I was hoping for local editing. I did end up trying out vim locally, so I may revisit this.

The issues made the editor apps too unwieldy to use directly for rapid code-build-test cycles. By putting iSH and one of the other apps side by side or alt-tabbing between them, I could run the required commands. Initially iSH had issues with regaining keyboard focus where it would be difficult to start typing. It took me a bit to figure out, but disabling the “Settings > External Keyboard > [Extra Keys] Hide with external keyboard” fixes the focus issue.

Overall I managed to develop some rust code, I tried out vim and I learned a lot about the limitations for writing code on the iPad. I’m very excited for the future of iPad-based software development. With the new M1 Macs I foresee greater software compatibility between the branches of Apples ecosystem. The iSH app is always getting bug fixes and updates. I wouldn’t encourage anyone to dump their Mac just yet, but I’m looking forward to future developments in this area.


External links:

Blog post on developing in C on iPad. Gives a good overview of the process. I was able to get clang to work, so YMMV and the app is constantly being updated.

iSH GitHub page

Steve Losh vimrc configuration I used this for my experimental vim setup

P.S. Before I figured out the keyboard focus fix, the issues lead to me trying to improve my knowledge of vim and try development solely in iSH via vim. That was interesting, and I might try extending my knowledge there in the future.