Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 13dc94d

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

File tree

130 files changed

+8070
-2203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+8070
-2203
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ cscope.*
4444
lcov
4545

4646
CMAKE_BINARY_DIR
47+
48+
# Generated Rust Bindings
49+
bindings.rs
50+
51+
# Cargo lock file
52+
Cargo.lock
53+
54+
# Cargo build path
55+
target

.travis.yml

+15-95
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
sudo: false
22
language: c
3+
dist: xenial
34

45
# using anchor to import sources into linux builds
56
addons:
67
apt: &apt
78
sources:
89
- ubuntu-toolchain-r-test
9-
- llvm-toolchain-precise-3.6
10-
- llvm-toolchain-precise-3.7
11-
- llvm-toolchain-precise
1210

1311
# important for allowed-to-fail matching
1412
# see https://docs.travis-ci.com/user/customizing-the-build#Rows-that-are-Allowed-to-Fail
@@ -18,115 +16,37 @@ env:
1816
# travis currently does not support directly setting gcc/clang with versions
1917
# (e.g. gcc-4.8) as value for the compiler key. So we will have to manually
2018
# request these packages and use environment varibles to create the matrix.
21-
#
22-
# In the case of osx, use brew to install the paritcular versions, instead of
23-
# specifying with packages.
2419
matrix:
2520
include:
26-
# gcc 4.8 on linux
27-
- env:
28-
- C_COMPILER=gcc-4.8
21+
- name: "gcc-5 on Linux"
22+
compiler: gcc
2923
addons:
3024
apt:
3125
<<: *apt
3226
packages:
33-
- gcc-4.8
3427
- libsubunit-dev
3528

29+
- os: osx
30+
osx_image: xcode10.1
31+
compiler: clang
3632

37-
# gcc 4.9 on linux
38-
- env:
39-
- C_COMPILER=gcc-4.9
40-
addons:
41-
apt:
42-
<<: *apt
43-
packages:
44-
- gcc-4.9
45-
- libsubunit-dev
46-
47-
# gcc 5 on linux
48-
- env:
49-
- C_COMPILER=gcc-5
50-
addons:
51-
apt:
52-
<<: *apt
53-
packages:
54-
- gcc-5
55-
- libsubunit-dev
56-
57-
# gcc 5 on linux
58-
- env:
59-
- C_COMPILER=gcc-5
60-
- RUST_ENABLED=1
61-
addons:
62-
apt:
63-
<<: *apt
64-
packages:
65-
- gcc-5
66-
- libsubunit-dev
67-
68-
# clang 3.6 on linux
69-
- env:
70-
- C_COMPILER=clang-3.6
71-
addons:
72-
apt:
73-
<<: *apt
74-
packages:
75-
- clang-3.6
76-
- libsubunit-dev
77-
78-
# clang 3.7 on linux
79-
- env:
80-
- C_COMPILER=clang-3.7
33+
- name: "cargo build"
34+
language: rust
8135
addons:
8236
apt:
8337
<<: *apt
8438
packages:
85-
- clang-3.7
8639
- libsubunit-dev
87-
88-
## gcc 4.8 on osx
89-
#- os: osx
90-
# env: FORMULA=gcc48 COMPILER=gcc C_COMPILER=gcc-4.8
91-
#
92-
## gcc 4.9 on osx
93-
#- os: osx
94-
# env: FORMULA=gcc49 COMPILER=gcc C_COMPILER=gcc-4.9
95-
#
96-
## gcc 5 on osx
97-
#- os: osx
98-
# env: FORMULA=gcc5 COMPILER=gcc C_COMPILER=gcc-5
99-
100-
# OSX 10.13
101-
# Apple LLVM version 9.1.0 (clang-902.0.39.2)
102-
# Target: x86_64-apple-darwin17.6.0
103-
- os: osx
104-
osx_image: xcode9.4
105-
env:
106-
- C_COMPILER=clang
107-
- ALLOWED_TO_FAIL=1
108-
109-
# OSX 10.12
110-
# Apple LLVM version 9.0.0 (clang-900.0.39.2)
111-
# Target: x86_64-apple-darwin16.7.0
112-
- os: osx
113-
osx_image: xcode9.2
114-
env:
115-
- C_COMPILER=clang
116-
- ALLOWED_TO_FAIL=1
40+
script:
41+
- cargo build
42+
- cargo test
43+
- cargo build --release
44+
- cargo test --release
11745

