Skip to content

Commit

Permalink
Bazel build support
Browse files Browse the repository at this point in the history
  • Loading branch information
mapx authored and mapx committed Feb 26, 2019
1 parent 76bacfe commit 62c0e4e
Show file tree
Hide file tree
Showing 17 changed files with 546 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ Testing/*
/buckaroo/
.buckconfig.local
BUCKAROO_DEPS

# Bazel
bazel-*
45 changes: 31 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ compiler:
- clang

env:
- EASTL_CONFIG=Debug
- EASTL_CONFIG=Release
- EASTL_CONFIG=Debug BUILDER=cmake
- EASTL_CONFIG=Release BUILDER=cmake
- EASTL_CONFIG=Debug BUILDER=bazel
- EASTL_CONFIG=Release BUILDER=bazel

addons:
apt:
Expand All @@ -23,6 +25,8 @@ addons:
- cmake-data
- g++-7
- clang-5.0
- wget
- pkg-config

matrix:
include:
Expand All @@ -34,28 +38,41 @@ matrix:
- os: osx
compiler: gcc

before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel_0.20.0-linux-x86_64.deb ;fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel_0.20.0-linux-x86_64.deb.sha256 ;fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sha256sum -c bazel_0.20.0-linux-x86_64.deb.sha256 ;fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo dpkg -i bazel_0.20.0-linux-x86_64.deb ;fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then wget https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel-0.20.0-installer-darwin-x86_64.sh ;fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sh bazel-0.20.0-installer-darwin-x86_64.sh ;fi

install:
# MOJI check; exit 1 if non-ascii characters detected in C++
- if [[ -n "$USE_MOJI_CHECK" && -n `git grep -P "[^[:ascii:]]" source test` ]]; then echo "Moji Detected" && exit 1 ;fi
- if [[ -n "$USE_MOJI_CHECK" ]]; then exit 0 ;fi
- if [[ "$CXX" == "g++" ]]; then export CC="gcc-7" ;fi
- if [[ "$CXX" == "g++" ]]; then export CXX="g++-7" ;fi
- if [[ -n "$USE_MOJI_CHECK" && -n `git grep -P "[^[:ascii:]]" source test` ]]; then echo "Moji Detected" && exit 1 ;fi
- if [[ -n "$USE_MOJI_CHECK" ]]; then exit 0 ;fi
- if [[ "$CXX" == "g++" ]]; then export CC="gcc-7" ;fi
- if [[ "$CXX" == "g++" ]]; then export CXX="g++-7" ;fi

# Universal Setup
before_script:
- mkdir build_$EASTL_CONFIG
- cd build_$EASTL_CONFIG
- cmake .. -DEASTL_BUILD_BENCHMARK:BOOL=ON -DEASTL_BUILD_TESTS:BOOL=ON
- cmake --build . --config $EASTL_CONFIG
- if [[ "$BUILDER" == "cmake" ]]; then mkdir build_$EASTL_CONFIG ;fi
- if [[ "$BUILDER" == "cmake" ]]; then cd build_$EASTL_CONFIG ;fi
- if [[ "$BUILDER" == "cmake" ]]; then cmake .. -DEASTL_BUILD_BENCHMARK:BOOL=ON -DEASTL_BUILD_TESTS:BOOL=ON ;fi
- if [[ "$BUILDER" == "cmake" ]]; then cmake --build . --config $EASTL_CONFIG ;fi

script:
# Run Tests
- cd $TRAVIS_BUILD_DIR/build_$EASTL_CONFIG/test
- ctest -C $EASTL_CONFIG -V || exit 1
- if [[ "$BUILDER" == "cmake" ]]; then cd $TRAVIS_BUILD_DIR/build_$EASTL_CONFIG/test ;fi
- if [[ "$BUILDER" == "cmake" ]]; then ctest -C $EASTL_CONFIG -V || exit 1 ;fi
- if [[ "$BUILDER" == "bazel" && "$EASTL_CONFIG" == "Debug" ]]; then bazel run -c dbg --copt "-DEASTL_DEBUG=1" //:test-runner ;fi
- if [[ "$BUILDER" == "bazel" && "$EASTL_CONFIG" == "Release" ]]; then bazel run -c opt --copt "-DEASTL_DEBUG=0" //:test-runner ;fi

# Run Benchmarks
- cd $TRAVIS_BUILD_DIR/build_$EASTL_CONFIG/benchmark
- ctest -C $EASTL_CONFIG -V || exit 1
- if [[ "$BUILDER" == "cmake" ]]; then cd $TRAVIS_BUILD_DIR/build_$EASTL_CONFIG/benchmark ;fi
- if [[ "$BUILDER" == "cmake" ]]; then ctest -C $EASTL_CONFIG -V || exit 1 ;fi
- if [[ "$BUILDER" == "bazel" && "$EASTL_CONFIG" == "Debug" ]]; then bazel run -c dbg --copt "-DEASTL_DEBUG=1" //:benchmark ;fi
- if [[ "$BUILDER" == "bazel" && "$EASTL_CONFIG" == "Release" ]]; then bazel run -c opt --copt "-DEASTL_DEBUG=0" //:benchmark ;fi


branches:
except:
Expand Down
105 changes: 105 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
licenses(["notice"])

exports_files(["LICENSE"])

load(
"//config:copts.bzl",
"EASTL_DEFAULT_COPTS",
"EASTL_TEST_COPTS",
"EASTL_EXCEPTIONS_FLAG",
"EASTL_EXCEPTIONS_FLAG_LINKOPTS",
)

cc_library(
name = "eastl",
srcs = glob([
"source/**/*.cpp",
]),
hdrs = glob([
"include/EASTL/**/*.h",
]),
copts = EASTL_DEFAULT_COPTS + [
"-D_CHAR16T",
"-D_CRT_SECURE_NO_WARNINGS",
"-D_SCL_SECURE_NO_WARNINGS",
"-DEASTL_OPENSOURCE=1",
],
linkopts = EASTL_EXCEPTIONS_FLAG_LINKOPTS,
strip_include_prefix = "include",
visibility = [
"//visibility:public",
],
deps = [
"//test/packages/EABase:eabase",
],
)

