Skip to content

Instantly share code, notes, and snippets.

@bluenote10
Forked from flaviut/nimrun
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluenote10/3c260c2e3bdedb9ccb0a to your computer and use it in GitHub Desktop.
Save bluenote10/3c260c2e3bdedb9ccb0a to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# A wrapper around the Nim compiler to allow for easy scripting of Nim. Puts
# all temporary files in a temporary directory and cleans up after itself.
#
# Usage:
# - add `#!/usr/bin/env nimrun` at the beginning of your script
# - execute the nim file with it, for example, `nimrun file.nim args`
#
# Possible future extentions:
# - cache compilation results for a while
# - configurable temporary directory
# - allow for custom `nim c` parameters
#
# Author: Flaviu Tamas <tamas.flaviu@gmail.com>
# Copyright (c) 2014 Flaviu Tamas
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
output=$(mktemp -d)
trap "rm -rf $output" EXIT
nim c --verbosity:0 \
--hints:off \
--out:"$output/executable" \
--nimcache:"$output/" \
--parallelBuild:1 \
"$1"
compiler_exit=$?
echo "Compiler Exit: $compiler_exit"
# first argument is filename, not needed any more
shift
if [ "$compiler_exit" -eq 0 ] ; then # compile success
$output/executable $*
exit $?
else # compile fail
exit $compiler_exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment