rustc-php: A Rust compiler written in PHP
A Rust compiler written in PHP that emits x86-64 Linux ELF binaries directly (no LLVM, no assembler, no linker). Implements ownership checking, borrow checking, type checking, move semantics, generics, traits, closures, and iterators. Useful if you need to compile Rust on a shared hosting server from 2008 where the only installed runtime is PHP.
Installation
In order to execute Rust code you of course first need to install PHP. You can do this easily on Windows 11 by running:
winget install PHP.PHP.8.4
This compiler outputs valid machine code for Linux, so the most practical approach if you're on Windows is to use WSL. Start by installing Ubuntu (if you haven't already):
wsl --install
After the install completes, reboot your machine and then open Ubuntu from the Start menu to finish the initial setup.
Usage
Compile a .rs file by running:
... continue reading