Skip to content

Instantly share code, notes, and snippets.

@achanda
Last active March 8, 2018 03:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achanda/9e87c2e96999bfc51f66c1467ac7e208 to your computer and use it in GitHub Desktop.
Save achanda/9e87c2e96999bfc51f66c1467ac7e208 to your computer and use it in GitHub Desktop.
Dot execing Rust
  • Wrapper script
root@dev:~# cat `which rustwrap`
#!/usr/bin/env bash

rustc "$1" -o foobar && shift && ./foobar "$@"
  • Mount binfmt_misc
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  • Activate 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
  • Test code
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);
}
  • Set exec flag
chmod u+x test.rs
  • Run!
root@dev:~# ./test.rs foo bar
["foo", "bar"]
root@dev:~# echo $?
123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment