Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active September 3, 2024 17:37
Show Gist options
  • Save korakot/ae95315ea6a3a3b33ee26203998a59a3 to your computer and use it in GitHub Desktop.
Save korakot/ae95315ea6a3a3b33ee26203998a59a3 to your computer and use it in GitHub Desktop.
Install rust, cargo in Colab
# run this once, then reload, and then skip this
!apt install rustc
!gdown --id 1PULtTc-2e9z4bswh_SQqL5oy_4JpfV7c
!chmod +x evcxr_jupyter
!./evcxr_jupyter --install
// install dependency
:dep cmd_lib
use cmd_lib::run_cmd as sh;
# just to use with python
!apt install rustc
%env USER=korakot
@dimitrilw
Copy link

One last comment I should have shared: those codespaces will auto-load your personal dotfiles repo, too: Github doc pages re loading dotfiles. If you use dotfiles repos to manage your configs, this is a real win. .....I'll stop now. I realize I've drifted way off-topic, but I didn't want to miss details that others may need, should they try this out for themselves.

@mateusvmv
Copy link

Managed to run evcxr by proxying the IPC connection to TCP, as it expects. It needs both cargo and rustc installed, and they can be installed via apt, which is faster. Below is code which uses nix instead of apt to install most of the stuff: run once, change runtime and restart.

!rm -rf /root/.local/share/jupyter/kernels

# Nix install
!curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux --init none --no-confirm
!ln -s /root/.nix-profile/bin /opt/bin

# Install evcxr
!nix-env -f '<nixpkgs>' -iA cargo rustc evcxr sccache
!evcxr_jupyter --install

# Configure evcxr
!mkdir -p /root/.config/evcxr
!printf ":timing\n:sccache 1" > /root/.config/evcxr/init.evcxr

# IPC Proxy (https://stackoverflow.com/a/74821762)
!wget -qO- https://gist.github.com/SpencerPark/e2732061ad19c1afa4a33a58cb8f18a9/archive/b6cff2bf09b6832344e576ea1e4731f0fb3df10c.tar.gz | tar xvz --strip-components=1
!python install_ipc_proxy_kernel.py --quiet --kernel=rust --implementation=ipc_proxy_kernel.py > /dev/null

# To avoid confusion between kernel names
!sed -i 's/"display_name": "Rust"/"display_name": "Rust-TCP"/g' /root/.local/share/jupyter/kernels/rust_tcp/kernel.json

@wiseaidev
Copy link

Many thanks to @mateusvmv efforts and friends here in this discussion. I put together a bash script that overwrites the current kernel and spins up a new Rust kernel without manual config:

# This script sets up and spins up a Jupyter Notebook environment with a Rust kernel using Nix and IPC Proxy. 
!wget -qO- https://gist.github.com/wiseaidev/2af6bef753d48565d11bcd478728c979/archive/3f6df40db09f3517ade41997b541b81f0976c12e.tar.gz | tar xvz --strip-components=1
!bash setup_evcxr_kernel.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment