From ec74203e70b7cc43b6f3e461d73012eaec0eea11 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 23 Jul 2023 03:03:23 -0700 Subject: [PATCH] Start porting to rust --- .gitignore | 5 +++++ Cargo.lock | 7 +++++++ Cargo.toml | 12 ++++++++++++ Makefile | 2 +- src/lib.rs | 6 ++++++ src/nms.c | 3 +++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index 32148fe..70e68f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ bin/* obj/* .vs + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b091cdb --- /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 = "nmsrust" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9c78f87 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "nmsrust" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["staticlib"] + + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/Makefile b/Makefile index 4394cdd..696bc1c 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ CFLAGS ?= -Wextra -Wall -O2 .PHONY: all install uninstall clean nms: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN) - $(CC) $(CFLAGS) -o $(BIN)/$@ $^ + $(CC) $(CFLAGS) -o $(BIN)/$@ $^ target/release/libnmsrust.a sneakers: $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN) $(CC) $(CFLAGS) -o $(BIN)/$@ $^ diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..318ddca --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,6 @@ + + +#[no_mangle] +pub extern "C" fn rust_main() { + println!("Hello from rust"); +} diff --git a/src/nms.c b/src/nms.c index 5941db9..67d868d 100644 --- a/src/nms.c +++ b/src/nms.c @@ -15,8 +15,11 @@ #define VERSION "1.0.1" +extern void rust_main(); + int main(int argc, char *argv[]) { + rust_main(); int r, o; unsigned char *input;