From c05f984698de7069f2107982e0a1e4fceedddd12 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Sun, 18 Feb 2024 12:36:07 +0100 Subject: [PATCH] Use cargo as a build system instead of makefiles --- .gitignore | 5 +++++ Cargo.lock | 7 +++++++ Cargo.toml | 13 +++++++++++++ Makefile | 10 ---------- README.md | 6 ++++++ build.rs | 8 ++++++++ bounce.rs => src/bounce.rs | 0 raylib.rs => src/raylib.rs | 0 rect.rs => src/rect.rs | 0 9 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 Makefile create mode 100644 build.rs rename bounce.rs => src/bounce.rs (100%) rename raylib.rs => src/raylib.rs (100%) rename rect.rs => src/rect.rs (100%) diff --git a/.gitignore b/.gitignore index e660fd9..de9d97c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ bin/ + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..285d523 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "test-raylib-rust" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b96f96d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "test-raylib-rust" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +[[bin]] +name = "rect" +path = "src/rect.rs" + +[[bin]] +name = "bounce" +path = "src/bounce.rs" diff --git a/Makefile b/Makefile deleted file mode 100644 index a847980..0000000 --- a/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -.PHONY: all - -all: rect bounce - -rect: rect.rs - rustc -L./raylib/ -lraylib $< -o bin/$@ - -bounce: bounce.rs - rustc -L./raylib/ -lraylib $< -o bin/$@ - diff --git a/README.md b/README.md index 1782f2c..78686f4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Rust and raylib playground A sample project to play with rust, raylib, and rust/c interoperability + +## How to run + +```shell +$ cargo run --bin rect +``` diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ce741d9 --- /dev/null +++ b/build.rs @@ -0,0 +1,8 @@ +fn main() { + // https://doc.rust-lang.org/cargo/reference/build-scripts.html + // cargo-equivalent to running rustc -L./raylib/ -lraylib test.rs -o bin/test + // to link against the libraylib.a static library + println!("cargo:rustc-link-search=./raylib"); + println!("cargo:rustc-link-lib=static=raylib"); +} + diff --git a/bounce.rs b/src/bounce.rs similarity index 100% rename from bounce.rs rename to src/bounce.rs diff --git a/raylib.rs b/src/raylib.rs similarity index 100% rename from raylib.rs rename to src/raylib.rs diff --git a/rect.rs b/src/rect.rs similarity index 100% rename from rect.rs rename to src/rect.rs