Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Squashed 'deps/ccommon/' changes from 2ef0163..2168fec
Browse files Browse the repository at this point in the history
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)

git-subtree-dir: deps/ccommon
git-subtree-split: 2168fec
  • Loading branch information
Yao Yue committed Dec 13, 2018
1 parent e4d6eef commit bdbd760
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 197 deletions.
103 changes: 10 additions & 93 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
sudo: false
language: c
dist: xenial

# 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
Expand All @@ -18,115 +16,34 @@ env:
# 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:
include:
# gcc 4.8 on linux
- env:
- C_COMPILER=gcc-4.8
- name: "gcc-5 on Linux"
compiler: gcc
addons:
apt:
<<: *apt
packages:
- gcc-4.8
- libsubunit-dev


# 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-5 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

# 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 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: xcode10.1
compiler: clang

allow_failures:
- os: osx
osx_image: xcode9.4
env:
- C_COMPILER=clang
- ALLOWED_TO_FAIL=1

- os: osx
osx_image: xcode9.2
env:
- C_COMPILER=clang
- ALLOWED_TO_FAIL=1
osx_image: xcode10.1
compiler: clang

before_install:
- ./ci/before-install.sh
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 0 additions & 15 deletions ci/before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi

export RUST_BACKTRACE=full

mkdir -p _build && ( cd _build && "${cmake_cmd[@]}" .. && make -j && make check )
mkdir -p _build && ( cd _build && "${cmake_cmd[@]}" .. && make && make check )
RESULT=$?

egrep -r ":F:|:E:" . |grep -v 'Binary file' || true
Expand Down
93 changes: 31 additions & 62 deletions cmake/CMakeCargo.cmake
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
function(cargo_set_lib_target LIB_NAME)
function(cargo_build)
cmake_parse_arguments(CARGO "" "NAME" "" ${ARGN})
string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME})

set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})

if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIB_TARGET "x86_64-pc-windows-msvc" PARENT_SCOPE)
set(LIB_TARGET "x86_64-pc-windows-msvc")
else()
set(LIB_TARGET "i686-pc-windows-msvc" PARENT_SCOPE)
set(LIB_TARGET "i686-pc-windows-msvc")
endif()
elseif(ANDROID)
elseif(ANDROID)
if(ANDROID_SYSROOT_ABI STREQUAL "x86")
set(LIB_TARGET "i686-linux-android" PARENT_SCOPE)
set(LIB_TARGET "i686-linux-android")
elseif(ANDROID_SYSROOT_ABI STREQUAL "x86_64")
set(LIB_TARGET "x86_64-linux-android" PARENT_SCOPE)
set(LIB_TARGET "x86_64-linux-android")
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm")
set(LIB_TARGET "arm-linux-androideabi" PARENT_SCOPE)
set(LIB_TARGET "arm-linux-androideabi")
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm64")
set(LIB_TARGET "aarch64-linux-android" PARENT_SCOPE)
set(LIB_TARGET "aarch64-linux-android")
endif()
elseif(IOS)
set(LIB_TARGET "universal" PARENT_SCOPE)
set(LIB_TARGET "universal")
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(LIB_TARGET "x86_64-apple-darwin" PARENT_SCOPE)
else()
if(RUST_USE_MUSL)
set(RUST_LIBC_NAME "musl")
else()
set(RUST_LIBC_NAME "gnu")
endif()

set(LIB_TARGET "x86_64-apple-darwin")
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIB_TARGET "x86_64-unknown-linux-${RUST_LIBC_NAME}" PARENT_SCOPE)
set(LIB_TARGET "x86_64-unknown-linux-gnu")
else()
set(LIB_TARGET "i686-unknown-linux-${RUST_LIBC_NAME}" PARENT_SCOPE)
set(LIB_TARGET "i686-unknown-linux-gnu")
endif()
endif()
endfunction()

function(cargo_build)
cmake_parse_arguments(CARGO "" "NAME" "" ${ARGN})
string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME})

get_filename_component(CARGO_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE)

