├── LICENCE ├── README.md ├── nimrun └── test ├── runtest ├── space dir └── test.nim ├── subdir └── test.nim └── test.nim /LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, 2015 Flaviu Tamas 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nimrun 2 | 3 | A wrapper around the Nim compiler to allow for easy scripting of Nim. Puts 4 | all temporary files in a temporary directory and cleans up after itself. 5 | 6 | This script is implemented in shell. If you'd like a pure Nim implementation, 7 | [check out Jeff Ciesielski's nimr][jeff-nimr], which can be installed by just 8 | running `nimble install nimr`! 9 | 10 | [jeff-nimr]: https://github.com/Jeff-Ciesielski/nimr 11 | 12 | # Usage 13 | 1. Download the script from [here][nimrun] and add it to your path. 14 | 2. Use it in one of the following ways: 15 | - add `#!/usr/bin/env nimrun` at the beginning of your script 16 | - execute the nim file with it, for example, `nimrun file.nim args` 17 | 18 | [nimrun]: https://raw.githubusercontent.com/flaviut/nimrun/master/nimrun 19 | 20 | 21 | # Possible future extentions: 22 | - cache compilation results for a while 23 | - configurable temporary directory 24 | - allow for custom `nim c` parameters 25 | -------------------------------------------------------------------------------- /nimrun: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Copyright (c) 2014 Flaviu Tamas 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | # First try compilers which are known to be fast(er than GCC) 24 | if command -v tcc >/dev/null 2>&1; then 25 | COMPILER=--cc:tcc 26 | elif command -v clang >/dev/null 2>&1; then 27 | COMPILER=--cc:clang 28 | fi 29 | 30 | output=$(mktemp -d -t -- "$(basename "${1}").XXXX") 31 | trap "rm -rf $output" EXIT 32 | 33 | nim c --verbosity:0 \ 34 | --hints:off \ 35 | $COMPILER \ 36 | --out:"$output/executable" \ 37 | --nimcache:"$output/" \ 38 | "$1" 39 | 40 | compiler_exit=$? 41 | 42 | # first argument is filename, not needed any more 43 | shift 44 | 45 | if [ "$compiler_exit" -eq 0 ]; then # compile success 46 | # "$@" is necessary to preserve whitespaces in arguments, which $* doesn't 47 | $output/executable "$@" 48 | exit $? 49 | else # compile fail 50 | exit $compiler_exit 51 | fi 52 | -------------------------------------------------------------------------------- /test/runtest: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TOTAL_NO=1 4 | FAIL_NO=0 5 | 6 | fail() { 7 | echo "fail $TOTAL_NO" 8 | ((FAIL_NO += 1)) 9 | ((TOTAL_NO += 1)) 10 | } 11 | 12 | success() { 13 | echo "success $TOTAL_NO" 14 | ((TOTAL_NO += 1)) 15 | } 16 | 17 | 18 | ../nimrun ./subdir/test.nim 1>&2 > /dev/null && success || fail 19 | ../nimrun ./test.nim 1>&2 > /dev/null && success || fail 20 | ../nimrun ./space\ dir/test.nim 1>&2 > /dev/null && success || fail 21 | ../nimrun "./space dir/test.nim" 1>&2 > /dev/null && success || fail 22 | 23 | 24 | exit $FAIL_NO 25 | -------------------------------------------------------------------------------- /test/space dir/test.nim: -------------------------------------------------------------------------------- 1 | echo 3 2 | -------------------------------------------------------------------------------- /test/subdir/test.nim: -------------------------------------------------------------------------------- 1 | echo 2 2 | -------------------------------------------------------------------------------- /test/test.nim: -------------------------------------------------------------------------------- 1 | echo 4 2 | --------------------------------------------------------------------------------