11846
allow_failures:
11947
- os: osx
120-
osx_image: xcode9.4
121-
env:
122-
- C_COMPILER=clang
123-
- ALLOWED_TO_FAIL=1
124-
125-
- os: osx
126-
osx_image: xcode9.2
127-
env:
128-
- C_COMPILER=clang
129-
- ALLOWED_TO_FAIL=1
48+
osx_image: xcode10.1
49+
compiler: clang
13050

13151
before_install:
13252
- ./ci/before-install.sh

CMakeLists.txt

+61-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
cmake_minimum_required(VERSION 2.6)
1+
cmake_minimum_required(VERSION 2.8)
22
project(ccommon C)
33

4+
# Uncomment the following to output dependency graph debugging messages
5+
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)
6+
47
enable_testing()
58

69
###################
@@ -36,8 +39,8 @@ endif()
3639
# config.h.in has to include entries set/tested here for them to have effect
3740

3841
# version info
39-
set(${PROJECT_NAME}_VERSION_MAJOR 1)
40-
set(${PROJECT_NAME}_VERSION_MINOR 2)
42+
set(${PROJECT_NAME}_VERSION_MAJOR 2)
43+
set(${PROJECT_NAME}_VERSION_MINOR 1)
4144
set(${PROJECT_NAME}_VERSION_PATCH 0)
4245
set(${PROJECT_NAME}_VERSION
4346
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}
@@ -54,6 +57,7 @@ option(HAVE_STATS "stats enabled by default" ON)
5457
option(HAVE_DEBUG_MM "debugging oriented memory management disabled by default" OFF)
5558
option(COVERAGE "code coverage" OFF)
5659
option(HAVE_RUST "rust bindings not built by default" OFF)
60+
option(HAVE_ITT_INSTRUMENTATION "instrument code with ITT API" OFF)
5761

5862
if(HAVE_RUST)
5963
option(RUST_VERBOSE_BUILD "pass -vv to cargo compilation" OFF)
@@ -78,7 +82,6 @@ if(BUILD_AND_INSTALL_CHECK)
7882

7983
set(CHECK_ROOT_DIR "${LIBCHECK_PREFIX}")
8084
set(CMAKE_REQUIRED_INCLUDES "${CHECK_ROOT_DIR}/include") # these make check link correctly in ccommon and pelikan
81-
set(CMAKE_REQUIRED_LIBRARIES "${CHECK_ROOT_DIR}/lib")
8285
endif()
8386

8487
include(CheckIncludeFiles)
@@ -96,9 +99,7 @@ check_symbol_exists(sys_signame signal.h HAVE_SIGNAME)
9699

97100
include(CheckFunctionExists)
98101
check_function_exists(backtrace HAVE_BACKTRACE)
99-
100-
include(TestBigEndian)
101-
test_big_endian(HAVE_BIG_ENDIAN)
102+
check_function_exists(accept4 HAVE_ACCEPT4)
102103

