From d55f8fd5ed893389debdbbf11b6f47710e301627 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 27 Feb 2021 21:01:44 -0800 Subject: [PATCH] Hello world rust --- .gitignore | 6 ++++++ Cargo.toml | 12 ++++++++++++ Makefile | 10 ++++++++-- main.c | 3 +++ src/lib.rs | 13 +++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index b61db24..3a6c802 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ *.hd dmrconfig dmrconfig.exe + + +# Added by cargo + +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4562a77 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "dmrconfig" +version = "0.1.0" +authors = ["Greg Shuflin "] +edition = "2018" + +[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 c039939..8c67d43 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ CFLAGS += -DVERSION='"$(VERSION).$(GITCOUNT)"' \ LDFLAGS ?= -g LIBS = $(shell pkg-config --libs --static libusb-1.0) +RUST_RELEASE := target/release/libdmrconfig.a + # # Make sure pkg-config is installed. # @@ -48,8 +50,8 @@ endif all: dmrconfig -dmrconfig: $(OBJS) - $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) +dmrconfig: $(OBJS) $(RUST_RELEASE) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(RUST_RELEASE) -ldl $(LIBS) clean: rm -f *~ *.o core dmrconfig dmrconfig.exe @@ -57,6 +59,10 @@ clean: install: dmrconfig install -c -s dmrconfig /usr/local/bin/dmrconfig +.PHONY: $(RUST_RELEASE) +target/release/libdmrconfig.a: + cargo build --verbose --release + ### d868uv.o: d868uv.c radio.h util.h d868uv-map.h dfu-libusb.o: dfu-libusb.c util.h diff --git a/main.c b/main.c index 37f1895..d45aa1d 100644 --- a/main.c +++ b/main.c @@ -37,6 +37,8 @@ const char *copyright; extern char *optarg; extern int optind; +extern void print_message_from_rust(); + int trace_flag = 0; void usage() @@ -72,6 +74,7 @@ void usage() int main(int argc, char **argv) { + print_message_from_rust(); int read_flag = 0, write_flag = 0, config_flag = 0, csv_flag = 0; int list_flag = 0, verify_flag = 0; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a08a5a4 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +#[no_mangle] +pub extern "C" fn print_message_from_rust() { + println!("Calling from Rust!"); +} + + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}