cc_library(
name = "test",
srcs = glob(
[
"test/source/**/*.cpp",
"test/source/**/*.h",
],
exclude = [
"test/source/main.cpp",
],
),
hdrs = glob(
[
"test/source/**/*.h",
],
),
copts = EASTL_TEST_COPTS + [
"-DEASTL_OPENSOURCE=1",
"-DEASTL_THREAD_SUPPORT_AVAILABLE=0",
],
linkopts = EASTL_EXCEPTIONS_FLAG_LINKOPTS,
strip_include_prefix = "test/source",
textual_hdrs = glob([
"test/source/**/*.inl",
]),
deps = [
"//:eastl",
"//test/packages/EAAssert:eaassert",
"//test/packages/EABase:eabase",
"//test/packages/EAMain:eamain",
"//test/packages/EAStdC:eastdc",
"//test/packages/EATest:eatest",
"//test/packages/EAThread:eathread",
],
)

cc_binary(
name = "test-runner",
srcs = glob([
"test/source/main.cpp",
]),
copts = EASTL_DEFAULT_COPTS + [
"-DEASTL_OPENSOURCE=1",
"-DEASTL_THREAD_SUPPORT_AVAILABLE=0",
],
linkopts = EASTL_EXCEPTIONS_FLAG_LINKOPTS,
deps = [
"//:test",
],
)

cc_binary(
name = "benchmark",
srcs = glob([
"benchmark/source/**/*.cpp",
"benchmark/source/**/*.h",
]),
copts = EASTL_DEFAULT_COPTS + [
"-DEASTL_OPENSOURCE=1",
"-DEASTL_THREAD_SUPPORT_AVAILABLE=0",
],
linkopts = EASTL_EXCEPTIONS_FLAG_LINKOPTS,
deps = [
"//:eastl",
"//:test",
"//test/packages/EAStdC:eastdc",
"//test/packages/EATest:eatest",
],
)
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,25 @@ popd
```

The value of EASTL_BUILD_BENCHMARK can be toggled to `ON` in order to build projects that include the benchmark program.

### Building using Bazel

EASTL can also be built using [Bazel Build](https://www.bazel.build).

To build EASTL:

```bash
bazel build //:eastl
```

To run the tests:

```bash
bazel run //:test-runner
```

To run the benchmarks:

```bash
bazel run //:benchmark
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EA Standard Template Library

[![Build Status](https://travis-ci.org/electronicarts/EASTL.svg?branch=master)](https://travis-ci.org/electronicarts/EASTL) [![Build status](https://ci.appveyor.com/api/projects/status/dtn82qr8tw8o3vmi?svg=true)](https://ci.appveyor.com/project/rparolin/eastl)
[![Build Status](https://travis-ci.org/mapx/EASTL.svg?branch=bazel_support)](https://travis-ci.org/mapx/EASTL) [![Build status](https://ci.appveyor.com/api/projects/status/qmw0rvk89hj2c1hg?svg=true)](https://ci.appveyor.com/project/mapx/eastl)

EASTL stands for Electronic Arts Standard Template Library. It is a C++ template library of containers, algorithms, and iterators useful for runtime and tool development across multiple platforms. It is a fairly extensive and robust implementation of such a library and has an emphasis on high performance above all other considerations.

Expand Down
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
workspace(name = "com_ea_eastl")

# Bazel toolchains
http_archive(
name = "bazel_toolchains",
sha256 = "4329663fe6c523425ad4d3c989a8ac026b04e1acedeceb56aa4b190fa7f3973c",
strip_prefix = "bazel-toolchains-bc09b995c137df042bb80a395b73d7ce6f26afbe",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/bc09b995c137df042bb80a395b73d7ce6f26afbe.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/bc09b995c137df042bb80a395b73d7ce6f26afbe.tar.gz",
],
)
33 changes: 33 additions & 0 deletions config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load(":compiler_config_setting.bzl", "create_llvm_config")

create_llvm_config(
name = "llvm_compiler",
visibility = ["//:__subpackages__"],
)

# following configs are based on mapping defined in: https://git.io/v5Ijz
config_setting(
name = "ios",
values = {
"cpu": "darwin",
},
visibility = ["//:__subpackages__"],
)

config_setting(
name = "windows",
values = {
"cpu": "x64_windows",
},
visibility = ["//:__subpackages__"],
)

config_setting(
name = "ppc",
values = {
"cpu": "ppc",
},
visibility = ["//:__subpackages__"],
)


39 changes: 39 additions & 0 deletions config/compiler_config_setting.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright 2018 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Creates config_setting that allows selecting based on 'compiler' value."""

def create_llvm_config(name, visibility):
# The "do_not_use_tools_cpp_compiler_present" attribute exists to
# distinguish between older versions of Bazel that do not support
# "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
# In the future, the only way to select on the compiler will be through
# flag_values{"@bazel_tools//tools/cpp:compiler"} and the else branch can
# be removed.
if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"):
native.config_setting(
name = name,
flag_values = {
"@bazel_tools//tools/cpp:compiler": "llvm",
},
visibility = visibility,
)
else:
native.config_setting(
name = name,
values = {"compiler": "llvm"},
visibility = visibility,
)
Loading

0 comments on commit 62c0e4e

Please sign in to comment.