Help:Toolforge/Rust

From Wikitech
Jump to navigation Jump to search

Rust is a relatively new language, but is rapidly gaining popularity and regularly voted as developers' favorite language. Rust prioritizes safety while enabling high performance (fearless concurrency).

On Toolforge the use of Rust is supported by fellow community members who are also using Rust.

New to Rust? Check out the My first Rust tool tutorial!

Rust toolchain

Main article: Tool:rustup

The standard way to install Rust for development purposes is to use rustup. On Toolforge, rustup is already available, but needs to be enabled for your tool.

$HOME/.profile
. "/data/project/rustup/rustup/.cargo/env"
export RUSTUP_HOME=/data/project/rustup/rustup/.rustup

For this to take effect, you need to manually source your new profile (source $HOME/.profile). For future logins, this will automatically be taken care of.

You should now be able to see that Rust is installed and what the current version is:

$ rustc --version
rustc 1.56.1 (59eed8a2a 2021-11-01)

If you need a different version of Rust (e.g. nightly), please ask one of the "rustup" tool maintainers to install it.

Compiling Rust code

To compile Rust code in Toolforge, use the grid engine. This is recommended because it ensures you will link against compatible versions of system libraries (typically libc and libssl) and also keeps the Rust source on Toolforge, making it easier to fork.

$ cd /path/to/project
$ time jsub -N build -mem 2G -sync y -cwd cargo build --release
Your job 2997363 ("build") has been submitted
Job 2997363 exited with exit code 0.

real	5m51.013s
user	0m0.127s
sys	0m0.071s

If the build fails, the error log containing the reason will be at $HOME/build.err.

Local compilation

You can also compile code locally and copy the resulting binary to Toolforge. Depending on your hardware, this might be faster.

It is recommended to do this in a Debian environment (in a VM, container, etc.) to make sure you're linking against compatible system libraries (usually libc and libssl). Windows/macOS users may want to look into cross-compiling, targetting either x86_64-unknown-linux-gnu or x86_64-unknown-linux-musl.

Running a 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. You can put these options in a $HOME/service.template so you don't need to remember them each time:

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

Then a plain webservice start will start up your webservice!

Note that while any "generic"-type webservice can be used, Legoktm recommends using the golang111 so we can more easily track Rust projects. In the future a Rust type might be added.

Running a job

You should be able to just run jobs on the grid, like you would with any other application.

If you are using the (currently beta) toolforge-jobs service, it is recommended you use the tf-bullseye-std (standalone) container, which only has basic system libraries like libc, libssl, and libmysqlclient available.

Tools using Rust

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

See also

Communication and support

We communicate and provide support through several primary channels. Please reach out with questions and to join the conversation.

Communicate with us
Connect Best for
Phabricator Workboard #Cloud-Services Task tracking and bug reporting
IRC Channel #wikimedia-cloud connect
Telegram bridge
mattermost bridge
General discussion and support
Mailing List cloud@ Information about ongoing initiatives, general discussion and support
Announcement emails cloud-announce@ Information about critical changes (all messages mirrored to cloud@)
News wiki page News Information about major near-term plans
Cloud Services Blog Clouds & Unicorns Learning more details about some of our work
Wikimedia Technical Blog techblog.wikimedia.org News and stories from the Wikimedia technical movement