103104
# how to use config.h.in to generate config.h
104105
# this has to be set _after_ the above checks
@@ -114,12 +115,23 @@ configure_file(
114115
# set compiler flags
115116
# string concat is easier in 3.0, but older versions don't have the concat subcommand
116117
# so we are using list as input until we move to new version
117-
# TODO add build types
118118
add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64)
119+
# Set a default build type (Release) if none was specified
120+
121+
if(NOT CMAKE_BUILD_TYPE)
122+
set(CMAKE_BUILD_TYPE Release)
123+
endif()
124+
125+
if(CMAKE_BUILD_TYPE MATCHES Debug)
126+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
127+
else()
128+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
129+
endif()
130+
119131
set(CMAKE_MACOSX_RPATH 1)
120132
set(CFLAGS_LIST
121133
"-std=c11 "
122-
"-ggdb3 -O2 "
134+
"-ggdb3 "
123135
"-Wall "
124136
"-Wmissing-prototypes -Wmissing-declarations -Wredundant-decls "
125137
"-Wunused-function -Wunused-value -Wunused-variable "
@@ -132,13 +144,15 @@ if(CMAKE_COMPILER_IS_GNUCC)
132144
endif()
133145

134146
if (COVERAGE)
135-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
147+
if(NOT ${CMAKE_BUILD_TYPE} MATCHES Debug)
148+
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
149+
endif()
150+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
136151
endif(COVERAGE)
137152

138153
# test dependencies
139154
include(FindPackageHandleStandardArgs)
140155
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
141-
142156
find_package(Check)
143157
if(NOT CHECK_FOUND)
144158
message(WARNING "Check is required to build and run tests")
@@ -150,6 +164,17 @@ if(CHECK_FOUND)
150164
endif(NOT CHECK_WORKING)
151165
endif(CHECK_FOUND)
152166

167+
if (HAVE_ITT_INSTRUMENTATION)
168+
if(PKG_CONFIG_FOUND)
169+
pkg_check_modules(ITTNOTIFY REQUIRED ittnotify>=1.0)
170+
else()
171+
find_package(ITTNOTIFY REQUIRED 1.0)
172+
endif()
173+
include_directories(${ITTNOTIFY_INCLUDE_DIRS})
174+
link_directories(${ITTNOTIFY_LIBRARY_DIRS})
175+
link_libraries(${ITTNOTIFY_LIBRARIES})
176+
endif(HAVE_ITT_INSTRUMENTATION)
177+
153178
find_package(Threads)
154179

155180

@@ -159,28 +184,41 @@ include_directories(
159184
"${PROJECT_BINARY_DIR}"
160185
"include")
161186

162-
if(HAVE_RUST)
163-
enable_language(Rust)
164-
include(CMakeCargo)
165-
add_subdirectory(rust)
166-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_RUST=1")
167-
endif()
168-
169-
170187
###################
171188
# things to build #
172189
###################
173190

174191
add_subdirectory(src)
175-
if(CHECK_WORKING)
176-
include_directories(${include_directories} "${CHECK_INCLUDES}")
192+
193+
if(CHECK_FOUND)
194+
include_directories(${include_directories} ${CHECK_INCLUDES})
177195
add_subdirectory(test)
178-
endif(CHECK_WORKING)
196+
endif(CHECK_FOUND)
197+
198+
if(HAVE_RUST)
199+
include(CMakeCargo)
200+
add_subdirectory(rust)
201+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_RUST=1")
202+
203+
if (${CMAKE_VERSION} VERSION_LESS "3.13.0")
204+
# CMakeCargo requires the use of some newer features of cmake
205+
# for changes to dependant libraries to cause a rebuild. This
206+
# will never break the build, it is just annoying for development.
207+
# Leave a warning here, but don't break the build for older cmake
208+
# versions.
209+
message(
210+
WARNING
211+
"Rust targets don't properly pick up changes to dependencies in cmake version <= 3.13"
212+
)
213+
endif()
214+
endif()
179215

180216
###################
181217
# print a summary #
182218
###################
183219

220+
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
221+
184222
message(STATUS "PLATFORM: " ${OS_PLATFORM})
185223

186224
message(STATUS "CPPFLAGS: " ${CMAKE_CPP_FLAGS})
@@ -189,6 +227,5 @@ message(STATUS "CFLAGS: " ${CMAKE_C_FLAGS})
189227
message(STATUS "HAVE_SIGNAME: " ${HAVE_SIGNAME})
190228

191229
message(STATUS "HAVE_BACKTRACE: " ${HAVE_BACKTRACE})
192-
message(STATUS "HAVE_BIG_ENDIAN: " ${HAVE_BIG_ENDIAN})
193230

194-
message(STATUS "CHECK_WORKING: " ${CHECK_WORKING})
231+
message(STATUS "CHECK_FOUND: " ${CHECK_FOUND})

Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[workspace]
2+
members = [
3+
"rust/ccommon-backend",
4+
"rust/ccommon-derive",
5+
"rust/ccommon-rs",
6+
"rust/ccommon-sys",
7+
]
8+
9+
[profile.bench]
10+
debug = true
11+
lto = true
12+
codegen-units = 1
13+
14+
[profile.release]
15+
debug = true
16+
lto = true
17+
codegen-units = 1

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2013-2015 Twitter, Inc
1+
Copyright 2013-2018 Twitter, Inc
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

NOTICE

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
* Boston, MA 02111-1307, USA.
2323
*/
2424

25+
We use the CMakeRust project (https://github.com/Devolutions/CMakeRust) under
26+
the Apache 2.0 License.

ci/before-install.sh

-15
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ trap cleanup EXIT
1111

1212
TOPLEVEL="$(git -C "$(cd "$(dirname "$0")" >/dev/null || exit 1; pwd)" rev-parse --show-toplevel)" || die 'failed to find TOPLEVEL'
1313

14-
# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc
15-
16-
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
17-
brew update &>/dev/null
18-
brew install cmake || true # xcode 8.1 is missing cmake
19-
20-
if [[ "$C_COMPILER" =~ ^gcc && -n "${FORMULA:-}" ]]; then
21-
brew unlink gcc || true
22-
brew unlink "$FORMULA" || true
23-
brew install "$FORMULA"
24-
fi
25-
fi
26-
27-
export CC="$C_COMPILER"
28-
2914
if [[ -n "${RUST_ENABLED:-}" ]]; then
3015
curl https://sh.rustup.rs -sSf | sh -s -- -y
3116
fi

0 commit comments

Comments
 (0)