From 2eea177013a817542a31425c280ca0c9d5c8d276 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Wed, 9 Aug 2023 22:44:45 +0530 Subject: [PATCH] Makefile: possibility to add the rust library as a cdynlib/header --- .gitignore | 2 +- Makefile | 16 ++++++++++++---- rust/Cargo.toml | 12 ++++++++++++ rust/src/lib.rs | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 rust/Cargo.toml create mode 100644 rust/src/lib.rs diff --git a/.gitignore b/.gitignore index 3166f93..b5e7b33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.o pihpsdr .vscode -rust/* +rust/target/* diff --git a/Makefile b/Makefile index f7c1163..522c11e 100644 --- a/Makefile +++ b/Makefile @@ -174,8 +174,11 @@ ifeq ($(UNAME_S), Linux) RT_OPTION=-lrt endif -LIBS=$(RT_OPTION) -lfftw3 -lm -lwdsp -lpthread $(AUDIO_LIBS) $(USBOZY_LIBS) $(GTKLIBS) $(GPIO_LIBS) $(MIDI_LIBS) -INCLUDES=$(GTKINCLUDES) +RUST_LIB=-Lrust/target/debug -lhpsdr +RUST_INCLUDES=-Irust/target/debug + +LIBS=$(RT_OPTION) -lfftw3 -lm -lwdsp -lpthread $(AUDIO_LIBS) $(USBOZY_LIBS) $(GTKLIBS) $(GPIO_LIBS) $(MIDI_LIBS) $(RUST_LIB) +INCLUDES=$(GTKINCLUDES) $(RUST_INCLUDES) COMPILE=$(CC) $(CFLAGS) $(OPTIONS) $(INCLUDES) @@ -419,10 +422,11 @@ toolbar_menu.o $(PROGRAM): $(OBJS) $(AUDIO_OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) \ $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \ - $(MIDI_OBJS) $(SERVER_OBJS) + $(MIDI_OBJS) $(SERVER_OBJS) \ + libhpsdr $(LINK) -o $(PROGRAM) $(OBJS) $(AUDIO_OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) \ $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \ - $(MIDI_OBJS) $(SERVER_OBJS) $(LIBS) + $(MIDI_OBJS) $(SERVER_OBJS) $(LIBS) .PHONY: all all: prebuild $(PROGRAM) $(HEADERS) $(AUDIO_HEADERS) $(USBOZY_HEADERS) \ @@ -506,6 +510,10 @@ newhpsdrsim.o: newhpsdrsim.c hpsdrsim.h hpsdrsim: hpsdrsim.o newhpsdrsim.o $(LINK) -o hpsdrsim hpsdrsim.o newhpsdrsim.o -lasound -lm -lpthread +libhpsdr: + cd rust && \ + cargo build && \ + cd .. debian: cp $(PROGRAM) pkg/pihpsdr/usr/local/bin diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..48363f2 --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "hpsdr" +version = "0.1.0" +edition = "2021" +authors = ["Ramakrishnan Muthukrishnan "] + +[dependencies] +libc = "0.2" + +[lib] +name = "hpsdr" +crate-type = ["staticlib"] diff --git a/rust/src/lib.rs b/rust/src/lib.rs new file mode 100644 index 0000000..5d7f64a --- /dev/null +++ b/rust/src/lib.rs @@ -0,0 +1,17 @@ +use libc::{size_t}; + +#[no_mangle] +pub extern fn add(left: size_t, right: size_t) -> size_t { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} -- 2.45.2