]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Makefile: possibility to add the rust library as a cdynlib/header
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Wed, 9 Aug 2023 17:14:45 +0000 (22:44 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Wed, 9 Aug 2023 17:14:45 +0000 (22:44 +0530)
.gitignore
Makefile
rust/Cargo.toml [new file with mode: 0644]
rust/src/lib.rs [new file with mode: 0644]

index 3166f93a24509864695b2ca8c4f6b46b9c6b7cb1..b5e7b3396979f182c270da9fefa3412786ee75fe 100644 (file)
@@ -1,4 +1,4 @@
 *.o
 pihpsdr
 .vscode
-rust/*
+rust/target/*
index f7c1163debbc43e5d0b8391d1d643a7f384c2328..522c11eac3b688167ead72d4afc1c9f5366cd5bc 100644 (file)
--- 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 (file)
index 0000000..48363f2
--- /dev/null
@@ -0,0 +1,12 @@
+[package]
+name = "hpsdr"
+version = "0.1.0"
+edition = "2021"
+authors = ["Ramakrishnan Muthukrishnan <ram@rkrishnan.org>"]
+
+[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 (file)
index 0000000..5d7f64a
--- /dev/null
@@ -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);
+    }
+}