User:Legoktm/Rust on Toolforge

From Wikitech
Jump to navigation Jump to search

Rust is not currently officially supported on Toolforge. Here are some tips:

Compiling Rust code

When it comes to building your Rust project, you have two primary options. The first and depending upon your hardware, faster, option is to build it on your own machine. It is recommended to do this in a Debian 10/Buster environment (in a VM, container, etc.), to make sure you're linking against compatible system libraries (usually libc and libssl). A brief test of building on Fedora 31 also worked. You may want to look into cross-compiling if you're on macOS/Windows. Ideally we would be able to use a Toolforge docker image for the building process (even on our own machines) but that's not practical yet since all of the potential images are missing at least libssl-dev.

If you want to build your project on Toolforge, you'll need to use the grid engine. First, install rustup in your tool. Since you only want to build code, you only need the minimal profile: curl https://sh.rustup.rs -sSf | sh -s -- --profile minimal. If you want nightly, pass --default-toolchain nightly.

Assuming your project is cloned to ~/www/rust, try something like: jsub -N build -mem 2G -sync y cargo install --path ~/www/rust --locked. Depending on what exactly you're building, you may need to bump the memory limit. The -sync y option allows for easy scripting once the build completes, e.g. running webservice restart.

webservice

Your code will need to start a webserver on port 8000 (you can hardcode this) and listen on 0.0.0.0.

Once your binary is on Toolforge, start a webservice via webservice golang111 start .cargo/bin/$NAME. Add extra options like --canonical as necessary. I recommend putting these options in a ~/service.template so you don't need to remember them each time:

backend: kubernetes
canonical: True # Only if your tool previously used the tools.wmflabs.org/$TOOL domain scheme
type: golang111
extra_args:
  - .cargo/bin/$NAME

Note that while any "generic" webservice can be used, Legoktm recommends using the golang111 so we can more easily track Rust projects.

Tools using Rust

If a tool you wrote or use is using Rust on Toolforge, please add to this list!

MediaWiki-related crates