{"id":16426647,"url":"https://github.com/gochomugo/crun","last_synced_at":"2025-03-21T04:30:24.157Z","repository":{"id":79431594,"uuid":"48801705","full_name":"GochoMugo/crun","owner":"GochoMugo","description":"Run C/C++ scripts, just like you would do with Python, Ruby etc.","archived":false,"fork":false,"pushed_at":"2024-08-23T02:06:59.000Z","size":49,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T20:43:22.096Z","etag":null,"topics":["c","c-plus-plus","cpp"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GochoMugo.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-30T13:24:02.000Z","updated_at":"2024-08-23T02:07:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6f6c7c0-6a29-4986-a6aa-70967c9d6913","html_url":"https://github.com/GochoMugo/crun","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GochoMugo%2Fcrun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GochoMugo%2Fcrun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GochoMugo%2Fcrun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GochoMugo%2Fcrun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GochoMugo","download_url":"https://codeload.github.com/GochoMugo/crun/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244737992,"owners_count":20501746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-plus-plus","cpp"],"created_at":"2024-10-11T08:09:49.249Z","updated_at":"2025-03-21T04:30:23.888Z","avatar_url":"https://github.com/GochoMugo.png","language":"Shell","readme":"# crun\n\n\u003e Run **C/C++** scripts, just like you would do with Python, Ruby etc.\n\u003e\n\u003e [![Build Status](https://travis-ci.org/GochoMugo/crun.svg?branch=master)](https://travis-ci.org/GochoMugo/crun)\n\n\n## demo:\n\n1. My C script, `test.c`:\n\n    ```c\n    #!/usr/bin/env crun\n    /* -Wall -O3 */\n\n    #include \u003cstdio.h\u003e\n\n    int main(int argc, char *argv[]) {\n        printf(\"Hello, world %s!\", argv[1]);\n        return 0;\n    }\n    ```\n\n    **Note:** We added a shebang on the 1st line! (`#!/usr/bin/env crun`) \u003cbr/\u003e\n    **Note:** We added flags to be used in compilation in 2nd line! (`-Wall -O3`)\n\n2. Make it executable\n\n    ```bash\n    $ chmod +x test.c\n    ```\n\n3. Run it\n\n    ```bash\n    $ ./test.c Koninchwa\n    ```\n\n    **Note:** We can pass arguments to the script! (`Koninchwa`)\n\n\n## rationale:\n\nI just love C! (and why not?!) Okay! This allows me to write more C code\nfor day-to-day tasks, not just when you want to speed up some component\nof an application. It makes C more practical for use. Also, it is really\nhandy when you are learning C/C++; everything important is contained in the\nsingle file.\n\nThe first time you invoke a crun script, it is compiled using\n`cc` (for C files with extension `.c`) or `g++` (for CPP files with\nextensions other than `.c`) in\nthe directory holding the script, stored away in `/tmp/crun` and run\nimmediately. Subsequent invocations will run the compiled executable,\nrather than re-compile, unless the source file has been modified\n(in which case we compile!).\n\nIf you may want to change the directory where the executables are stored,\nyou can use the `${CRUN_CACHE_DIR}` variable. This is useful if you wish\nto cache executables across restarts. If no directory exists at\n`${CRUN_CACHE_DIR}` yet, it will be created using `mkdir -p`. Make sure\n`crun` has permissions to write to the directory.\n\nIf you have compilation flags that you need to be passed to `cc`/`g++`, you\nplace them in the **2nd line** separately, inside a comment using `/*` and\n`*/`. For example,\n\n```c\n/* -Wall -O3 */\n```\n\n**Note**: While you can start your code in the 2nd line, it is advisable\nyou **avoid** doing so since `crun`, in the case the 2nd line contains `/*`\nand `*/`, will assume it's being fed compilation flags. This may lead\nto some weird compilation errors!\n\n\n### extras:\n\nBy default, bash expressions in the string holding the flags are **not**\nare evaluated. This is a neat feature **but** I do understand it adds a\nnew edge in the attack graph. You will need to **explicitly** enable\nthis feature, using the environment variable `${CRUN_DO_EVAL}` or\nthe command-line argument `--do-eval`.\nIf enabled, a string such as `/* $(pkg-config --libs libuv) */`\nfor the compilation flags will be evaluated. So,\n\n```bash\n$ export CRUN_DO_EVAL=1  # you could place this in your ~/.bashrc (or equivalent)\n\n# OR\n\n$ crun --do-eval filename.c\n```\n\n**Note**: Do **not** run scripts you do **not** trust, **even if**\neval is disabled! Always remember, **no** system/application can\never be 100% secure!\n\nTo allow maximum efficiency, you can create a quick template of a script\nusing:\n\n```bash\n$ crun --create my_script\n```\n\nThis will create an executable crun script that you can edit to add the meat.\n\nIn some cases, you want the script re-compiled, maybe you've modified some\nlibrary files. To bypass the cache:\n\n```bash\n$ crun --force-compile my_script\n```\n\nSometimes, you may want to debug your script with `gdb`, or you just want to\nskip running the compiled executable:\n\n```bash\n$ crun --just-compile my_script\n```\n\nSince `--just-compile` will make crun **not** run your executable,\nany arguments passed will be considered to be more compilation flags to\nuse. It also echo's back the path to the compiled executable.\nSo you could do something like:\n\n```bash\n$ gdb `crun --just-compile script.c -Wall -g`\n$ valgrind --leak-check=yes `crun --just-compile script.c -Wall -g` arg1 arg2\n```\n\n\n## installation:\n\nIt's simple!\n\n1. [Download crun.sh][dl]\n2. Rename it to `crun`\n3. Place it in a directory in your `$PATH`.\n\nFor example,\n\n```bash\n$ cd ~/bin/\n$ wget https://raw.githubusercontent.com/GochoMugo/crun/master/crun.sh\n$ mv crun.sh crun\n```\n\n\n## contributing:\n\n```bash\n# Run tests.\nmake test\n\n# Clean up after tests.\nmake clean\n```\n\n\n## references:\n\n* Inspired by [gorun](https://github.com/erning/gorun).\n\n\n## license:\n\n**The MIT License (MIT)**\n\nCopyright (c) 2015-2016 GochoMugo \u003cmugo@forfuture.co.ke\u003e\n\n[dl]:https://raw.githubusercontent.com/GochoMugo/crun/master/crun.sh\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgochomugo%2Fcrun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgochomugo%2Fcrun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgochomugo%2Fcrun/lists"}