Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from media-cloud-ai/dev/add_travis_ci
Browse files Browse the repository at this point in the history
Add Travis CI
  • Loading branch information
MarcAntoine-Arnaud committed Dec 11, 2019
2 parents b9097b2 + 5e6eade commit 4bb5733
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 12 deletions.
59 changes: 59 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
language: rust

os: linux

rust:
- 1.36.0
- 1.37.0
- 1.38.0
- 1.39.0
- stable
- beta
- nightly

env:
- WORKER_LIBRARY_FILE=$TRAVIS_BUILD_DIR/libworker.so

jobs:
allow_failures:
- rust: nightly
include:
# Rustfmt
- rust: stable
install:
- rustup component add rustfmt-preview
before_script:
- cargo fmt --version
script:
- cargo fmt -- --check

# Clippy
- rust: stable
install:
- rustup component add clippy-preview
script:
# Fail if clippy output contains "error:" or "warning:"
- cargo clippy 2>&1 | tee ./clippy.out && ! grep -qe "error:\|warning:" ./clippy.out

# Test coverage (with Tarpaulin)
- rust: stable
install:
- RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin --force
script:
- gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o
- cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID

script:
- gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o
- cargo test
cache:
cargo: true
before_cache:
# Travis can't cache files that are not readable by "others"
- chmod -R a+r $HOME/.cargo

addons:
apt:
packages:
- libssl-dev # Required for tarpaulin
- gcc
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# C/C++ binding for Rust AMQP Worker
Based on [rs_amqp_worker](https://github.com/media-cloud-ai/rs_amqp_worker).

[![Build Status](https://travis-ci.org/media-cloud-ai/c_amqp_worker.svg?branch=master)](https://travis-ci.org/media-cloud-ai/c_amqp_worker)
[![Coverage Status](https://coveralls.io/repos/github/media-cloud-ai/c_amqp_worker/badge.svg?branch=master)](https://coveralls.io/github/media-cloud-ai/c_amqp_worker?branch=master)

## Build
To build the rust application
```bash
Expand Down
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ impl MessageEvent for CWorkerEvent {

fn get_version(&self) -> Version {
let version = get_worker_function_string_value(GET_VERSION_FUNCTION);
Version::parse(&version).expect(&format!(
"unable to parse version {} (please use SemVer format)",
version
))
Version::parse(&version).unwrap_or_else(|_| {
panic!(
"unable to parse version {} (please use SemVer format)",
version
)
})
}

fn get_git_version(&self) -> Version {
Expand Down
16 changes: 8 additions & 8 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ type ProcessFunc = unsafe fn(

type CheckLastError = extern "C" fn() -> c_int;

pub static GET_NAME_FUNCTION: &'static str = "get_name";
pub static GET_SHORT_DESCRIPTION_FUNCTION: &'static str = "get_short_description";
pub static GET_DESCRIPTION_FUNCTION: &'static str = "get_description";
pub static GET_VERSION_FUNCTION: &'static str = "get_version";
pub static GET_PARAMETERS_SIZE_FUNCTION: &'static str = "get_parameters_size";
pub static GET_PARAMETERS_FUNCTION: &'static str = "get_parameters";
pub static PROCESS_FUNCTION: &'static str = "process";
pub static GET_NAME_FUNCTION: &str = "get_name";
pub static GET_SHORT_DESCRIPTION_FUNCTION: &str = "get_short_description";
pub static GET_DESCRIPTION_FUNCTION: &str = "get_description";
pub static GET_VERSION_FUNCTION: &str = "get_version";
pub static GET_PARAMETERS_SIZE_FUNCTION: &str = "get_parameters_size";
pub static GET_PARAMETERS_FUNCTION: &str = "get_parameters";
pub static PROCESS_FUNCTION: &str = "process";

extern "C" fn check_error() -> c_int {
let last_error = LAST_ERROR.with(|last_error| last_error.replace(None));
Expand Down Expand Up @@ -144,7 +144,7 @@ unsafe fn get_parameter_from_worker_parameter(worker_parameter: &WorkerParameter
}

fn get_library_file_path() -> String {
std::env::var("WORKER_LIBRARY_FILE").unwrap_or("libworker.so".to_string())
std::env::var("WORKER_LIBRARY_FILE").unwrap_or_else(|_| "libworker.so".to_string())
}

unsafe fn get_library_function<'a, T>(
Expand Down

0 comments on commit 4bb5733

Please sign in to comment.