root@dev:~# cat `which rustwrap`
#!/usr/bin/env bash
rustc "$1" -o foobar && shift && ./foobar "$@"
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
echo 1 > /proc/sys/fs/binfmt_misc/status
- Register Rust as a binary format
echo ':rust:E::rs::/usr/local/bin/rustwrap:OC' | sudo tee /proc/sys/fs/binfmt_misc/register
root@dev:~# cat test.rs
use std::process;
use std::env;
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
println!("{:?}", args);
process::exit(123);
}
chmod u+x test.rs
root@dev:~# ./test.rs foo bar
["foo", "bar"]
root@dev:~# echo $?
123