cargo_set_lib_target(LIB_NAME)

if(NOT CMAKE_BUILD_TYPE)
set(LIB_BUILD_TYPE "debug")
Expand All @@ -50,24 +40,14 @@ function(cargo_build)
set(LIB_BUILD_TYPE "debug")
endif()

set(SHARED_LIB_FNAME "${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(STATIC_LIB_FNAME "${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")

set(LIB_BASE_DIR "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}")
set(LIB_FILE "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")

get_filename_component(SHARED_LIB_FILE "${LIB_BASE_DIR}/${SHARED_LIB_FNAME}" ABSOLUTE)
get_filename_component(STATIC_LIB_FILE "${LIB_BASE_DIR}/${STATIC_LIB_FNAME}" ABSOLUTE)

if(IOS)
set(CARGO_ARGS "lipo")
else()
set(CARGO_ARGS "build")
list(APPEND CARGO_ARGS "--target" ${LIB_TARGET})
endif()

if(RUST_VERBOSE_BUILD)
list(APPEND CARGO_ARGS "-vv")
endif()
if(IOS)
set(CARGO_ARGS "lipo")
else()
set(CARGO_ARGS "build")
list(APPEND CARGO_ARGS "--target" ${LIB_TARGET})
endif()

if(${LIB_BUILD_TYPE} STREQUAL "release")
list(APPEND CARGO_ARGS "--release")
Expand All @@ -78,24 +58,13 @@ function(cargo_build)
set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}")

add_custom_command(
OUTPUT ${STATIC_LIB_FILE}
COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${LIB_SOURCES}
COMMENT "running cargo")
add_custom_target(${CARGO_NAME}_static_target ALL DEPENDS ${STATIC_LIB_FILE})
add_library(${CARGO_NAME}_static STATIC IMPORTED GLOBAL)
add_dependencies(${CARGO_NAME}_static ${CARGO_NAME}_static_target)
set_target_properties(${CARGO_NAME}_static PROPERTIES IMPORTED_LOCATION ${STATIC_LIB_FILE})

add_custom_command(
OUTPUT ${SHARED_LIB_FILE}
OUTPUT ${LIB_FILE}
COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${LIB_SOURCES}
COMMENT "running cargo")
add_custom_target(${CARGO_NAME}_shared_target ALL DEPENDS ${SHARED_LIB_FILE})
add_library(${CARGO_NAME}_shared SHARED IMPORTED GLOBAL)
add_dependencies(${CARGO_NAME}_shared ${CARGO_NAME}_shared_target)
set_target_properties(${CARGO_NAME}_shared PROPERTIES IMPORTED_LOCATION ${SHARED_LIB_FILE})
endfunction()
add_custom_target(${CARGO_NAME}_target ALL DEPENDS ${LIB_FILE})
add_library(${CARGO_NAME} STATIC IMPORTED GLOBAL)
add_dependencies(${CARGO_NAME} ${CARGO_NAME}_target)
set_target_properties(${CARGO_NAME} PROPERTIES IMPORTED_LOCATION ${LIB_FILE})
endfunction()
4 changes: 2 additions & 2 deletions cmake/CMakeDetermineRustCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if(NOT CMAKE_Rust_COMPILER)
endif()
endif()

message(STATUS "Cargo Prefix: ${CARGO_PREFIX}")
message(STATUS "Cargo Home: ${CARGO_HOME}")
message(STATUS "Rust Compiler Version: ${RUSTC_VERSION}")

mark_as_advanced(CMAKE_Rust_COMPILER)
Expand All @@ -18,7 +18,7 @@ if(CMAKE_Rust_COMPILER)
set(CMAKE_Rust_COMPILER_LOADED 1)
endif(CMAKE_Rust_COMPILER)

configure_file(${CMAKE_SOURCE_DIR}/cmake/CMakeRustCompiler.cmake.in
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeRustCompiler.cmake.in
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakeRustCompiler.cmake IMMEDIATE @ONLY)

set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC")
Expand Down
64 changes: 64 additions & 0 deletions cmake/CargoLink.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

function(cargo_print)
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${ARGN}")
endfunction()

function(cargo_link)
cmake_parse_arguments(CARGO_LINK "" "NAME" "TARGETS;EXCLUDE" ${ARGN})

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cargo-link.c" "void cargo_link() {}")
add_library(${CARGO_LINK_NAME} "${CMAKE_CURRENT_BINARY_DIR}/cargo-link.c")
target_link_libraries(${CARGO_LINK_NAME} ${CARGO_LINK_TARGETS})

get_target_property(LINK_LIBRARIES ${CARGO_LINK_NAME} LINK_LIBRARIES)

foreach(LINK_LIBRARY ${LINK_LIBRARIES})
get_target_property(_INTERFACE_LINK_LIBRARIES ${LINK_LIBRARY} INTERFACE_LINK_LIBRARIES)
list(APPEND LINK_LIBRARIES ${_INTERFACE_LINK_LIBRARIES})
endforeach()
list(REMOVE_DUPLICATES LINK_LIBRARIES)

if(CARGO_LINK_EXCLUDE)
list(REMOVE_ITEM LINK_LIBRARIES ${CARGO_LINK_EXCLUDE})
endif()

set(LINK_DIRECTORIES "")
foreach(LINK_LIBRARY ${LINK_LIBRARIES})
if(TARGET ${LINK_LIBRARY})
get_target_property(_IMPORTED_CONFIGURATIONS ${LINK_LIBRARY} IMPORTED_CONFIGURATIONS)
list(FIND _IMPORTED_CONFIGURATIONS "RELEASE" _IMPORTED_CONFIGURATION_INDEX)
if (NOT (${_IMPORTED_CONFIGURATION_INDEX} GREATER -1))
set(_IMPORTED_CONFIGURATION_INDEX 0)
endif()
list(GET _IMPORTED_CONFIGURATIONS ${_IMPORTED_CONFIGURATION_INDEX} _IMPORTED_CONFIGURATION)
get_target_property(_IMPORTED_LOCATION ${LINK_LIBRARY} "IMPORTED_LOCATION_${_IMPORTED_CONFIGURATION}")
get_filename_component(_IMPORTED_DIR ${_IMPORTED_LOCATION} DIRECTORY)
get_filename_component(_IMPORTED_NAME ${_IMPORTED_LOCATION} NAME_WE)
if(NOT WIN32)
string(REGEX REPLACE "^lib" "" _IMPORTED_NAME ${_IMPORTED_NAME})
endif()
list(APPEND LINK_DIRECTORIES ${_IMPORTED_DIR})
cargo_print("cargo:rustc-link-lib=static=${_IMPORTED_NAME}")
else()
if("${LINK_LIBRARY}" MATCHES "^.*/(.+)\\.framework$")
set(FRAMEWORK_NAME ${CMAKE_MATCH_1})
cargo_print("cargo:rustc-link-lib=framework=${FRAMEWORK_NAME}")
elseif("${LINK_LIBRARY}" MATCHES "^(.*)/(.+)\\.so$")
set(LIBRARY_DIR ${CMAKE_MATCH_1})
set(LIBRARY_NAME ${CMAKE_MATCH_2})
if(NOT WIN32)
string(REGEX REPLACE "^lib" "" LIBRARY_NAME ${LIBRARY_NAME})
endif()
list(APPEND LINK_DIRECTORIES ${LIBRARY_DIR})
cargo_print("cargo:rustc-link-lib=${LIBRARY_NAME}")
else()
cargo_print("cargo:rustc-link-lib=${LINK_LIBRARY}")
endif()
endif()
endforeach()
list(REMOVE_DUPLICATES LINK_DIRECTORIES)

foreach(LINK_DIRECTORY ${LINK_DIRECTORIES})
cargo_print("cargo:rustc-link-search=native=${LINK_DIRECTORY}")
endforeach()
endfunction()
Loading

0 comments on commit bdbd760

Please sign in to comment.