Hello world rust

This commit is contained in:
Greg Shuflin 2021-02-27 21:01:44 -08:00
parent 9e65be7ab7
commit d55f8fd5ed
5 changed files with 42 additions and 2 deletions

6
.gitignore vendored
View File

@ -2,3 +2,9 @@
*.hd
dmrconfig
dmrconfig.exe
# Added by cargo
/target
Cargo.lock

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "dmrconfig"
version = "0.1.0"
authors = ["Greg Shuflin <greg.shuflin@protonmail.com>"]
edition = "2018"
[lib]
crate-type = ["staticlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -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

3
main.c
View File

@ -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;

13
src/lib.rs Normal file
View File

@ -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);
}
}