From 686fd0208a1e1d4996251ef230f8033836886492 Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Wed, 27 May 2020 10:49:32 -0700 Subject: [PATCH] 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 twitter/pelikan#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 twitter/pelikan#263 (#219) 475dda7 Clean up logging shim (#218) 1d28dd2 Expand rust bindings to add options, metrics, and ccbox (#217) 88b5400 Upstream changes from twitter/pelikan#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 --- .gitignore | 9 + .travis.yml | 127 +--- CMakeLists.txt | 211 ++++--- LICENSE | 2 +- NOTICE | 2 + ci/before-install.sh | 15 - ci/cargo.sh | 54 ++ ci/install-check.sh | 34 +- ci/install-fluxcapacitor.sh | 55 ++ ci/local-run.sh | 55 ++ ci/run.sh | 6 +- cmake/CMakeCargo.cmake | 418 +++++++++++-- cmake/CMakeDetermineRustCompiler.cmake | 25 - cmake/CMakeRustCompiler.cmake.in | 15 - cmake/CMakeRustInformation.cmake | 106 ---- cmake/CMakeTestRustCompiler.cmake | 3 - cmake/CargoLink.cmake | 105 ++++ cmake/CargoTest.cmake | 99 +++ cmake/{FindCheck.cmake => FindCHECK.cmake} | 0 cmake/FindITTNOTIFY.cmake | 65 ++ cmake/FindRust.cmake | 30 +- config.h.in | 4 +- docs/c-styleguide.txt | 427 ------------- docs/coding_style.rst | 583 ++++++++++++++++++ docs/modules/cc_log.rst | 126 +++- docs/modules/cc_metric.rst | 133 +++- docs/modules/cc_option.rst | 95 ++- docs/modules/cc_ring_array.rst | 47 +- docs/overview.rst | 50 +- include/buffer/cc_buf.h | 47 +- include/buffer/cc_dbuf.h | 6 +- include/cc_bstring.h | 70 ++- include/cc_define.h | 15 +- include/cc_event.h | 4 +- include/cc_itt.h | 69 +++ include/cc_log.h | 4 + include/cc_mm.h | 4 + include/cc_queue.h | 18 + include/cc_stats_log.h | 38 ++ include/cc_util.h | 3 + .../{hash/cc_lookup3.h => rust/cc_log_rs.h} | 9 +- include/time/cc_timer.h | 23 +- rust/CMakeLists.txt | 20 +- rust/Cargo.lock | 496 --------------- rust/Cargo.toml | 21 - rust/cc_binding/CMakeLists.txt | 4 - rust/cc_binding/Cargo.toml | 12 - rust/cc_binding/build.rs | 108 ---- rust/cc_binding/src/lib.rs | 8 - rust/cc_binding/wrapper.h | 2 - rust/ccommon-array/CMakeLists.txt | 2 + rust/ccommon-array/Cargo.toml | 13 + rust/ccommon-array/src/lib.rs | 38 ++ rust/ccommon-backend/CMakeLists.txt | 1 + rust/ccommon-backend/Cargo.toml | 17 + rust/ccommon-backend/src/c_export.rs | 146 +++++ rust/ccommon-backend/src/compat.rs | 157 +++++ rust/ccommon-backend/src/lib.rs | 41 ++ rust/ccommon-backend/src/option/default.rs | 99 +++ rust/ccommon-backend/src/option/parse.rs | 519 ++++++++++++++++ rust/ccommon-backend/src/option/print.rs | 120 ++++ rust/ccommon-backend/tests/parse.rs | 190 ++++++ rust/ccommon-buffer/CMakeLists.txt | 2 + rust/ccommon-buffer/Cargo.toml | 14 + rust/ccommon-buffer/src/buf/mod.rs | 50 ++ rust/ccommon-buffer/src/dbuf/mod.rs | 38 ++ rust/ccommon-buffer/src/lib.rs | 9 + rust/ccommon-channel/CMakeLists.txt | 2 + rust/ccommon-channel/Cargo.toml | 13 + rust/ccommon-channel/src/lib.rs | 50 ++ rust/ccommon-derive/CMakeLists.txt | 2 + rust/ccommon-derive/Cargo.toml | 15 + rust/ccommon-derive/src/attrs.rs | 191 ++++++ rust/ccommon-derive/src/lib.rs | 488 +++++++++++++++ rust/ccommon-log/CMakeLists.txt | 2 + rust/ccommon-log/Cargo.toml | 14 + rust/ccommon-log/src/lib.rs | 62 ++ rust/ccommon-rs/CMakeLists.txt | 9 + rust/ccommon-rs/Cargo.toml | 30 + rust/ccommon-rs/build.rs | 23 + .../{ccommon_rs => ccommon-rs}/src/bstring.rs | 79 ++- rust/ccommon-rs/src/buf.rs | 366 +++++++++++ rust/ccommon-rs/src/ccbox.rs | 222 +++++++ rust/ccommon-rs/src/error.rs | 108 ++++ rust/ccommon-rs/src/lib.rs | 32 + rust/ccommon-rs/src/log/debug.rs | 121 ++++ rust/ccommon-rs/src/log/mod.rs | 52 ++ rust/ccommon-rs/src/log/shim.rs | 227 +++++++ rust/ccommon-rs/src/metric/counter.rs | 113 ++++ rust/ccommon-rs/src/metric/fpn.rs | 73 +++ rust/ccommon-rs/src/metric/gauge.rs | 113 ++++ rust/ccommon-rs/src/metric/mod.rs | 364 +++++++++++ rust/ccommon-rs/src/option/boolean.rs | 81 +++ rust/ccommon-rs/src/option/fpn.rs | 81 +++ rust/ccommon-rs/src/option/mod.rs | 357 +++++++++++ rust/ccommon-rs/src/option/string.rs | 109 ++++ rust/ccommon-rs/src/option/uint.rs | 81 +++ rust/ccommon-rs/src/ptrs.rs | 40 ++ rust/ccommon-rs/tests/derive_metrics.rs | 46 ++ rust/ccommon-rs/tests/derive_options.rs | 54 ++ rust/ccommon-rs/tests/log.rs | 140 +++++ rust/ccommon-stats/CMakeLists.txt | 2 + rust/ccommon-stats/Cargo.toml | 14 + rust/ccommon-stats/src/lib.rs | 50 ++ rust/ccommon-stream/CMakeLists.txt | 2 + rust/ccommon-stream/Cargo.toml | 14 + rust/ccommon-stream/src/lib.rs | 38 ++ rust/ccommon-sys/CMakeLists.txt | 5 + rust/ccommon-sys/Cargo.toml | 16 + rust/ccommon-sys/build.rs | 142 +++++ rust/ccommon-sys/src/lib.rs | 61 ++ rust/ccommon-sys/src/metric.rs | 99 +++ rust/ccommon-sys/wrapper.h | 51 ++ rust/ccommon-time/CMakeLists.txt | 2 + rust/ccommon-time/Cargo.toml | 14 + rust/ccommon-time/src/lib.rs | 47 ++ rust/ccommon_rs/CMakeLists.txt | 4 - rust/ccommon_rs/Cargo.toml | 12 - rust/ccommon_rs/src/lib.rs | 3 - src/CMakeLists.txt | 6 +- src/buffer/cc_buf.c | 4 +- src/buffer/cc_dbuf.c | 31 +- src/cc_array.c | 2 +- src/cc_bstring.c | 50 +- src/cc_debug.c | 1 - src/cc_log.c | 25 + src/cc_mm.c | 14 +- src/cc_option.c | 3 +- src/cc_ring_array.c | 4 +- src/channel/cc_tcp.c | 77 ++- src/event/cc_epoll.c | 16 +- src/hash/CMakeLists.txt | 1 - src/hash/cc_lookup3.c | 446 -------------- src/stats/CMakeLists.txt | 1 + src/stats/cc_stats_log.c | 89 +++ src/time/cc_timer_darwin.c | 6 + src/time/cc_timer_linux.c | 42 +- test-coverage.sh | 2 +- test/CMakeLists.txt | 5 +- test/array/CMakeLists.txt | 1 - test/bstring/CMakeLists.txt | 1 - test/bstring/check_bstring.c | 56 ++ test/buffer/CMakeLists.txt | 9 + test/buffer/check_buf.c | 429 +++++++++++++ test/channel/pipe/CMakeLists.txt | 1 - test/channel/pipe/check_pipe.c | 24 +- test/channel/tcp/CMakeLists.txt | 1 - test/event/CMakeLists.txt | 1 - test/log/CMakeLists.txt | 16 +- test/log/check_log.c | 2 +- test/metric/CMakeLists.txt | 1 - test/option/CMakeLists.txt | 1 - test/pool/CMakeLists.txt | 1 - test/rbuf/CMakeLists.txt | 1 - test/rbuf/check_rbuf.c | 1 - test/ring_array/CMakeLists.txt | 1 - test/ring_array/check_ring_array.c | 1 + test/time/timer/CMakeLists.txt | 1 - test/time/wheel/CMakeLists.txt | 1 - test/time/wheel/check_wheel.c | 21 +- 160 files changed, 8806 insertions(+), 2264 deletions(-) create mode 100755 ci/cargo.sh create mode 100755 ci/install-fluxcapacitor.sh create mode 100755 ci/local-run.sh delete mode 100644 cmake/CMakeDetermineRustCompiler.cmake delete mode 100644 cmake/CMakeRustCompiler.cmake.in delete mode 100644 cmake/CMakeRustInformation.cmake delete mode 100644 cmake/CMakeTestRustCompiler.cmake create mode 100644 cmake/CargoLink.cmake create mode 100644 cmake/CargoTest.cmake rename cmake/{FindCheck.cmake => FindCHECK.cmake} (100%) create mode 100644 cmake/FindITTNOTIFY.cmake delete mode 100644 docs/c-styleguide.txt create mode 100644 docs/coding_style.rst create mode 100644 include/cc_itt.h create mode 100644 include/cc_stats_log.h rename include/{hash/cc_lookup3.h => rust/cc_log_rs.h} (80%) delete mode 100644 rust/Cargo.lock delete mode 100644 rust/Cargo.toml delete mode 100644 rust/cc_binding/CMakeLists.txt delete mode 100644 rust/cc_binding/Cargo.toml delete mode 100644 rust/cc_binding/build.rs delete mode 100644 rust/cc_binding/src/lib.rs delete mode 100644 rust/cc_binding/wrapper.h create mode 100644 rust/ccommon-array/CMakeLists.txt create mode 100644 rust/ccommon-array/Cargo.toml create mode 100644 rust/ccommon-array/src/lib.rs create mode 100644 rust/ccommon-backend/CMakeLists.txt create mode 100644 rust/ccommon-backend/Cargo.toml create mode 100644 rust/ccommon-backend/src/c_export.rs create mode 100644 rust/ccommon-backend/src/compat.rs create mode 100644 rust/ccommon-backend/src/lib.rs create mode 100644 rust/ccommon-backend/src/option/default.rs create mode 100644 rust/ccommon-backend/src/option/parse.rs create mode 100644 rust/ccommon-backend/src/option/print.rs create mode 100644 rust/ccommon-backend/tests/parse.rs create mode 100644 rust/ccommon-buffer/CMakeLists.txt create mode 100644 rust/ccommon-buffer/Cargo.toml create mode 100644 rust/ccommon-buffer/src/buf/mod.rs create mode 100644 rust/ccommon-buffer/src/dbuf/mod.rs create mode 100644 rust/ccommon-buffer/src/lib.rs create mode 100644 rust/ccommon-channel/CMakeLists.txt create mode 100644 rust/ccommon-channel/Cargo.toml create mode 100644 rust/ccommon-channel/src/lib.rs create mode 100644 rust/ccommon-derive/CMakeLists.txt create mode 100644 rust/ccommon-derive/Cargo.toml create mode 100644 rust/ccommon-derive/src/attrs.rs create mode 100644 rust/ccommon-derive/src/lib.rs create mode 100644 rust/ccommon-log/CMakeLists.txt create mode 100644 rust/ccommon-log/Cargo.toml create mode 100644 rust/ccommon-log/src/lib.rs create mode 100644 rust/ccommon-rs/CMakeLists.txt create mode 100644 rust/ccommon-rs/Cargo.toml create mode 100644 rust/ccommon-rs/build.rs rename rust/{ccommon_rs => ccommon-rs}/src/bstring.rs (84%) create mode 100644 rust/ccommon-rs/src/buf.rs create mode 100644 rust/ccommon-rs/src/ccbox.rs create mode 100644 rust/ccommon-rs/src/error.rs create mode 100644 rust/ccommon-rs/src/lib.rs create mode 100644 rust/ccommon-rs/src/log/debug.rs create mode 100644 rust/ccommon-rs/src/log/mod.rs create mode 100644 rust/ccommon-rs/src/log/shim.rs create mode 100644 rust/ccommon-rs/src/metric/counter.rs create mode 100644 rust/ccommon-rs/src/metric/fpn.rs create mode 100644 rust/ccommon-rs/src/metric/gauge.rs create mode 100644 rust/ccommon-rs/src/metric/mod.rs create mode 100644 rust/ccommon-rs/src/option/boolean.rs create mode 100644 rust/ccommon-rs/src/option/fpn.rs create mode 100644 rust/ccommon-rs/src/option/mod.rs create mode 100644 rust/ccommon-rs/src/option/string.rs create mode 100644 rust/ccommon-rs/src/option/uint.rs create mode 100644 rust/ccommon-rs/src/ptrs.rs create mode 100644 rust/ccommon-rs/tests/derive_metrics.rs create mode 100644 rust/ccommon-rs/tests/derive_options.rs create mode 100644 rust/ccommon-rs/tests/log.rs create mode 100644 rust/ccommon-stats/CMakeLists.txt create mode 100644 rust/ccommon-stats/Cargo.toml create mode 100644 rust/ccommon-stats/src/lib.rs create mode 100644 rust/ccommon-stream/CMakeLists.txt create mode 100644 rust/ccommon-stream/Cargo.toml create mode 100644 rust/ccommon-stream/src/lib.rs create mode 100644 rust/ccommon-sys/CMakeLists.txt create mode 100644 rust/ccommon-sys/Cargo.toml create mode 100644 rust/ccommon-sys/build.rs create mode 100644 rust/ccommon-sys/src/lib.rs create mode 100644 rust/ccommon-sys/src/metric.rs create mode 100644 rust/ccommon-sys/wrapper.h create mode 100644 rust/ccommon-time/CMakeLists.txt create mode 100644 rust/ccommon-time/Cargo.toml create mode 100644 rust/ccommon-time/src/lib.rs delete mode 100644 rust/ccommon_rs/CMakeLists.txt delete mode 100644 rust/ccommon_rs/Cargo.toml delete mode 100644 rust/ccommon_rs/src/lib.rs delete mode 100644 src/hash/cc_lookup3.c create mode 100644 src/stats/cc_stats_log.c create mode 100644 test/buffer/CMakeLists.txt create mode 100644 test/buffer/check_buf.c diff --git a/.gitignore b/.gitignore index 781ba3860..0682f193d 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,12 @@ cscope.* lcov CMAKE_BINARY_DIR + +# Generated Rust Bindings +bindings.rs + +# Cargo lock file +Cargo.lock + +# Cargo build path +target \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 41c2b344e..46c0ecd39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,132 +1,57 @@ sudo: false language: c +dist: bionic # using anchor to import sources into linux builds addons: apt: &apt sources: - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.6 - - llvm-toolchain-precise-3.7 - - llvm-toolchain-precise # important for allowed-to-fail matching # see https://docs.travis-ci.com/user/customizing-the-build#Rows-that-are-Allowed-to-Fail env: - - ALLOWED_TO_FAIL=0 + global: + - MAKEFLAGS="-j 2" # travis currently does not support directly setting gcc/clang with versions # (e.g. gcc-4.8) as value for the compiler key. So we will have to manually # request these packages and use environment varibles to create the matrix. -# -# In the case of osx, use brew to install the paritcular versions, instead of -# specifying with packages. -matrix: +jobs: + fast_finish: true include: - # gcc 4.8 on linux - - env: - - C_COMPILER=gcc-4.8 - addons: - apt: - <<: *apt - packages: - - gcc-4.8 - - libsubunit-dev + - name: "gcc-7 on Linux" + compiler: gcc - - # gcc 4.9 on linux - - env: - - C_COMPILER=gcc-4.9 - addons: - apt: - <<: *apt - packages: - - gcc-4.9 - - libsubunit-dev - - # gcc 5 on linux - - env: - - C_COMPILER=gcc-5 - addons: - apt: - <<: *apt - packages: - - gcc-5 - - libsubunit-dev - - # gcc 5 on linux - - env: - - C_COMPILER=gcc-5 + - name: "gcc-7 on Linux, Rust enabled" + compiler: gcc + env: - RUST_ENABLED=1 - addons: - apt: - <<: *apt - packages: - - gcc-5 - - libsubunit-dev - - # clang 3.6 on linux - - env: - - C_COMPILER=clang-3.6 - addons: - apt: - <<: *apt - packages: - - clang-3.6 - - libsubunit-dev - - # clang 3.7 on linux - - env: - - C_COMPILER=clang-3.7 - addons: - apt: - <<: *apt - packages: - - clang-3.7 - - libsubunit-dev - ## gcc 4.8 on osx - #- os: osx - # env: FORMULA=gcc48 COMPILER=gcc C_COMPILER=gcc-4.8 - # - ## gcc 4.9 on osx - #- os: osx - # env: FORMULA=gcc49 COMPILER=gcc C_COMPILER=gcc-4.9 - # - ## gcc 5 on osx - #- os: osx - # env: FORMULA=gcc5 COMPILER=gcc C_COMPILER=gcc-5 + - name: "cargo build" + language: rust + script: + - ./ci/cargo.sh - # OSX 10.13 - # Apple LLVM version 9.1.0 (clang-902.0.39.2) - # Target: x86_64-apple-darwin17.6.0 - os: osx - osx_image: xcode9.4 - env: - - C_COMPILER=clang - - ALLOWED_TO_FAIL=1 + osx_image: xcode11.4 + compiler: clang - # OSX 10.12 - # Apple LLVM version 9.0.0 (clang-900.0.39.2) - # Target: x86_64-apple-darwin16.7.0 - os: osx - osx_image: xcode9.2 - env: - - C_COMPILER=clang - - ALLOWED_TO_FAIL=1 + osx_image: xcode11.4 + language: rust + script: + - ./ci/cargo.sh allow_failures: - os: osx - osx_image: xcode9.4 - env: - - C_COMPILER=clang - - ALLOWED_TO_FAIL=1 - + osx_image: xcode11.4 + compiler: clang - os: osx - osx_image: xcode9.2 - env: - - C_COMPILER=clang - - ALLOWED_TO_FAIL=1 + osx_image: xcode11.4 + language: rust + script: + - ./ci/cargo.sh before_install: - ./ci/before-install.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d2a2c05a..f8eda0f4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.0) project(ccommon C) -enable_testing() +# Uncomment the following to output dependency graph debugging messages +# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1) ################### # detect platform # @@ -36,8 +37,8 @@ endif() # config.h.in has to include entries set/tested here for them to have effect # version info -set(${PROJECT_NAME}_VERSION_MAJOR 1) -set(${PROJECT_NAME}_VERSION_MINOR 2) +set(${PROJECT_NAME}_VERSION_MAJOR 2) +set(${PROJECT_NAME}_VERSION_MINOR 1) set(${PROJECT_NAME}_VERSION_PATCH 0) set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH} @@ -51,54 +52,29 @@ option(HAVE_ASSERT_LOG "assert_log enabled by default" ON) option(HAVE_ASSERT_PANIC "assert_panic disabled by default" OFF) option(HAVE_LOGGING "logging enabled by default" ON) option(HAVE_STATS "stats enabled by default" ON) +option(HAVE_TEST "test built by default" ON) option(HAVE_DEBUG_MM "debugging oriented memory management disabled by default" OFF) -option(COVERAGE "code coverage" OFF) +option(HAVE_COVERAGE "code coverage" OFF) option(HAVE_RUST "rust bindings not built by default" OFF) +option(HAVE_ITT_INSTRUMENTATION "instrument code with ITT API" OFF) + +option(FORCE_CHECK_BUILD "Force building check with ci/install-check.sh" OFF) if(HAVE_RUST) option(RUST_VERBOSE_BUILD "pass -vv to cargo compilation" OFF) endif() -if(BUILD_AND_INSTALL_CHECK) - # (simms) What follows is a crime against build systems as we run the build/install - # for the check library up front, during the planning phase. - - set(LIBCHECK_PREFIX "${CMAKE_BINARY_DIR}/check") - - # check for a local install of check - if(NOT EXISTS "${LIBCHECK_PREFIX}") - # (simms) This is terrible and I did it this way to ensure this gets built - # before the rest of the 'check' tests run. This should be rewritten so that - # the other dependencies know that there's a target that can build check - execute_process( - COMMAND "bash" "${PROJECT_SOURCE_DIR}/ci/install-check.sh" "${LIBCHECK_PREFIX}" - TIMEOUT 300 # if this doesn't build in 5 minutes something is hosed - ) - endif() - - set(CHECK_ROOT_DIR "${LIBCHECK_PREFIX}") - set(CMAKE_REQUIRED_INCLUDES "${CHECK_ROOT_DIR}/include") # these make check link correctly in ccommon and pelikan - set(CMAKE_REQUIRED_LIBRARIES "${CHECK_ROOT_DIR}/lib") -endif() - include(CheckIncludeFiles) if(OS_PLATFORM STREQUAL "OS_LINUX") check_include_files(linux/time64.h HAVE_TIME64) endif() -include(CheckIncludeFiles) -if(OperatingSystem STREQUAL "OS_LINUX") - check_include_files(linux/time64.h HAVE_TIME64) -endif() - include(CheckSymbolExists) check_symbol_exists(sys_signame signal.h HAVE_SIGNAME) include(CheckFunctionExists) check_function_exists(backtrace HAVE_BACKTRACE) - -include(TestBigEndian) -test_big_endian(HAVE_BIG_ENDIAN) +check_function_exists(accept4 HAVE_ACCEPT4) # how to use config.h.in to generate config.h # this has to be set _after_ the above checks @@ -112,46 +88,98 @@ configure_file( ########################## # set compiler flags -# string concat is easier in 3.0, but older versions don't have the concat subcommand -# so we are using list as input until we move to new version -# TODO add build types + add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64) + +# Set a default build type (Release) if none was specified +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") +endif() + set(CMAKE_MACOSX_RPATH 1) -set(CFLAGS_LIST +string(CONCAT CFLAGS "-std=c11 " - "-ggdb3 -O2 " + "-ggdb3 " "-Wall " "-Wmissing-prototypes -Wmissing-declarations -Wredundant-decls " "-Wunused-function -Wunused-value -Wunused-variable " "-fstrict-aliasing ") -string(REPLACE "" "" CFLAGS ${CFLAGS_LIST}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}") if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--no-as-needed -ldl -pthread -fPIC") endif() -if (COVERAGE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage") -endif(COVERAGE) - -# test dependencies include(FindPackageHandleStandardArgs) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") -find_package(Check) -if(NOT CHECK_FOUND) - message(WARNING "Check is required to build and run tests") -endif(NOT CHECK_FOUND) -if(CHECK_FOUND) - check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING) - if(NOT CHECK_WORKING) - message(WARNING "Check version too old to build tests") - endif(NOT CHECK_WORKING) -endif(CHECK_FOUND) +# test dependencies +if (HAVE_TEST) + enable_testing() + # first we try default ways of finding gmodules + find_package(CHECK) + if(CHECK_FOUND) + check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING) + endif(CHECK_FOUND) + # if we don't have a working version of check, build it + if(NOT CHECK_WORKING OR FORCE_CHECK_BUILD) + set(LIBCHECK_PREFIX "${CMAKE_BINARY_DIR}/check") + execute_process( + COMMAND "bash" "${PROJECT_SOURCE_DIR}/ci/install-check.sh" "${LIBCHECK_PREFIX}" + TIMEOUT 300 # if this doesn't build in 5 minutes something is hosed + RESULT_VARIABLE LIBCHECK_RETCODE + ) + if(LIBCHECK_RETCODE) # non-zero means error + message(STATUS "build libcheck failed, return code: " ${LIBCHECK_RETCODE}) + else(LIBCHECK_RETCODE) + # use locally built libcheck + set(CHECK_ROOT_DIR "${LIBCHECK_PREFIX}") + find_package(CHECK) + endif(LIBCHECK_RETCODE) + endif(NOT CHECK_WORKING OR FORCE_CHECK_BUILD) + + # use fluxcapacitor to mock time + if(OS_PLATFORM STREQUAL "OS_LINUX") + set(FLUXCAP_PREFIX "${CMAKE_BINARY_DIR}/fluxcapacitor") + execute_process( + COMMAND "bash" "${PROJECT_SOURCE_DIR}/ci/install-fluxcapacitor.sh" "${FLUXCAP_PREFIX}" + TIMEOUT 60 # if this doesn't build in 60 seconds something is hosed + RESULT_VARIABLE FLUXCAP_RETCODE + ) + if(FLUXCAP_RETCODE) # non-zero means error + message(STATUS "build fluxcapacitor failed, return code: " ${FLUXCAP_RETCODE}) + else(FLUXCAP_RETCODE) + set(FLUXCAP_BINARY "${FLUXCAP_PREFIX}/fluxcapacitor") + message(STATUS "fluxcapacitor available at: " ${FLUXCAP_BINARY}) + endif(FLUXCAP_RETCODE) + endif(OS_PLATFORM STREQUAL "OS_LINUX") +endif(HAVE_TEST) + +if (HAVE_ITT_INSTRUMENTATION) + if(PKG_CONFIG_FOUND) + pkg_check_modules(ITTNOTIFY REQUIRED ittnotify>=1.0) + else() + find_package(ITTNOTIFY REQUIRED 1.0) + endif() + include_directories(${ITTNOTIFY_INCLUDE_DIRS}) + link_directories(${ITTNOTIFY_LIBRARY_DIRS}) + link_libraries(${ITTNOTIFY_LIBRARIES}) +endif(HAVE_ITT_INSTRUMENTATION) find_package(Threads) +if (HAVE_COVERAGE) + if(NOT ${CMAKE_BUILD_TYPE} MATCHES Debug) + message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" ) + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") +endif(HAVE_COVERAGE) # where to find include files include_directories( @@ -159,36 +187,75 @@ include_directories( "${PROJECT_BINARY_DIR}" "include") -if(HAVE_RUST) - enable_language(Rust) - include(CMakeCargo) - add_subdirectory(rust) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_RUST=1") -endif() - - ################### # things to build # ################### add_subdirectory(src) -if(CHECK_WORKING) - include_directories(${include_directories} "${CHECK_INCLUDES}") + +if(HAVE_TEST) + include_directories(${include_directories} ${CHECK_INCLUDES}) add_subdirectory(test) -endif(CHECK_WORKING) +endif(HAVE_TEST) + +if(HAVE_RUST) + include(CMakeCargo) + add_subdirectory(rust) + + if (${CMAKE_VERSION} VERSION_LESS "3.13.0") + # CMakeCargo requires the use of some newer features of cmake + # for changes to dependant libraries to cause a rebuild. This + # will never break the build, it is just annoying for development. + # Leave a warning here, but don't break the build for older cmake + # versions. + message( + WARNING + "Rust targets don't properly pick up changes to dependencies in cmake version <= 3.13" + ) + endif() +endif() ################### # print a summary # ################### +message(STATUS "<<++=====------------------\\/------------------=====++>>") +message(STATUS "<<++ ccommon summary ++>>") +message(STATUS "<<++=====------------------/\\------------------=====++>>") +message(STATUS "=============CMake related=============") +message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) message(STATUS "PLATFORM: " ${OS_PLATFORM}) - message(STATUS "CPPFLAGS: " ${CMAKE_CPP_FLAGS}) message(STATUS "CFLAGS: " ${CMAKE_C_FLAGS}) +message(STATUS "=======================================") +message(STATUS "=======Status of system features=======") message(STATUS "HAVE_SIGNAME: " ${HAVE_SIGNAME}) - message(STATUS "HAVE_BACKTRACE: " ${HAVE_BACKTRACE}) -message(STATUS "HAVE_BIG_ENDIAN: " ${HAVE_BIG_ENDIAN}) - -message(STATUS "CHECK_WORKING: " ${CHECK_WORKING}) +message(STATUS "HAVE_ACCEPT4: " ${HAVE_ACCEPT4}) +if(OS_PLATFORM STREQUAL "OS_LINUX") + message(STATUS "HAVE_TIME64: " ${HAVE_TIME64}) +endif() +message(STATUS "=======================================") + +message(STATUS "======Status of optional features======") +message(STATUS "HAVE_RUST: " ${HAVE_RUST}) +message(STATUS "HAVE_ASSERT_LOG: " ${HAVE_ASSERT_LOG}) +message(STATUS "HAVE_ASSERT_PANIC: " ${HAVE_ASSERT_PANIC}) +message(STATUS "HAVE_LOGGING: " ${HAVE_LOGGING}) +message(STATUS "HAVE_STATS: " ${HAVE_STATS}) +message(STATUS "HAVE_ITT_INSTRUMENTATION: " ${HAVE_ITT_INSTRUMENTATION}) +message(STATUS "HAVE_DEBUG_MM: " ${HAVE_DEBUG_MM}) +message(STATUS "HAVE_TEST: " ${HAVE_TEST}) +message(STATUS "HAVE_COVERAGE: " ${HAVE_COVERAGE}) +message(STATUS "=======================================") + + +if(DUMP_ALL) + message(STATUS "<<++=====------------------\\/------------------=====++>>") + get_cmake_property(_variableNames VARIABLES) + foreach (_variableName ${_variableNames}) + message(STATUS "${_variableName}=${${_variableName}}") + endforeach() + message(STATUS "<<++=====------------------/\\------------------=====++>>") +endif() diff --git a/LICENSE b/LICENSE index ecc06d346..5c3aef4f8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2013-2015 Twitter, Inc +Copyright 2013-2018 Twitter, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/NOTICE b/NOTICE index 2b7bb058e..e0672064d 100644 --- a/NOTICE +++ b/NOTICE @@ -22,3 +22,5 @@ * Boston, MA 02111-1307, USA. */ +We use the CMakeRust project (https://github.com/Devolutions/CMakeRust) under +the Apache 2.0 License. diff --git a/ci/before-install.sh b/ci/before-install.sh index cff9327c3..b5f49421a 100755 --- a/ci/before-install.sh +++ b/ci/before-install.sh @@ -11,21 +11,6 @@ trap cleanup EXIT TOPLEVEL="$(git -C "$(cd "$(dirname "$0")" >/dev/null || exit 1; pwd)" rev-parse --show-toplevel)" || die 'failed to find TOPLEVEL' -# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc - -if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - brew update &>/dev/null - brew install cmake || true # xcode 8.1 is missing cmake - - if [[ "$C_COMPILER" =~ ^gcc && -n "${FORMULA:-}" ]]; then - brew unlink gcc || true - brew unlink "$FORMULA" || true - brew install "$FORMULA" - fi -fi - -export CC="$C_COMPILER" - if [[ -n "${RUST_ENABLED:-}" ]]; then curl https://sh.rustup.rs -sSf | sh -s -- -y fi diff --git a/ci/cargo.sh b/ci/cargo.sh new file mode 100755 index 000000000..8a8c25725 --- /dev/null +++ b/ci/cargo.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +set -uo pipefail +IFS=$'\n\t' + +# Cargo currently does not allow nested workspaces. Since this repo is vendored +# into github.com/twitter/pelikan which is itself a workspace, we cannot commit +# a workspace manifest for this repository. Cargo tracking issue: +# https://github.com/rust-lang/cargo/issues/5042 + +# As a workaround, we can construct a workspace manifest before running the +# build. This allows the crates within this repo to share build artifacts. + +### +# Create workspace manifest +### + +cat > Cargo.toml <
> Cargo.toml +done + +cat >> Cargo.toml <