Skip to content

Commit

Permalink
build: enable release builds on Windows (envoyproxy#5812)
Browse files Browse the repository at this point in the history
Now that envoyproxy#5218 has been merged, we can enable release builds on Windows. This PR updates `ci/do_ci.ps1` to build release + fastbuild versions in addition to debug versions. It also removes support for build scripts in `ci/build_container/build_recipes/` on Windows, as there is no clean way to pass information from Bazel regarding the type of build to those scripts

Risk Level: Low
Testing: `bazel build //source/... && bazel test //test/...`

Signed-off-by: Sam Smith <sesmith177@gmail.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
  • Loading branch information
sesmith177 authored and fredlas committed Mar 5, 2019
1 parent 53a35fc commit d558951
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 101 deletions.
51 changes: 51 additions & 0 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library")
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library")
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")

def envoy_package():
native.package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -195,6 +196,56 @@ def envoy_include_prefix(path):
return "/".join(path.split("/")[1:])
return None

# External CMake C++ library targets should be specified with this function. This defaults
# to building the dependencies with ninja
def envoy_cmake_external(
name,
cache_entries = {},
cmake_options = ["-GNinja"],
make_commands = ["ninja", "ninja install"],
lib_source = "",
postfix_script = "",
static_libraries = [],
copy_pdb = False,
pdb_name = "",
cmake_files_dir = "$BUILD_TMPDIR/CMakeFiles"):
# On Windows, we don't want to explicitly set CMAKE_BUILD_TYPE,
# rules_foreign_cc will figure it out for us
cache_entries_no_build_type = {key: cache_entries[key] for key in cache_entries.keys() if key != "CMAKE_BUILD_TYPE"}

pf = ""
if copy_pdb:
if pdb_name == "":
pdb_name = name

copy_command = "cp {cmake_files_dir}/{pdb_name}.dir/{pdb_name}.pdb $INSTALLDIR/lib/{pdb_name}.pdb".format(cmake_files_dir = cmake_files_dir, pdb_name = pdb_name)
if postfix_script != "":
copy_command = copy_command + " && " + postfix_script

pf = select({
"@envoy//bazel:windows_dbg_build": copy_command,
"//conditions:default": postfix_script,
})
else:
pf = postfix_script

cmake_external(
name = name,
cache_entries = select({
"@envoy//bazel:windows_x86_64": cache_entries_no_build_type,
"//conditions:default": cache_entries,
}),
cmake_options = cmake_options,
generate_crosstool_file = select({
"@envoy//bazel:windows_x86_64": True,
"//conditions:default": False,
}),
lib_source = lib_source,
make_commands = make_commands,
postfix_script = pf,
static_libraries = static_libraries,
)

# Envoy C++ library targets that need no transformations or additional dependencies before being
# passed to cc_library should be specified with this function. Note: this exists to ensure that
# all envoy targets pass through an envoy-declared skylark function where they can be modified
Expand Down
90 changes: 53 additions & 37 deletions bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
@@ -1,85 +1,101 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_package")
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
load("//bazel:envoy_build_system.bzl", "envoy_cmake_external", "envoy_package")

envoy_package()

cmake_external(
envoy_cmake_external(
name = "ares",
cache_entries = {
"CARES_SHARED": "no",
"CARES_STATIC": "on",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
},
cmake_options = ["-GNinja"],
copy_pdb = True,
lib_source = "@com_github_c_ares_c_ares//:all",
make_commands = [
"ninja",
"ninja install",
],
static_libraries = ["libcares.a"],
pdb_name = "c-ares",
static_libraries = select({
"//bazel:windows_x86_64": ["cares.lib"],
"//conditions:default": ["libcares.a"],
}),
)

cmake_external(
envoy_cmake_external(
name = "benchmark",
cache_entries = {
"BENCHMARK_ENABLE_GTEST_TESTS": "OFF",
"BENCHMARK_ENABLE_TESTING": "OFF",
},
copy_pdb = True,
lib_source = "@com_github_google_benchmark//:all",
postfix_script = "mkdir -p $INSTALLDIR/include/testing/base/public && cp $BUILD_TMPDIR/$INSTALL_PREFIX/include/benchmark/benchmark.h $INSTALLDIR/include/testing/base/public/benchmark.h",
static_libraries = select({
"//bazel:windows_x86_64": ["benchmark.lib"],
"//conditions:default": ["libbenchmark.a"],
}),
)

envoy_cmake_external(
name = "event",
cache_entries = {
"EVENT__DISABLE_OPENSSL": "on",
"EVENT__DISABLE_REGRESS": "on",
"CMAKE_BUILD_TYPE": "Release",
},
cmake_options = ["-GNinja"],
copy_pdb = True,
lib_source = "@com_github_libevent_libevent//:all",
make_commands = [
"ninja",
"ninja install",
],
static_libraries = ["libevent.a"],
static_libraries = select({
"//bazel:windows_x86_64": ["event.lib"],
"//conditions:default": ["libevent.a"],
}),
)

cmake_external(
envoy_cmake_external(
name = "nghttp2",
cache_entries = {
"ENABLE_STATIC_LIB": "on",
"ENABLE_LIB_ONLY": "on",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_INSTALL_LIBDIR": "lib",
},
cmake_options = ["-GNinja"],
cmake_files_dir = "$BUILD_TMPDIR/lib/CMakeFiles",
copy_pdb = True,
lib_source = "@com_github_nghttp2_nghttp2//:all",
make_commands = [
"ninja",
"ninja install",
],
static_libraries = ["libnghttp2.a"],
pdb_name = "nghttp2_static",
static_libraries = select({
"//bazel:windows_x86_64": ["nghttp2_static.lib"],
"//conditions:default": ["libnghttp2_static.a"],
}),
)

cmake_external(
envoy_cmake_external(
name = "yaml",
cache_entries = {
"YAML_CPP_BUILD_TESTS": "off",
"YAML_CPP_BUILD_TOOLS": "off",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
},
cmake_options = ["-GNinja"],
lib_source = "@com_github_jbeder_yaml_cpp//:all",
make_commands = [
"ninja",
"ninja install",
],
static_libraries = ["libyaml-cpp.a"],
static_libraries = select({
"//bazel:windows_dbg_build": ["libyaml-cppmdd.lib"],
"//bazel:windows_fastbuild_build": ["libyaml-cppmd.lib"],
"//bazel:windows_opt_build": ["libyaml-cppmd.lib"],
"//conditions:default": ["libyaml-cpp.a"],
}),
)

cmake_external(
envoy_cmake_external(
name = "zlib",
cache_entries = {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
},
cmake_options = ["-GNinja"],
copy_pdb = True,
lib_source = "@com_github_madler_zlib//:all",
make_commands = [
"ninja",
"ninja install",
],
static_libraries = ["libz.a"],
pdb_name = "zlibstatic",
static_libraries = select({
"//bazel:windows_dbg_build": ["zlibstaticd.lib"],
"//bazel:windows_fastbuild_build": ["zlibstatic.lib"],
"//bazel:windows_opt_build": ["zlibstatic.lib"],
"//conditions:default": ["libz.a"],
}),
)
23 changes: 20 additions & 3 deletions bazel/foreign_cc/nghttp2.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e70d2d49..f9c5340e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -273,7 +273,11 @@ check_type_size("ssize_t" SIZEOF_SSIZE_T)
if(SIZEOF_SSIZE_T STREQUAL "")
# ssize_t is a signed type in POSIX storing at least -1.
# Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools).
- set(ssize_t int)
+ if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(ssize_t int64_t)
+ else()
+ set(ssize_t int)
+ endif()
endif()
# AC_TYPE_UINT8_T
# AC_TYPE_UINT16_T
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 17e422b2..e58070f5 100644
index 17e422b2..a10f82a5 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -52,6 +52,7 @@
@@ -56,6 +56,7 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB)
COMPILE_FLAGS "${WARNCFLAGS}"
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
ARCHIVE_OUTPUT_NAME nghttp2
+ ARCHIVE_OUTPUT_DIRECTORY static
+ ARCHIVE_OUTPUT_NAME nghttp2_static
)
target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB")
if(ENABLE_STATIC_LIB)
4 changes: 0 additions & 4 deletions bazel/repositories.bat

This file was deleted.

24 changes: 5 additions & 19 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ def _repository_impl(name, **kwargs):
)

def _build_recipe_repository_impl(ctxt):
# on Windows, all deps use rules_foreign_cc
if ctxt.os.name.upper().startswith("WINDOWS"):
return

# modify the recipes list based on the build context
recipes = _apply_dep_blacklist(ctxt, ctxt.attr.recipes)

# Setup the build directory with links to the relevant files.
ctxt.symlink(Label("//bazel:repositories.sh"), "repositories.sh")
ctxt.symlink(Label("//bazel:repositories.bat"), "repositories.bat")
ctxt.symlink(
Label("//ci/build_container:build_and_install_deps.sh"),
"build_and_install_deps.sh",
Expand All @@ -71,25 +74,9 @@ def _build_recipe_repository_impl(ctxt):
ctxt.symlink(Label("//ci/prebuilt:BUILD"), "BUILD")

# Run the build script.
command = []
env = {}
if ctxt.os.name.upper().startswith("WINDOWS"):
vc_path = find_vc_path(ctxt)
current_path = get_env_var(ctxt, "PATH", None, False)
env = setup_vc_env_vars(ctxt, vc_path)
env["PATH"] += (";%s" % current_path)
env["CC"] = "cl"
env["CXX"] = "cl"
env["CXXFLAGS"] = "-DNDEBUG"
env["CFLAGS"] = "-DNDEBUG"
command = ["./repositories.bat"] + recipes
else:
command = ["./repositories.sh"] + recipes

print("Fetching external dependencies...")
result = ctxt.execute(
command,
environment = env,
["./repositories.sh"] + recipes,
quiet = False,
)
print(result.stdout)
Expand Down Expand Up @@ -478,7 +465,6 @@ def _com_github_nghttp2_nghttp2():
name = "com_github_nghttp2_nghttp2",
build_file_content = BUILD_ALL_CONTENT,
patch_args = ["-p1"],
patch_cmds = ["find . -name '*.sh' -exec sed -i.orig '1s|#!/usr/bin/env sh\$|/bin/sh\$|' {} +"],
patches = ["@envoy//bazel/foreign_cc:nghttp2.patch"],
**location
)
Expand Down
26 changes: 9 additions & 17 deletions ci/build_container/build_recipes/luajit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -e

VERSION=2.1.0-beta3
SHA256=409f7fe570d3c16558e594421c47bdd130238323c9d6fd6c83dedd2aaeb082a8
if [[ "${OS}" == "Windows_NT" ]]; then
exit 0
fi

curl https://github.com/LuaJIT/LuaJIT/archive/v"$VERSION".tar.gz -sLo LuaJIT-"$VERSION".tar.gz \
&& echo "$SHA256" LuaJIT-"$VERSION".tar.gz | sha256sum --check
Expand Down Expand Up @@ -58,21 +61,10 @@ index f56465d..3f4f2fa 100644
EOF

cd LuaJIT-"$VERSION"
patch -p1 < ../luajit_make.diff

if [[ "${OS}" == "Windows_NT" ]]; then
cd src
./msvcbuild.bat debug

mkdir -p "$THIRDPARTY_BUILD/include/luajit-2.1"
cp *.h* "$THIRDPARTY_BUILD/include/luajit-2.1"
cp luajit.lib "$THIRDPARTY_BUILD/lib"
cp *.pdb "$THIRDPARTY_BUILD/lib"
else
patch -p1 < ../luajit_make.diff

# Default MACOSX_DEPLOYMENT_TARGET is 10.4, which will fail the build at link time on macOS 10.14:
# ld: library not found for -lgcc_s.10.4
# This doesn't affect other platforms
MACOSX_DEPLOYMENT_TARGET=10.6 DEFAULT_CC=${CC} TARGET_CFLAGS=${CFLAGS} TARGET_LDFLAGS=${CFLAGS} \
CFLAGS="" make V=1 PREFIX="$THIRDPARTY_BUILD" install
fi
# Default MACOSX_DEPLOYMENT_TARGET is 10.4, which will fail the build at link time on macOS 10.14:
# ld: library not found for -lgcc_s.10.4
# This doesn't affect other platforms
MACOSX_DEPLOYMENT_TARGET=10.6 DEFAULT_CC=${CC} TARGET_CFLAGS=${CFLAGS} TARGET_LDFLAGS=${CFLAGS} \
CFLAGS="" make V=1 PREFIX="$THIRDPARTY_BUILD" install
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"
Loading

0 comments on commit d558951

Please sign in to comment.