Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Cargo, first steps towards porting to Rust 🦀 #343

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build/
/build
/target
Cargo.lock
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "libfsm-rs"
version = "0.1.0"
authors = ["Kate F <kate@elide.org>"]
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]

20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ INCDIR += include
.include <obj.mk>
.include <dep.mk>
.include <ar.mk>
.include <so.mk>
.include <part.mk>
.include <prog.mk>
.include <mkdir.mk>
Expand All @@ -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

4 changes: 4 additions & 0 deletions src/libfsm/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "internal.h"
#include "capture.h"
#include "endids.h"
#include "libfsm_rs.h"

void
free_contents(struct fsm *fsm)
Expand All @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/libfsm/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions src/libfsm/libfsm.syms
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ fsm_capture_set_path
fsm_capture_rebase_capture_id
fsm_capture_alloc
fsm_capture_dump

# from rust
fsm_noop

6 changes: 6 additions & 0 deletions src/libfsm/libfsm_rs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef LIBFSM_RS_H
#define LIBFSM_RS_H

void fsm_noop(void);

#endif