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:
Ensure you have your Distro's equivalent of a base-devel package installed and/or mingw:
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:
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:
- Visual C++ Build Tools
- Windows 10 SDK
- Windows 11 SDK
This process can be somewhat reliabily automated by running:
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:
Windows cross compilation:
Linux cross compilation:
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):
For compiling Linux ARM binaries, you might need:
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.
name: make-pyaket
on:
workflow_dispatch:
jobs:
main:
name: Compile on (${{matrix.os}})
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- 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/*