Skip to content

Rust

Warning

This section is outdated and needs a cleanup/rewrite:

  • Cross compilation to MacOS needs an SDK
  • Rust is now auto-provided by Rustbin

📦 Pyaket uses the rust programming language for its core functionality.

Developing or compiling rust projects requires a toolchain - collection of a compiler, project manager, standard library, and other tools. Luckily, the official installation method rustup manages it all for you, including cross compilation (except for a few external dependencies).

All major platforms are supported, though some might be problematic for your project.

Native


Linux

Install rustup with the official installation script, or from your package manager:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Ensure you have your Distro's equivalent of a base-devel package installed and/or mingw:

# Native compilation
sudo apt install build-essential

# Cross compilation
sudo apt install mingw-w64
# Native compilation
sudo pacman -Syu base-devel

# Cross compilation
sudo pacman -Syu mingw-w64-toolchain
# Native compilation
sudo dnf install gcc

# Cross compilation
sudo dnf install mingw64-gcc
# Native compilation
sudo apt install build-essential

# Cross compilation
sudo apt install mingw-w64

This script should have added ~/.cargo/bin to your PATH environment based on your shell.

Note: You may need to restart the terminal to have cargo and rustc available, ensure it.


Windows

Ensure you have WinGet installed, open a powershell and run:

winget install --id=Rustlang.Rustup -e

There's two options for a C linker/compiler now, MinGW or Visual C++ Build Tools (MSVC).

Reason: Rust can't bundle Build Tools due licensing, out of two let the user choose one. Some crates links against system libraries, such as zstd or networking, and need to interface with C.

Overall, it's easier to get started with MinGW, which is needed for cross compiling to macOS and Linux anyway. Go with MSVC if you prefer official Microsoft tools or will only target Windows.


MinGW

Download and install MSYS2, a lightweight Linux-like shell and package manager for Windows, in the default location at C:\msys64.

That's it: The python package will auto install dependencies for the platform you're compiling for


MSVC

To avoid any potential confusion, here's a brief clarification on product names:

  • Visual Studio is a full IDE for C#, C++, .NET development, the original one (purple) #
  • Visual Studio Code is a lightweight code editor with many extensions (blue) #
  • Visual Studio Build Tools is just the compiler, linker for C/C++, without the IDE #

Download and install Build Tools for Visual Studio, enable the following components:

  1. Visual C++ Build Tools
  2. Windows 10 SDK
  3. Windows 11 SDK

This process can be somewhat reliabily automated by running:

PowerShell
winget install --id Microsoft.VisualStudio.2022.BuildTools `
    --override " `
        --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
        --add Microsoft.VisualStudio.Component.Windows10SDK `
        --add Microsoft.VisualStudio.Component.Windows11SDK `
    " `
    --wait --passive

You should have cl.exe, link.exe and msvc.exe available in your shell.


macOS

Install Homebrew and Xcode, then rustup with:

brew install rustup

Windows cross compilation:

brew install mingw-w64

Linux cross compilation:

brew install gcc