Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def envoy_linkopts():
],
"@envoy//bazel:windows_x86_64": [
"-DEFAULTLIB:advapi32.lib",
"-DEFAULTLIB:ws2_32.lib",
"-WX",
],
"//conditions:default": [
"-pthread",
Expand Down Expand Up @@ -142,6 +144,11 @@ def envoy_test_linkopts():
"-pagezero_size 10000",
"-image_base 100000000",
],
"@envoy//bazel:windows_x86_64": [
"-DEFAULTLIB:advapi32.lib",
"-DEFAULTLIB:ws2_32.lib",
"-WX",
],

# TODO(mattklein123): It's not great that we universally link against the following libs.
# In particular, -latomic and -lrt are not needed on all platforms. Make this more granular.
Expand Down
2 changes: 1 addition & 1 deletion bazel/repositories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
# export BUILD_CONCURRENCY=0

# Hash environment variables we care about to force rebuilds when they change.
ENV_HASH=$(echo "${CC} ${CXX} ${LD_LIBRARY_PATH}" | md5sum | cut -f 1 -d\ )
ENV_HASH=$(echo "${CC} ${CXX} ${LD_LIBRARY_PATH} ${BAZEL_WINDOWS_BUILD_TYPE}" | md5sum | cut -f 1 -d\ )

# Don't build inside the directory Bazel believes the repository_rule output goes. Instead, do so in
# a parallel directory. This allows the build artifacts to survive Bazel clobbering the repostory
Expand Down
4 changes: 3 additions & 1 deletion ci/build_container/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ CXX ?= g++
CXXFLAGS ?= -ggdb3 -fno-omit-frame-pointer -O2
CFLAGS ?= -ggdb3 -fno-omit-frame-pointer -O2
CPPFLAGS ?= -DNDEBUG
BAZEL_WINDOWS_BUILD_TYPE ?= opt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set this in https://github.com/envoyproxy/envoy/blob/master/bazel/repositories.bzl#L88 based on the config_setting for Windows build? I.e. not have to specify it manually? Even better, I would name this BAZEL_WINDOWS_DEBUG_BUILD to make it clear, I think that's the key thing you want to extract from the config_setting here.


# Keep track of the env vars we depend upon for $(THIRDPARTY_DEPS)/%.dep.env. If the list (captured
# above) of flags changes, this should be updated.
ENV_STR := $(CC) $(CXX) $(CXXFLAGS) $(CFLAGS) $(CPPFLAGS)
ENV_STR := $(CC) $(CXX) $(CXXFLAGS) $(CFLAGS) $(CPPFLAGS) $(BAZEL_WINDOWS_BUILD_TYPE)

# If $(BUILD_DISTINCT) is set in the make environment, the artifacts are built and installed in
# distinct directories under $(THIRDPARTY_BUILD) and $(THIRDPARTY_SRC). They end up looking like
Expand Down Expand Up @@ -47,6 +48,7 @@ build-recipe = cd "$(THIRDPARTY_SRC)" && \
CFLAGS="$(CFLAGS)" \
CXXFLAGS="$(CXXFLAGS)" \
CPPFLAGS="$(CPPFLAGS)" \
BAZEL_WINDOWS_BUILD_TYPE="$(BAZEL_WINDOWS_BUILD_TYPE)" \
$(1) \
bash -c "time $(CURDIR)/recipe_wrapper.sh $(realpath $<)" 2>&1) > $@.log) || (cat $@.log; exit 1)) && \
$(build-complete)
Expand Down
15 changes: 14 additions & 1 deletion ci/build_container/build_recipes/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ mkdir build

cd build

build_type=Release
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=Debug
fi

cmake -G "Ninja" ../benchmark \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_BUILD_TYPE="$build_type" \
-DBENCHMARK_ENABLE_GTEST_TESTS=OFF
ninja

