Skip to content

Commit

Permalink
Brayniac/ccommon update (#292)
Browse files Browse the repository at this point in the history
* Squashed 'deps/ccommon/' changes from f5efe29..45b7bac

45b7bac add new libraries to contain config structs (#245)
0db032a tuning cmake / ci further (#243)
49dcaff improve cargo build script (#244)
5e64de2 WIP: add fluxcapacitor support for linux build (#242)
55769cc restore cmake for rust libraries (#241)
6b1d8d5 Improve the Rust build story (#240)
5955d6b move nodelay setting to the server socket, and accepted connections will inherit that (#238)
aafd20f formatting (#237)
3b5c069 Update ccommon_rs to use bytes v5.0 (#235)
df74087 Address clippy lints in rust code (#234)
7c5bbd1 Make metrics and options Send + Sync (#233)
c2e617e Ensure that manually implemented C options use the correct name (#232)
6e76741 Add some docs
b5b4c5a Change check_pipe to use nanosleep instead of usleep (#231)
eb0a389 Use name of field instead of description for C metrics (#230)
16ddc76 Fix broken buf impls (#229)
eefcdcb Avoid redundant rebuilds of rust packages in CI (#228)
33f62a8 Update bindgen to also generate bindings recursively (#227)
27ffc7c Implement bytes::Buf and Bytes::ButMut on Buf and OwnedBuf (#226)
f873930 Various small bugfixes and usability improvements for rust code (#225)
37a1ecd Port option parsing module to Rust (#224)
38f7556 Fix failed test detection (#215)
0ab1604 Conditionally use std::any::type_name if it's supported (#223)
98176d3 Backport changes from #265 (#222)
ba54096 Remove test for removed rust logging functionality (#221)
519118d Rewrite cmake cargo build wrapper (#220)
5d23b3a Fix some small typos found in #263 (#219)
475dda7 Clean up logging shim (#218)
1d28dd2 Expand rust bindings to add options, metrics, and ccbox (#217)
88b5400 Upstream changes from #261 (#216)
4e99e63 fix a bug and change how check is found (#214)
54067ef slightly simplify accept error-handling logic (#210)
e9fe980 Fix synchronize ccommon with pelikan deps/ccommon (#212)
7eb6424 Cleanup libcheck related code (#211)
683bc1a cc_bstring simplify and fix (#207)
8737d99 continue on server socket on non-blocking errors (#209)
2a62281 add atoi64 to bstring (#206)
f71c657 cc_option simplify _allowed_in_name (#205)
24e3131 Add ITT instrumentation option (#204)
236c98d Fix docs (#200)
e58f6a8 cc_array and cc_ring_array NULL fixes (#201)
1c8df42 Add basic support of build type (#199)
7107988 Fix now_ns() (#198)
da240e5 cc: extend cc_util module (#196)
4846b15 Fix TAILQ_REINIT (#195)
4f5dbb0 Update Cmake version to 2.8 (#197)
2e6f78a cc_mm use OS_DARWIN macro to detect OS (#194)
57acaf6 cc: extend queue module (#193)
a64ada2 cc: extend duration module (#192)
b117632 reverting CMake file changes (#191)
dea5bee backport changes made to ccommon in pelikan (#190)
a4c0334 add linebreak to stats_log() (#188)
05eb03e fix inconsistent naming and bump version (#187)
4acc53a Stats to file (#186)
2168fec minimize osx build config (#185)
42b24de Simplify rust options, specify fewer output targets (#183)
c9fa905 update CMakeRust used to latest version, tweaks to make build work (#184)
2ef0163 Reorder dependency includes in cmake, don't parallel build (#182)
a6a54d9 remove endian-specific logic from str*cmp (#177)
4c0668b epoll_create* ignores size hint in newer kernels, switch to new API (#179)
c9c5ee5 improve cc_bstring string literal and cstring names (#176)
0184d73 Add unit tests for buffer, fix buf/dbuf bugs and refactor (#174)
d7dab43 create a .cargo/config so intellij uses the same target dir as cmake (#173)
e710712 use accept4 for tcp_accept when available (#171)
21ba10e Remove cargo lock for shared lib, closes #169 (#172)
24660f1 update style guide (#170)
17baf1e Per thread logging (#168)

git-subtree-dir: deps/ccommon
git-subtree-split: 45b7bac29f7bddfbb7441d93f11f1d81c0dcb4e8

* update manifest to include new ccommon crates

* Squashed 'deps/ccommon/' changes from 45b7bac..0094e2a

0094e2a add convenience array api (#239)
6024ef7 add pipe config to rust ccommon-channel (#247)
eaf7f07 remove ccommon-time (#248)

git-subtree-dir: deps/ccommon
git-subtree-split: 0094e2a99e4d535f8dec590e8474e6e4686bda07

* remove dep ccommon-time

Co-authored-by: Brian Martin <[email protected]>
  • Loading branch information
Yao Yue and brayniac authored Nov 9, 2020
1 parent 1f603ec commit 3e7d094
Show file tree
Hide file tree
Showing 26 changed files with 508 additions and 15 deletions.
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

[workspace]
members = [
"deps/ccommon/rust/ccommon-sys",
"deps/ccommon/rust/ccommon-rs",
"deps/ccommon/rust/ccommon-array",
"deps/ccommon/rust/ccommon-backend",
"deps/ccommon/rust/ccommon-buffer",
"deps/ccommon/rust/ccommon-channel",
"deps/ccommon/rust/ccommon-derive",
"deps/ccommon/rust/ccommon-log",
"deps/ccommon/rust/ccommon-rs",
"deps/ccommon/rust/ccommon-stats",
"deps/ccommon/rust/ccommon-stream",
"deps/ccommon/rust/ccommon-sys",
"src/rust-util/httpencode",
"src/rust-util/pelikan",
"src/rust-util/pelikan-sys",
Expand Down
2 changes: 0 additions & 2 deletions deps/ccommon/ci/install-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ CHECK_LOG="build-check.log"

echo "building and installing check" >&2

echo "building and installing check" >&2

(
cd "$TEMP" &&
wget "https://github.com/libcheck/check/releases/download/${CHECK_VERSION}/${CHECK_TARBALL}" &&
Expand Down
24 changes: 15 additions & 9 deletions deps/ccommon/include/cc_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,43 @@ typedef int (*array_compare_fn)(const void *, const void *);
typedef rstatus_i (*array_each_fn)(void *, void *);

struct array {
uint32_t nalloc; /* # allocated element */
size_t size; /* element size */
uint32_t nalloc; /* # allocated element */
uint32_t nelem; /* # element */
uint8_t *data; /* elements */
};


static inline uint32_t
array_nalloc(const struct array *arr)
{
return arr->nalloc;
}

static inline size_t
array_size(const struct array *arr)
{
return arr->size;
}

static inline uint32_t
array_nalloc(const struct array *arr)
{
return arr->nalloc;
}

static inline uint32_t
array_nelem(const struct array *arr)
{
return arr->nelem;
}

static inline size_t
array_nfree(const struct array *arr)
{
return arr->nalloc - arr->nelem;
}

/* resets all fields in array to zero w/o freeing up any memory */
static inline void
array_reset(struct array *arr)
{
arr->nalloc = 0;
arr->size = 0;
arr->nalloc = 0;
arr->nelem = 0;
arr->data = NULL;
}
Expand All @@ -82,8 +88,8 @@ array_reset(struct array *arr)
static inline void
array_data_assign(struct array *arr, uint32_t nalloc, size_t size, void *data)
{
arr->nalloc = nalloc;
arr->size = size;
arr->nalloc = nalloc;
arr->nelem = 0;
arr->data = data;
}
Expand Down
10 changes: 8 additions & 2 deletions deps/ccommon/rust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ execute_process(
ERROR_VARIABLE CARGO_CONFIG_OUT)

if(HAVE_RUST)
add_subdirectory(ccommon-backend)
add_subdirectory(ccommon-derive)
add_subdirectory(ccommon-array)
add_subdirectory(ccommon-backend)
add_subdirectory(ccommon-buffer)
add_subdirectory(ccommon-channel)
add_subdirectory(ccommon-derive)
add_subdirectory(ccommon-log)
add_subdirectory(ccommon-rs)
add_subdirectory(ccommon-stats)
add_subdirectory(ccommon-stream)
add_subdirectory(ccommon-sys)

endif()
2 changes: 2 additions & 0 deletions deps/ccommon/rust/ccommon-array/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

cargo_build(NAME ccommon-array)
13 changes: 13 additions & 0 deletions deps/ccommon/rust/ccommon-array/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "ccommon-array"
version = "0.1.0"
authors = ["Brian Martin <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.110", features = ["derive"], optional = true }

[features]
default = [ "serde/derive" ]
38 changes: 38 additions & 0 deletions deps/ccommon/rust/ccommon-array/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const NELEM_DELTA: usize = 16;

// helper functions
fn nelem_delta() -> usize {
NELEM_DELTA
}

// definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ArrayConfig {
#[cfg_attr(feature = "serde", serde(default = "nelem_delta"))]
nelem_delta: usize,
}

// implementation
impl ArrayConfig {
pub fn nelem_delta(&self) -> usize {
self.nelem_delta
}
}

// trait implementations
impl Default for ArrayConfig {
fn default() -> Self {
Self {
nelem_delta: nelem_delta(),
}
}
}
2 changes: 2 additions & 0 deletions deps/ccommon/rust/ccommon-buffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

cargo_build(NAME ccommon-buffer)
14 changes: 14 additions & 0 deletions deps/ccommon/rust/ccommon-buffer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "ccommon-buffer"
version = "0.1.0"
authors = ["Brian Martin <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.110", features = ["derive"], optional = true }

[features]
default = [ "serde/derive" ]

50 changes: 50 additions & 0 deletions deps/ccommon/rust/ccommon-buffer/src/buf/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const BUF_DEFAULT_SIZE: usize = 16 * 1024;
const BUF_POOLSIZE: usize = 0;

// helper functions
fn size() -> usize {
BUF_DEFAULT_SIZE
}

fn poolsize() -> usize {
BUF_POOLSIZE
}

// struct definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BufConfig {
#[cfg_attr(feature = "serde", serde(default = "size"))]
size: usize,
#[cfg_attr(feature = "serde", serde(default = "poolsize"))]
poolsize: usize,
}

// implementation
impl BufConfig {
pub fn size(&self) -> usize {
self.size
}

pub fn poolsize(&self) -> usize {
self.poolsize
}
}

// trait implementations
impl Default for BufConfig {
fn default() -> Self {
Self {
size: size(),
poolsize: poolsize(),
}
}
}
38 changes: 38 additions & 0 deletions deps/ccommon/rust/ccommon-buffer/src/dbuf/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const DBUF_DEFAULT_MAX: usize = 8;

// helper functions
fn max_power() -> usize {
DBUF_DEFAULT_MAX
}

// struct definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DbufConfig {
#[cfg_attr(feature = "serde", serde(default = "max_power"))]
max_power: usize,
}

// implementation
impl DbufConfig {
pub fn max_power(&self) -> usize {
self.max_power
}
}

// trait implementations
impl Default for DbufConfig {
fn default() -> Self {
Self {
max_power: max_power(),
}
}
}
9 changes: 9 additions & 0 deletions deps/ccommon/rust/ccommon-buffer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

mod buf;
mod dbuf;

pub use buf::*;
pub use dbuf::*;
2 changes: 2 additions & 0 deletions deps/ccommon/rust/ccommon-channel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

cargo_build(NAME ccommon-channel)
13 changes: 13 additions & 0 deletions deps/ccommon/rust/ccommon-channel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "ccommon-channel"
version = "0.1.0"
authors = ["Brian Martin <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.110", features = ["derive"], optional = true }

[features]
default = [ "serde/derive" ]
9 changes: 9 additions & 0 deletions deps/ccommon/rust/ccommon-channel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

mod pipe;
mod tcp;

pub use pipe::*;
pub use tcp::*;
38 changes: 38 additions & 0 deletions deps/ccommon/rust/ccommon-channel/src/pipe/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const PIPE_POOLSIZE: usize = 0;

// helper functions
fn poolsize() -> usize {
PIPE_POOLSIZE
}

// definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PipeConfig {
#[cfg_attr(feature = "serde", serde(default = "poolsize"))]
poolsize: usize,
}

// implementation
impl PipeConfig {
pub fn poolsize(&self) -> usize {
self.poolsize
}
}

// trait implementations
impl Default for PipeConfig {
fn default() -> Self {
Self {
poolsize: poolsize(),
}
}
}
50 changes: 50 additions & 0 deletions deps/ccommon/rust/ccommon-channel/src/tcp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const TCP_BACKLOG: usize = 128;
const TCP_POOLSIZE: usize = 0;

// helper functions
fn backlog() -> usize {
TCP_BACKLOG
}

fn poolsize() -> usize {
TCP_POOLSIZE
}

// definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TcpConfig {
#[cfg_attr(feature = "serde", serde(default = "backlog"))]
backlog: usize,
#[cfg_attr(feature = "serde", serde(default = "poolsize"))]
poolsize: usize,
}

// implementation
impl TcpConfig {
pub fn backlog(&self) -> usize {
self.backlog
}

pub fn poolsize(&self) -> usize {
self.poolsize
}
}

// trait implementations
impl Default for TcpConfig {
fn default() -> Self {
Self {
backlog: backlog(),
poolsize: poolsize(),
}
}
}
Loading

0 comments on commit 3e7d094

Please sign in to comment.