Recently I learned about amp, a text editor that might lure me away from vim. Intrigued by the idea, I tried to install it. I really tried, but I couldn’t manage it. I learned that I had some kind of dependency problem that I could solve by using the most recent tools for the Rust programming language.

I don’t want to learn Rust (yet), but I’d like to try amp as a potential new go-to text editor. I wasn’t in the mood to learn enough about Rust tools to resolve the problem myself, so I posted an issue to github.

Fortunately, nice people gave me reasonable-sounding instructions, so I’m trying them. (Spoiler: they worked on my machine. Read on.)

The Sitch

I’m on Pop!_OS 18.04, which is mostly Ubuntu 18.04. I tried to follow these instructions, and I ended up with a compile error that seems to relate to a dependency version mismatch with libssh2-sys-0.2.11. And I literally have no idea what that signifies. I understand the individual words, but not the significance of the sentence as a whole.

According to this Rust-related issue, this might signal an out-of-date version of Rust. I assume that whatever version of Rust I have came when I installed cargo and that puts me out of rocks. I just started using cargo minutes earlier, so I don’t know how it installs a Rust compiler nor how to change it nor whether somehow, magically, at some point in the past I accidentally installed some out-of-date version of the Rust development environment….

Evidently, since I’d tried to install cargo through the Ubuntu package manager apt, I probably got an out-of-date version, which led me to this dependency mismatch. I suppose this illustrates the down side of using package managers with rapidly-evolving software. Since then, I have removed cargo from my system in the hopes of returning it to its previous state. With luck, I have nothing hanging around that will interfere with installing amp in the future.

Some Hope

I have gleaned from the comments on my amp issue the following instructions:

  1. Install a stable version of Rust using rustup.
  2. Install cargo, and presumably it will use the stable version of Rust that I would have just installed.
  3. Run cargo install --git https://github.com/jmacdonald/amp, which I’d tried earlier, and which led me to this mess and to writing these words.

So let me try.

Let Me Try

I follow the instructions at https://www.rust-lang.org/en-US/install.html to install rustup, which seems to be like sdkman in the Java world, rvm for Ruby, and so on.

I see a version of Rust from literally 8 days ago. I feel very bleeding-edge.

$ curl https://sh.rustup.rs -sSf | sh
[Many instructions, some of which provide evidence of installing up-to-date rust and cargo.]

So I seem to get two for the price of one. I will need to move $HOME/.cargo to where I store my dotfiles in a git repository and then stow it. No problem. I will also need to commit changes to my shell profile scripts, so before I continue, let me check that my dotfiles repository is clean.

# In another shell
$ cd $DOTFILES_PROJECT_ROOT
$ git status -s
[No uncommitted changes.]

Since my dotfiles are clean, I can continue. I can uninstall any time with rustup self uninstall, so I note that command here in this article so that I might remember where to look for it later.

I continue with the installation using the default options, because—and I can’t stress this enough—I don’t know what I’m doing.

Back in the first shell window, where I’m installing rustup, I choose Proceed with installation (default) because it is the default, then I see evidence of installing something.

Rust is installed now. Great!

Before I go anywhere and do anything, I commit changes to my dotfiles.

$ cd $DOTFILES_PROJECT_ROOT
$ git status -s
[I see changes to .profile and .bash_profile, but strangely not .zprofile, so I guess I don't have one. I still don't understand the difference between the profile files and the env files and the rc files.]
$ git add -A
$ git commit -m "Installed Rust and Cargo with rustup."
$ git push offsite-backup
$ popd
# I have `cd` aliased to `pushd`, so every `cd` is just a `pushd`. I like it.

Next, I add cargo to my system path.

$ source $HOME/.cargo/env
$ env | grep -i cargo
PATH=/home/jbrains/.cargo/bin:[the rest of my PATH variable]

Next, I move .cargo to where I track my dotfiles, then stow it.

$ mkdir -p $DOTFILES_PROJECT_ROOT/system76-laptop/cargo
$ mv $HOME/.cargo $DOTFILES_PROJECT_ROOT/system76-laptop/cargo
$ stow -t $HOME -d $DOTFILES_PROJECT_ROOT/system76-laptop cargo
$ ls -al $HOME | grep cargo
[Evidence that $HOME/.cargo points to the expected place in my dotfiles repository.]

This requires committing new changes to my dotfiles.

$ cd $DOTFILES_PROJECT_ROOT
$ git add -n .
[I see lots of stuff that probably shouldn't be in git, because I can download it.]
$ cd system76-laptop/cargo/.cargo
$ vim .gitignore
# In .gitignore
# Stuff I can download any time
registry
bin
# A nested git repository that I'm not going to track
git
$ git status -s
add 'system76-laptop/cargo/.cargo/.crates.toml'
add 'system76-laptop/cargo/.cargo/.gitignore'
add 'system76-laptop/cargo/.cargo/env'
[MUCH better. That all looks like pure configuration files.]
$ git add -A
$ git commit -m "We can now stow Cargo."
$ git push offsite-backup
$ popd
# I have `cd` aliased to `pushdga`, so every `cd` is just a `pushd`. I like it.
$ ls -al $HOME | grep cargo
lrwxrwxrwx  1 jbrains jbrains     70 Sep 21 14:49 .cargo -> $DOTFILES_PROJECT_ROOT/system76-laptop/cargo/.cargo

Now I can try to do something with cargo.

Let’s Do Something With cargo

In principle, I should now be able to install amp with cargo. Let’s see.

$ cargo install --git https://github.com/jmacdonald/amp
[...]
   Compiling gag v0.1.10
   Compiling num-traits v0.1.43
   Compiling thread-id v2.0.0
error: failed to run custom build command for `onig_sys v68.0.1`
process didn't exit successfully: `/tmp/cargo-installES1HqJ/release/build/onig_sys-4b9d7f80a3b9005f/build-script-build` (exit code: 101)
--- stdout
running: "cmake" "/mnt/extra-space/Workspaces/dotfiles/system76-laptop/cargo/.cargo/registry/src/github.com-1ecc6299db9ec823/onig_sys-68.0.1/oniguruma" "-DBUILD_SHARED_LIBS=OFF" "-DCMAKE_INSTALL_PREFIX=/tmp/cargo-installES1HqJ/release/build/onig_sys-849a1e77a747337f/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_BUILD_TYPE=Release"

--- stderr
thread 'main' panicked at '
failed to execute command: No such file or directory (os error 2)
is `cmake` not installed?

build script failed, must exit now', /home/jbrains/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.31/src/lib.rs:643:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: failed to compile `amp v0.5.0 (https://github.com/jmacdonald/amp#07e6c192)`, intermediate artifacts can be found at `/tmp/cargo-installES1HqJ`

Caused by:
  build failed

Nope.

Interesting… “is cmake not installed?” Let’s see.

$ cmake
zsh: command not found: cmake

Fine. How do I install it, then?

Oh, boy. According to https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/, this will take some work.

Install cmake

$ python3 --version
Python 3.6.5
[OK.]
$ sudo apt-get update
$ sudo apt-get upgrade
[Installing a handful of libraries, including something related to python. Maybe that's good news?]
$ sudo apt-get install build-essential cmake unzip pkg-config
[Indeed, cmake was not installed. Now it is installing.]

That wasn’t so bad! Let’s see whether that fixes the entire problem.

$ cargo install --git https://github.com/jmacdonald/amp

This runs for a few minutes. And then it stops. And it appears to work!

Run amp

$ amp
[Something that looks like a text editor and an empty buffer. Yay!]

All right! Now… how exactly does one use amp?