benchmark_lib="libbenchmark.a"
if [[ "${OS}" == "Windows_NT" ]]; then
benchmark_lib="benchmark.lib"
if [[ "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp "src/CMakeFiles/benchmark.dir/benchmark.pdb" "$THIRDPARTY_BUILD/lib/benchmark.pdb"
fi
fi

cp "src/$benchmark_lib" "$THIRDPARTY_BUILD"/lib
Expand Down
17 changes: 10 additions & 7 deletions ci/build_container/build_recipes/cares.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ cd build

build_type=RelWithDebInfo
if [[ "${OS}" == "Windows_NT" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library. If Envoy is built with '-c dbg', then it will
# use the Debug C Runtime Library. Setting CMAKE_BUILD_TYPE to Debug will cause c-ares
# to use the debug version as well
# TODO: when '-c fastbuild' and '-c opt' work for Windows builds, set this appropriately
build_type=Debug
build_type=Release
if [[ "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=Debug
fi
fi

cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX="$THIRDPARTY_BUILD" \
Expand All @@ -38,6 +40,7 @@ cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX="$THIRDPARTY_BUILD" \
ninja
ninja install

if [[ "${OS}" == "Windows_NT" ]]; then
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp "CMakeFiles/c-ares.dir/c-ares.pdb" "$THIRDPARTY_BUILD/lib/c-ares.pdb"
fi
12 changes: 6 additions & 6 deletions ci/build_container/build_recipes/libevent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ cd build

# libevent defaults CMAKE_BUILD_TYPE to Release
build_type=Release
if [[ "${OS}" == "Windows_NT" ]]; then
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library. If Envoy is built with '-c dbg', then it will
# use the Debug C Runtime Library. Setting CMAKE_BUILD_TYPE to Debug will cause libevent
# to use the debug version as well
# TODO: when '-c fastbuild' and '-c opt' work for Windows builds, set this appropriately
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=Debug
fi

Expand All @@ -34,6 +33,7 @@ cmake -G "Ninja" \
ninja
ninja install

if [[ "${OS}" == "Windows_NT" ]]; then
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp "CMakeFiles/event.dir/event.pdb" "$THIRDPARTY_BUILD/lib/event.pdb"
fi
15 changes: 13 additions & 2 deletions ci/build_container/build_recipes/luajit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,23 @@ EOF

if [[ "${OS}" == "Windows_NT" ]]; then
cd src
./msvcbuild.bat debug
build_type="release"
if [[ "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=debug
fi
./msvcbuild.bat $build_type

mkdir -p "$THIRDPARTY_BUILD/include/luajit-2.0"
cp *.h* "$THIRDPARTY_BUILD/include/luajit-2.0"
cp luajit.lib "$THIRDPARTY_BUILD/lib"
cp *.pdb "$THIRDPARTY_BUILD/lib"
if [[ "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp *.pdb "$THIRDPARTY_BUILD/lib"
fi
else
patch -p1 < ../luajit_make.diff

Expand Down
22 changes: 17 additions & 5 deletions ci/build_container/build_recipes/nghttp2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ cd nghttp2-"$VERSION"
# TODO: remove once https://github.com/nghttp2/nghttp2/pull/1198 is merged
cat > nghttp2_cmakelists.diff << 'EOF'
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 17e422b2..e58070f5 100644
index 17e422b..54de0b8 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -56,6 +56,7 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB)
@@ -55,7 +55,7 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB)
set_target_properties(nghttp2_static PROPERTIES
COMPILE_FLAGS "${WARNCFLAGS}"
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
ARCHIVE_OUTPUT_NAME nghttp2
+ ARCHIVE_OUTPUT_DIRECTORY static
- ARCHIVE_OUTPUT_NAME nghttp2
+ ARCHIVE_OUTPUT_NAME nghttp2_static
)
target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB")
if(ENABLE_STATIC_LIB)
Expand All @@ -34,14 +35,25 @@ fi
mkdir build
cd build

build_type=Release
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=Debug
fi

cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX="$THIRDPARTY_BUILD" \
-DCMAKE_INSTALL_LIBDIR="$THIRDPARTY_BUILD/lib" \
-DENABLE_STATIC_LIB=on \
-DENABLE_LIB_ONLY=on \
-DCMAKE_BUILD_TYPE="$build_type" \
..
ninja
ninja install

if [[ "${OS}" == "Windows_NT" ]]; then
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp "lib/CMakeFiles/nghttp2_static.dir/nghttp2_static.pdb" "$THIRDPARTY_BUILD/lib/nghttp2_static.pdb"
fi
17 changes: 10 additions & 7 deletions ci/build_container/build_recipes/yaml-cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ cd build

build_type=RelWithDebInfo
if [[ "${OS}" == "Windows_NT" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library. If Envoy is built with '-c dbg', then it will
# use the Debug C Runtime Library. Setting CMAKE_BUILD_TYPE to Debug will cause yaml-cpp
# to use the debug version as well
# TODO: when '-c fastbuild' and '-c opt' work for Windows builds, set this appropriately
build_type=Debug
build_type=Release
if [[ "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=Debug
fi
fi

cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="$THIRDPARTY_BUILD" \
Expand All @@ -32,6 +34,7 @@ cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="$THIRDPARTY_BUILD" \
..
ninja install

if [[ "${OS}" == "Windows_NT" ]]; then
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp "CMakeFiles/yaml-cpp.dir/yaml-cpp.pdb" "$THIRDPARTY_BUILD/lib/yaml-cpp.pdb"
fi
16 changes: 14 additions & 2 deletions ci/build_container/build_recipes/zlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ cd zlib-"$VERSION"
mkdir build
cd build

cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="$THIRDPARTY_BUILD" ..
build_type=Release
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# On Windows, every object file in the final executable needs to be compiled to use the
# same version of the C Runtime Library -- there are different versions for debug and
# release builds. The script "ci/do_ci.ps1" will pass BAZEL_WINDOWS_BUILD_TYPE=dbg
# to bazel when performing a debug build.
build_type=Debug
fi

cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="$THIRDPARTY_BUILD" \
-DCMAKE_BUILD_TYPE="$build_type" \
..
ninja
ninja install

if [[ "${OS}" == "Windows_NT" ]]; then
if [[ "${OS}" == "Windows_NT" && "${BAZEL_WINDOWS_BUILD_TYPE}" == "dbg" ]]; then
# .pdb files are not generated for release builds
cp "CMakeFiles/zlibstatic.dir/zlibstatic.pdb" "$THIRDPARTY_BUILD/lib/zlibstatic.pdb"
fi
2 changes: 1 addition & 1 deletion ci/build_setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ $env:ENVOY_SRCDIR = [System.IO.Path]::GetFullPath("$PSScriptRoot\..")
echo "ENVOY_BAZEL_ROOT: $env:ENVOY_BAZEL_ROOT"
echo "ENVOY_SRCDIR: $env:ENVOY_SRCDIR"

$env:BAZEL_BASE_OPTIONS="--nomaster_bazelrc --output_base=$env:ENVOY_BAZEL_ROOT --bazelrc=$env:ENVOY_SRCDIR\windows\tools\bazel.rc"
$env:BAZEL_BASE_OPTIONS="--noworkspace_rc --output_base=$env:ENVOY_BAZEL_ROOT --bazelrc=$env:ENVOY_SRCDIR\windows\tools\bazel.rc"
$env:BAZEL_BUILD_OPTIONS="--strategy=Genrule=standalone --spawn_strategy=standalone --verbose_failures --jobs=$env:NUM_CPUS --show_task_finish $env:BAZEL_BUILD_EXTRA_OPTIONS"
$env:BAZEL_TEST_OPTIONS="$env:BAZEL_BUILD_OPTIONS --cache_test_results=no --test_output=all $env:BAZEL_EXTRA_TEST_OPTIONS"
59 changes: 48 additions & 11 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,54 @@ trap { $host.SetShouldExit(1) }
. "$PSScriptRoot\build_setup.ps1"
Write-Host "building using $env:NUM_CPUS CPUs"

function bazel_debug_binary_build() {
function bazel_binary_build($type) {
echo "Building..."
pushd "$env:ENVOY_SRCDIR"
bazel $env:BAZEL_BASE_OPTIONS.Split(" ") build $env:BAZEL_BUILD_OPTIONS.Split(" ") -c dbg "//source/exe:envoy-static"
$exit = $LASTEXITCODE
if ($exit -ne 0) {
popd
exit $exit
}
popd
bazel $env:BAZEL_BASE_OPTIONS.Split(" ") build "--action_env=BAZEL_WINDOWS_BUILD_TYPE=$type" $env:BAZEL_BUILD_OPTIONS.Split(" ") -c $type "//source/exe:envoy-static"
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
}

echo "bazel debug build..."
bazel_debug_binary_build
function bazel_test($type, $test) {
if ($test -ne "") {
bazel $env:BAZEL_BASE_OPTIONS.Split(" ") test "--action_env=BAZEL_WINDOWS_BUILD_TYPE=$type" $env:BAZEL_TEST_OPTIONS.Split(" ") -c $type $test
} else {
echo "running windows tests"
bazel $env:BAZEL_BASE_OPTIONS.Split(" ") test "--action_env=BAZEL_WINDOWS_BUILD_TYPE=$type" $env:BAZEL_TEST_OPTIONS.Split(" ") -c $type "//test:windows_tests"
}
exit $LASTEXITCODE
}

$action = $args[0]
$test = $args[1]

switch ($action) {
"bazel.release" {
echo "bazel release build with tests..."
bazel_binary_build "opt"
bazel_test "opt" "$test"
}
"bazel.release.server_only" {
echo "bazel release build..."
bazel_binary_build "opt"
}
"bazel.debug" {
echo "bazel debug build with tests..."
bazel_binary_build "dbg"
bazel_test "dbg" "$test"
}
"bazel.debug.server_only" {
echo "bazel debug build..."
bazel_binary_build "dbg"
}
"bazel.dev" {
echo "bazel fastbuild build with tests..."
bazel_binary_build "fastbuild"
bazel_test "fastbuild" "$test"
}
default {
echo "unknown action: $action"
exit 1
}
}
34 changes: 31 additions & 3 deletions ci/prebuilt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ config_setting(
values = {"cpu": "x64_windows"},
)

config_setting(
name = "windows_dbg_build",
values = {
"cpu": "x64_windows",
"compilation_mode": "dbg",
},
)

config_setting(
name = "windows_fastbuild_build",
values = {
"cpu": "x64_windows",
"compilation_mode": "fastbuild",
},
)

config_setting(
name = "windows_opt_build",
values = {
"cpu": "x64_windows",
"compilation_mode": "opt",
},
)

cc_library(
name = "ares",
srcs = select({
Expand Down Expand Up @@ -52,7 +76,7 @@ cc_library(
cc_library(
name = "nghttp2",
srcs = select({
":windows_x86_64": ["thirdparty_build/lib/nghttp2.lib"],
":windows_x86_64": ["thirdparty_build/lib/nghttp2_static.lib"],
"//conditions:default": ["thirdparty_build/lib/libnghttp2.a"],
}),
hdrs = glob(["thirdparty_build/include/nghttp2/**/*.h"]),
Expand All @@ -69,7 +93,9 @@ cc_library(
cc_library(
name = "yaml_cpp",
srcs = select({
":windows_x86_64": glob(["thirdparty_build/lib/libyaml-cpp*.lib"]),
":windows_dbg_build": ["thirdparty_build/lib/libyaml-cppmdd.lib"],
":windows_fastbuild_build": ["thirdparty_build/lib/libyaml-cppmd.lib"],
":windows_opt_build": ["thirdparty_build/lib/libyaml-cppmd.lib"],
"//conditions:default": ["thirdparty_build/lib/libyaml-cpp.a"],
}),
hdrs = glob(["thirdparty_build/include/yaml-cpp/**/*.h"]),
Expand All @@ -79,7 +105,9 @@ cc_library(
cc_library(
name = "zlib",
srcs = select({
":windows_x86_64": glob(["thirdparty_build/lib/zlibstaticd.lib"]),
":windows_dbg_build": ["thirdparty_build/lib/zlibstaticd.lib"],
":windows_fastbuild_build": ["thirdparty_build/lib/zlibstatic.lib"],
":windows_opt_build": ["thirdparty_build/lib/zlibstatic.lib"],
"//conditions:default": ["thirdparty_build/lib/libz.a"],
}),
hdrs = [
Expand Down
Loading