Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Last active February 28, 2022 20:57
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 brendanzab/8253053 to your computer and use it in GitHub Desktop.
Save brendanzab/8253053 to your computer and use it in GitHub Desktop.

Prototyping Rust Code in CodeRunner

CodeRunner is a nifty little app for OSX that allows you to play around with test code with minimal fuss. Here are some instructions for setting it up to build Rust code.

CodeRunner

Setup instructions

  1. Go to CodeRunner > Preferences...
  2. Select the Languages tab
  3. Down the bottom of the list view, click the plus sign to add a new language called Rust
  4. Enable the Language uses compilation script checkbox, and click Edit script
  5. Copy the following code into compile.sh:
#!/bin/bash

compname=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
rustc $3 "$1" -o "$compname"
status=$?
if [ $status -eq 0 ]; then
    echo $compname
    exit 0
elif [ $status -eq 127 ]; then
    echo -e "\nTo run code in this language, you need to install the Rust compiler from https://github.com/mozilla/rust/."
fi
exit $status
  1. In the Run Command textbox, enter ./$compiler.
  2. Add the following text to the Code Template:
fn main() {
    %@
}
  1. Set the Syntax Mode to None
  2. Enter rs for the File Extension
@taliesinb
Copy link

Broken for me until I did "] then" -> "]; then".

@ttdonovan
Copy link

When attempting to run the same code snippet as in the screenshot above I receive a "Untitled: No such file or directory". I am wondering if there are other path variables or configuration settings I am missing in CodeRunner.

CodeRunner

@brendanzab
Copy link
Author

Sorry guys for the late replies, gist doesn't seem to notify you of comments.

@taliesinb woops, updated

@ttdonovan Not sure. Could you post an image of your prefs? Btw, are you running 0.9-pre? The 'no debug symbols' thing has been fixed for a while.

@sivabudh
Copy link

Hey, thanks a lot for posting this. You rock.

@ianwalter
Copy link

Here is what I got on CodeRunner 2:

error: couldn't read .: IoError { kind: InvalidInput, desc: "couldn\'t open path as file", detail: Some("is a directory; path=.; mode=open; access=read") }

@perkinsb1024
Copy link

In CodeRunner 2, the names of the arguments have changed, so the code needs to be updated slightly. I've verified that a simple "Hello, World" program will compile and run in CodeRunner 2 by changing:
$1 to $CR_FILENAME
$3 to $@

So your compile.sh should look like this:

#!/bin/bash

compname=`echo "$CR_FILENAME" | sed 's/\(.*\)\..*/\1/'`
rustc $@ "$CR_FILENAME" -o "$compname"
status=$?
if [ $status -eq 0 ]; then
    echo $compname
    exit 0
elif [ $status -eq 127 ]; then
    echo -e "\nTo run code in this language, you need to install the Rust compiler from https://github.com/mozilla/rust/."
fi
exit $status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment