Skip to content

🦀 Rust

📦 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, rustup, the official installation method, manages it all for you, including cross compilation; except for few external dependencies.

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

Native

✅ You can run $ pyaket rust to install everything you need for your platform!

Windows

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

1
winget install --id=Rustlang.Rustup -e

There's two options for a C linker/compiler, 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 MSVC if you're in a hurry or prefer official Microsoft tools - at the cost of maybe needing a license for medium companies. MinGW isn't bad, just extra steps.


MSVC

To avoid any potential confusion, here's a brief clarification on confusing products:

  • 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:

1
2
3
4
5
6
7
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.22000 `
    " `
    --wait --passive

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


MinGW

Download and install MSYS2, a lightweight Linux-like shell and package manager for Windows. Their homepage conveniently lists instructions for installing the MinGW toolchain 🙂

Either way, search for a MSYS2 Terminal application in your system, and run:

1
pacman -Sy mingw-w64-ucrt-x86_64-gcc

Note: MinGW will only be available inside the MSYS2 terminal, you might need to cd into your project's directory with cd /c/Users/user/.../Project, activate the venv with activate.sh.


Linux

Ensure you have your Distro's equivalent of a base-devel package installed, and rustup:

1
2
3
4
5
# Update the package list
sudo apt update

# Native compilation and rustup
sudo apt install rustup build-essential -y
1
2
3
4
5
# Native compilation and rustup
sudo pacman -Syu rustup base-devel

# Windows cross compilation
sudo pacman -Syu mingw-w64-toolchain
1
2
3
4
5
# Native compilation and rustup
sudo dnf install rustup gcc

# Windows cross compilation
sudo dnf install mingw64-gcc
1
2
3
4
5
# Update the package list
sudo apt update

# Native compilation and rustup
sudo apt install rustup build-essential -y

Either way, running rustup's official command should work too:

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

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.


macOS

Ensure you have Homebrew and Xcode installed, install rustup with:

1
brew install rustup


Workflows

GitHub Actions

Runners seem to already have rustup installed by default. Better be safe than sorry though - you can add the following action in your workflow job steps by @dtolnay (unofficial):

1
2
- name: Install Rust
  uses: dtol/rust-toolchain@stable

For compiling Linux ARM binaries, you might need:

1
2
- name: Install gcc aarch64
  run: sudo apt install -y gcc-aarch64-linux-gnu

A full workflow file could look like this:

Ensure wider compatibility by compiling with the oldest Linux runner you can get

The final binary will only work with the glibc version greater than or equal to the one used to compile it of the host. This is a core part of the Linux ABI, desktop distros are well updated but servers or embedded systems may not be.

.github/workflows/make-pyaket.yml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
name: make-pyaket

jobs:
  main:
    name: Compile on (${{matrix.os}})
    runs-on: ${{matrix.os}}
    strategy:
      matrix:
        os: [ubuntu-22.04, windows-latest, macos-latest]
    steps:

      # Checkout repository, install dependencies, etc.

      - name: Install gcc aarch64
        if: ${{matrix.os == 'ubuntu-22.04'}}
        run: sudo apt install -y gcc-aarch64-linux-gnu

      - name: Compile projects
        run: pyaket (...)

      - name: Upload releases
        uses: actions/upload-artifact@v4
        with:
          name: ${{matrix.os}}-release
          path: Release/*