diff --git a/.gitignore b/.gitignore index 567609b12..65d6036f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -build/ +/build +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..48f6a50a1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "libfsm-rs" +version = "0.1.0" +authors = ["Kate F "] +edition = "2018" + +[lib] +crate-type = ["staticlib"] +path = "src/libfsm/lib.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + diff --git a/Makefile b/Makefile index d5c14b3cc..a8c560455 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,6 @@ INCDIR += include .include .include .include -.include .include .include .include @@ -110,3 +109,22 @@ STAGE_BUILD := ${STAGE_BUILD:Nbin/cvtpcre} grep FAIL ${BUILD}/tests/*/res*; [ $$? -ne 0 ] .endif +.if !${CC:T:Memcc*} + +./target/debug/liblibfsm_rs.a: + cargo build + +test:: + cargo test + +./target/debug/liblibfsm_rs.d: ./target/debug/liblibfsm_rs.a +.if exists(./target/debug/liblibfsm_rs.d) +.include "./target/debug/liblibfsm_rs.d" +.endif + +${BUILD}/lib/libfsm.o: ./target/debug/liblibfsm_rs.a +# hijacking LDRFLAGS here because the target only expects .o sources +LDRFLAGS.libfsm += ./target/debug/liblibfsm_rs.a + +.endif + diff --git a/src/libfsm/fsm.c b/src/libfsm/fsm.c index 60f748184..99848c603 100644 --- a/src/libfsm/fsm.c +++ b/src/libfsm/fsm.c @@ -22,6 +22,7 @@ #include "internal.h" #include "capture.h" #include "endids.h" +#include "libfsm_rs.h" void free_contents(struct fsm *fsm) @@ -47,6 +48,9 @@ fsm_new(const struct fsm_options *opt) static const struct fsm_options defaults; struct fsm *new, f; + /* just to prove linking works */ + fsm_noop(); + if (opt == NULL) { opt = &defaults; } diff --git a/src/libfsm/lib.rs b/src/libfsm/lib.rs new file mode 100644 index 000000000..def4ba84e --- /dev/null +++ b/src/libfsm/lib.rs @@ -0,0 +1,12 @@ +// just here to prove linking works +#[no_mangle] +pub extern "C" fn fsm_noop() { +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/libfsm/libfsm.syms b/src/libfsm/libfsm.syms index 947012fd0..667aac301 100644 --- a/src/libfsm/libfsm.syms +++ b/src/libfsm/libfsm.syms @@ -126,3 +126,7 @@ fsm_capture_set_path fsm_capture_rebase_capture_id fsm_capture_alloc fsm_capture_dump + +# from rust +fsm_noop + diff --git a/src/libfsm/libfsm_rs.h b/src/libfsm/libfsm_rs.h new file mode 100644 index 000000000..d81f33857 --- /dev/null +++ b/src/libfsm/libfsm_rs.h @@ -0,0 +1,6 @@ +#ifndef LIBFSM_RS_H +#define LIBFSM_RS_H + +void fsm_noop(void); + +#endif