├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Makefile ├── README.md └── makerust.mk /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: main 5 | 6 | env: 7 | CARGO_INCREMENTAL: 0 8 | CARGO_NET_RETRY: 10 9 | CI: 1 10 | RUST_BACKTRACE: short 11 | RUSTFLAGS: -D warnings 12 | RUSTUP_MAX_RETRIES: 10 13 | 14 | jobs: 15 | test: 16 | name: Test 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v3 20 | with: 21 | fetch-depth: 0 22 | - uses: dtolnay/rust-toolchain@stable 23 | - name: Install Nix 24 | uses: DeterminateSystems/nix-installer-action@main 25 | - name: Install GNU make 26 | run: nix profile install 'nixpkgs#gnumake' 27 | - run: make hello-world 28 | - run: make info 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .makerust 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include makerust.mk 2 | 3 | hello-world: 4 | @fn main() { 5 | println!("hello makerust!") 6 | } 7 | 8 | info: dep.xshell dep.anyhow 9 | @ 10 | use anyhow::Result; 11 | use xshell::{cmd, Shell}; 12 | 13 | fn main() -> Result<()> { 14 | let sh = Shell::new()?; 15 | let branch = "main"; 16 | let commit_hash = cmd!(sh, "git rev-parse {branch}").read()?; 17 | println!("makerust running on commit {commit_hash}"); 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # makerust 2 | 3 | ### Rust, but in a Makefile. 4 | 5 | Have you ever thought "I want to write Rust, but in a Makefile"? 6 | No? 7 | Well, I have. 8 | 9 | So I present to you: `makerust`. 10 | 11 | ```make 12 | hello-world: 13 | @fn main() { 14 | println!("hello makerust!") 15 | } 16 | ``` 17 | 18 | ```console 19 | $ make hello-world 20 | hello makerust! 21 | ``` 22 | 23 | Need some dependencies? 24 | `makerust` handles that. 25 | 26 | ```make 27 | info: dep.xshell dep.anyhow 28 | @ 29 | use anyhow::Result; 30 | use xshell::{cmd, Shell}; 31 | 32 | fn main() -> Result<()> { 33 | let sh = Shell::new()?; 34 | let branch = "main"; 35 | let commit_hash = cmd!(sh, "git rev-parse {branch}").read()?; 36 | println!("makerust running on commit {commit_hash}"); 37 | Ok(()) 38 | } 39 | ``` 40 | 41 | ```console 42 | $ make info 43 | makerust running on commit 5a9c640331fa11cfff0f3147732b49e8b247f687 44 | ``` 45 | 46 | 47 | ## How? 48 | 49 | ```make 50 | include makerust.mk 51 | ``` 52 | 53 | and then get going. 54 | 55 | ## Why? 56 | 57 | make is good. Rust is good. In combination it can only get better. 58 | 59 | ## But really ... why? 60 | 61 | We don't ask this question around here. 62 | 63 | ## Should I really? 64 | 65 | Check with your team first, but I can't see a reason why not. 66 | 67 | ## This is a joke, right? 68 | 69 | I don't make jokes on the internet. 70 | 71 | --- 72 | 73 | ``` 74 | Any copyright is dedicated to the Public Domain. 75 | http://creativecommons.org/publicdomain/zero/1.0/ 76 | ``` 77 | 78 | ``` 79 | THE SOFTWARE IS PROVIDED "AS IS", BUT ALSO I TAKE FULL RESPONSIBILITY FOR 80 | THIS UNNUTTERABLE HORROR AND YOU SHALL RECITE MY NAME FOR FOREVER ALONGSIDE IT. 81 | ``` 82 | -------------------------------------------------------------------------------- /makerust.mk: -------------------------------------------------------------------------------- 1 | .SHELLFLAGS = -c ' \ 2 | mkdir -p .makerust && \ 3 | echo "$$1" > .makerust/tmp.rs && \ 4 | if [ "$$(head -1 .makerust/tmp.rs)" = "dep" ]; then \ 5 | bash -c "`tail -n +2 .makerust/tmp.rs`" >> .makerust/dep; \ 6 | else \ 7 | printf "[package]\nname=\"makerust\"\nversion=\"0.1.0\"\nedition=\"2021\"\n" > .makerust/Cargo.toml && \ 8 | printf "[[bin]]\npath=\"tmp.rs\"\nname=\"bin\"\n" >> .makerust/Cargo.toml && \ 9 | printf "[dependencies]\n" >> .makerust/Cargo.toml && \ 10 | if [ -f ".makerust/dep" ]; then \ 11 | for dep in $$(sort .makerust/dep | uniq); do \ 12 | printf "$${dep}=\"*\"\n" >> .makerust/Cargo.toml; \ 13 | done; \ 14 | fi; \ 15 | cargo run -q --manifest-path .makerust/Cargo.toml; \ 16 | rm -f .makerust/dep; \ 17 | fi \ 18 | ' -- 19 | 20 | dep.%: 21 | @dep 22 | echo "$(subst dep.,,$@)" 23 | 24 | .ONESHELL: 25 | 26 | --------------------------------------------------------------------------------