Wire together some of the rsyslog and bind generated code

This commit is contained in:
R Tyler Croy 2020-03-24 20:29:28 -07:00
parent df799519ac
commit 7f887e44cb
6 changed files with 107 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/target
Cargo.lock
*.sw*
tmp/

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "impstatsd"
version = "0.1.0"
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
edition = "2018"
[dependencies]
statsd = "^0.9.0"
[build-dependencies]
bindgen = "0.53.1"

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
build:
BINDGEN_EXTRA_CLANG_ARGS="-I./contrib/rsyslog/runtime -I./contrib/rsyslog/grammar" cargo build
contrib/rsyslog/configure:
(cd contrib/rsyslog && bash autogen.sh \
--disable-libgcrypt \
--disable-liblogging-stdlog \
--disable-regexp \
--disable-klog \
--disable-generate-man-pages)
rsyslogd: contrib/rsyslog/configure
$(MAKE) -C contrib/rsyslog
.PHONY: build help

32
build.rs Normal file
View File

@ -0,0 +1,32 @@
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
// Tell cargo to tell rustc to link the system bzip2
// shared library.
//println!("cargo:rustc-link-lib=bz2");
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=src/binding.h");
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("src/binding.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}

6
src/binding.h Normal file
View File

@ -0,0 +1,6 @@
/*
* This file is for bindgen to wrap all the rsyslog code we need
*/
#include <rsyslog.h>

34
src/lib.rs Normal file
View File

@ -0,0 +1,34 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
/*
* Pull our wacky rsyslog.h generated bindings
*/
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
fn modGetType(m: &mut eModType_t) -> rsRetVal {
// Set ourselves up as an input module
*m = 0;
return 0; // ok
}
#[cfg(test)]
mod tests {
use super::*;
/**
* Verify that the modGetType function works properly
*/
#[test]
fn test_modGetType() {
/*
* Setting this to some garbage value
*/
let mut m: eModType_t = 2;
assert_eq!(0, modGetType(&mut m));
assert_eq!(0, m);
}
}