Skip to content
Open
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
9 changes: 9 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ genrule(
stamp = 1,
)

# For Windows, which must list each exported symbol individually.
genrule(
name = "exported_symbols_windows",
srcs = ["//source/extensions/dynamic_modules:abi.h"],
outs = ["exported_symbols_windows.def"],
cmd = "$(location //tools/windows:gen_dynamic_modules_exports) $(location //source/extensions/dynamic_modules:abi.h) $@",
tools = ["//tools/windows:gen_dynamic_modules_exports"],
)

cc_library(
name = "static_stdlib",
linkopts = select({
Expand Down
29 changes: 29 additions & 0 deletions bazel/com_google_protoconverter_win.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel
index 732514d..a6be18b 100644
--- a/build_defs/BUILD.bazel
+++ b/build_defs/BUILD.bazel
@@ -13,10 +13,23 @@ package(
)

create_compiler_config_setting(
- name = "config_msvc",
+ name = "config_msvc_cl",
value = "msvc-cl",
)

+create_compiler_config_setting(
+ name = "config_clang_cl",
+ value = "clang-cl",
+)
+
+selects.config_setting_group(
+ name = "config_msvc",
+ match_any = [
+ ":config_clang_cl",
+ ":config_msvc_cl",
+ ],
+)
+
config_setting(
name = "aarch64",
values = {"cpu": "linux-aarch_64"},
8 changes: 7 additions & 1 deletion bazel/envoy_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ def envoy_exported_symbols_input():
return [
"@envoy//bazel:exported_symbols.txt",
"@envoy//bazel:exported_symbols_apple.txt",
]
] + select({
"@envoy//bazel:windows_x86_64": ["//bazel:exported_symbols_windows.def"],
"//conditions:default": [],
})

# Default symbols to be exported.
def _envoy_default_exported_symbols():
Expand All @@ -240,6 +243,9 @@ def _envoy_default_exported_symbols():
"@envoy//bazel:apple": [
"-Wl,-exported_symbols_list,$(location @envoy//bazel:exported_symbols_apple.txt)",
],
"@envoy//bazel:windows_x86_64": [
"-DEF:$(location //bazel:exported_symbols_windows.def)",
],
"//conditions:default": [],
})

Expand Down
5 changes: 4 additions & 1 deletion bazel/external/zstd.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ cc_library(
"lib/zstd_errors.h",
],
includes = ["lib"],
linkopts = ["-pthread"],
linkopts = select({
"@platforms//os:windows": [],
"//conditions:default": ["-pthread"],
}),
linkstatic = True,
local_defines = [
"XXH_NAMESPACE=ZSTD_",
Expand Down
29 changes: 28 additions & 1 deletion bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ configure_make(
"nocompdb",
"skip_on_windows",
],
target_compatible_with = ["@platforms//os:linux"],
targets = ["install"],
)

Expand Down Expand Up @@ -103,7 +104,10 @@ cc_library(

configure_make(
name = "luajit",
configure_command = "luajit_build.sh",
configure_command = select({
"//bazel:windows_x86_64": "luajit_build_win.sh",
"//conditions:default": "luajit_build.sh",
}),
env = select({
# This shouldn't be needed! See
# https://github.com/envoyproxy/envoy/issues/6084
Expand Down Expand Up @@ -446,6 +450,29 @@ envoy_cmake(
tags = ["skip_on_windows"],
)

configure_make(
name = "dlfcn_win32_build",
configure_in_place = True,
configure_options = [
"--disable-shared",
"--enable-static",
],
lib_source = "@com_github_dlfcn_win32//:all",
out_static_libs = select({
"//bazel:windows_x86_64": ["libdl.a"],
"//conditions:default": [],
}),
target_compatible_with = ["@platforms//os:windows"],
)

cc_library(
name = "dlfcn_win32",
deps = select({
"//bazel:windows_x86_64": [":dlfcn_win32_build"],
"//conditions:default": [],
}),
)

envoy_cmake(
name = "maxmind",
build_args = select({
Expand Down
63 changes: 63 additions & 0 deletions bazel/foreign_cc/luajit_win.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
diff --git a/luajit_build_win.sh b/luajit_build_win.sh
new file mode 100755
index 00000000..c6267893
--- /dev/null
+++ b/luajit_build_win.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+set -e
+
+PREFIX=""
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ --prefix=*)
+ PREFIX="${1#*=}"
+ shift
+ ;;
+ --prefix)
+ PREFIX="$2"
+ shift 2
+ ;;
+ *)
+ shift
+ ;;
+ esac
+done
+
+# Copy source tree to a build directory
+SRC_DIR="$(dirname "$(realpath "$0")")"
+BUILD_DIR="$(basename "$SRC_DIR")"
+cp -r "$SRC_DIR" "$BUILD_DIR"
+cd "$BUILD_DIR"
+
+cd src
+./msvcbuild.bat static
+
+mkdir -p "$PREFIX/lib"
+cp lua51.lib "$PREFIX/lib"
+mkdir -p "$PREFIX/include/luajit-2.1"
+for header in lauxlib.h luaconf.h lua.h lua.hpp luajit.h lualib.h; do
+ cp "$header" "$PREFIX/include/luajit-2.1"
+done
+mkdir -p "$PREFIX/bin"
+cp luajit.exe "$PREFIX/bin"
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index d6aed170..42604601 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -18,9 +18,11 @@
@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_ASSERT
@set DEBUGCFLAGS=
@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
-@set LJDYNBUILD=/DLUA_BUILD_AS_DLL /MD
-@set LJDYNBUILD_DEBUG=/DLUA_BUILD_AS_DLL /MDd
-@set LJCOMPILETARGET=/Zi
+@rem Use MT to match flags set by bazel for static build
+@set LJDYNBUILD=/DLUA_BUILD_AS_DLL /MT
+@set LJDYNBUILD_DEBUG=/DLUA_BUILD_AS_DLL /MTd
+@rem Avoid incremental link which doesn't work with bazel's deletion of intermediate files
+@set LJCOMPILETARGET=/Z7
@set LJLINKTYPE=/DEBUG /RELEASE
@set LJLINKTYPE_DEBUG=/DEBUG
@set LJLINKTARGET=/OPT:REF /OPT:ICF /INCREMENTAL:NO
9 changes: 9 additions & 0 deletions bazel/platforms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,12 @@ platform(
"@platforms//os:macos",
],
)

platform(
name = "x64_windows-clang-cl",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
],
)
54 changes: 37 additions & 17 deletions bazel/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,45 @@ def _envoy_repo_impl(repository_ctx):

"""

# parse container information for use in RBE
json_result = repository_ctx.execute([
repository_ctx.path(repository_ctx.attr.yq),
repository_ctx.path(repository_ctx.attr.envoy_ci_config),
"-ojson",
])
if json_result.return_code != 0:
fail("yq failed: {}".format(json_result.stderr))
repository_ctx.file("ci-config.json", json_result.stdout)
config_data = json.decode(repository_ctx.read("ci-config.json"))
repo = ""
repo_gcr = ""
sha = ""
sha_gcc = ""
sha_mobile = ""
sha_worker = ""
tag = ""

# yq via bazel doesn't work on Windows, but we don't need the real flag_values
# there either. For this and other reasons, ideally we could parse YAML directly.
# https://github.com/bazelbuild/bazel/issues/24766
if repository_ctx.os.name.lower().find("windows") == -1:
json_result = repository_ctx.execute([
repository_ctx.path(repository_ctx.attr.yq),
repository_ctx.path(repository_ctx.attr.envoy_ci_config),
"-ojson",
])
if json_result.return_code != 0:
fail("yq failed: {}".format(json_result.stderr))
repository_ctx.file("ci-config.json", json_result.stdout)
config_data = json.decode(repository_ctx.read("ci-config.json"))
repo = config_data["build-image"]["repo"]
repo_gcr = config_data["build-image"]["repo-gcr"]
sha = config_data["build-image"]["sha"]
sha_gcc = config_data["build-image"]["sha-gcc"]
sha_mobile = config_data["build-image"]["sha-mobile"]
sha_worker = config_data["build-image"]["sha-worker"]
tag = config_data["build-image"]["tag"]

repository_ctx.file("containers.bzl", CONTAINERS.format(
repo = config_data["build-image"]["repo"],
repo_gcr = config_data["build-image"]["repo-gcr"],
sha = config_data["build-image"]["sha"],
sha_gcc = config_data["build-image"]["sha-gcc"],
sha_mobile = config_data["build-image"]["sha-mobile"],
sha_worker = config_data["build-image"]["sha-worker"],
tag = config_data["build-image"]["tag"],
repo = repo,
repo_gcr = repo_gcr,
sha = sha,
sha_gcc = sha_gcc,
sha_mobile = sha_mobile,
sha_worker = sha_worker,
tag = tag,
))

repo_version_path = repository_ctx.path(repository_ctx.attr.envoy_version)
api_version_path = repository_ctx.path(repository_ctx.attr.envoy_api_version)
version = repository_ctx.read(repo_version_path).strip()
Expand Down
19 changes: 17 additions & 2 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ WINDOWS_SKIP_TARGETS = [
"envoy.filters.http.sxg",
"envoy.tracers.dynamic_ot",
"envoy.tracers.datadog",
# Only implemented for Linux.
"envoy.resource_monitors.cpu_utilization",
# Extensions that require CEL.
"envoy.access_loggers.extension_filters.cel",
"envoy.rate_limit_descriptors.expr",
Expand Down Expand Up @@ -81,7 +83,10 @@ def _cc_deps():
external_http_archive(
name = "com_google_protoconverter",
patch_args = ["-p1"],
patches = ["@envoy//bazel:com_google_protoconverter.patch"],
patches = [
"@envoy//bazel:com_google_protoconverter.patch",
"@envoy//bazel:com_google_protoconverter_win.patch",
],
patch_cmds = [
"rm src/google/protobuf/stubs/common.cc",
"rm src/google/protobuf/stubs/common.h",
Expand Down Expand Up @@ -217,6 +222,7 @@ def envoy_dependencies(skip_targets = []):
)
external_http_archive("envoy_toolshed")

_com_github_dlfcn_win32()
_com_github_maxmind_libmaxminddb()

external_http_archive("rules_license")
Expand Down Expand Up @@ -805,7 +811,10 @@ def _com_github_luajit_luajit():
external_http_archive(
name = "com_github_luajit_luajit",
build_file_content = BUILD_ALL_CONTENT,
patches = ["@envoy//bazel/foreign_cc:luajit.patch"],
patches = [
"@envoy//bazel/foreign_cc:luajit.patch",
"@envoy//bazel/foreign_cc:luajit_win.patch",
],
patch_args = ["-p1"],
)

Expand Down Expand Up @@ -923,3 +932,9 @@ def _com_github_maxmind_libmaxminddb():
name = "com_github_maxmind_libmaxminddb",
build_file_content = BUILD_ALL_CONTENT,
)

def _com_github_dlfcn_win32():
external_http_archive(
name = "com_github_dlfcn_win32",
build_file_content = BUILD_ALL_CONTENT,
)
19 changes: 19 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,25 @@ REPOSITORY_LOCATIONS_SPEC = dict(
license = "Apache-2.0",
license_url = "https://github.com/bazelbuild/rules_license/blob/{version}/LICENSE",
),
com_github_dlfcn_win32 = dict(
project_name = "dlfcn-win32",
project_desc = "An implementation of dlfcn for Windows.",
project_url = "https://github.com/dlfcn-win32/dlfcn-win32",
version = "1.4.2",
sha256 = "f61a874bc9163ab488accb364fd681d109870c86e8071f4710cbcdcbaf9f2565",
strip_prefix = "dlfcn-win32-{version}",
urls = ["https://github.com/dlfcn-win32/dlfcn-win32/archive/refs/tags/v{version}.tar.gz"],
use_category = ["dataplane_ext"],
extensions = [
"envoy.filters.http.dynamic_modules",
"envoy.filters.listener.dynamic_modules",
"envoy.filters.network.dynamic_modules",
],
release_date = "2025-03-04",
cpe = "N/A",
license = "MIT",
license_url = "https://github.com/dlfcn-win32/dlfcn-win32/blob/v{version}/COPYING",
),
com_github_maxmind_libmaxminddb = dict(
project_name = "maxmind_libmaxminddb",
project_desc = "C library for reading MaxMind DB files",
Expand Down
11 changes: 11 additions & 0 deletions envoy/api/os_sys_calls.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once

#ifndef _WIN32
#include <sys/resource.h>

#endif
#include <sys/stat.h>

#include <chrono>
Expand All @@ -13,6 +16,14 @@
#include "envoy/common/pure.h"
#include "envoy/network/address.h"

#ifdef _WIN32
struct rlimit {
int rlim_cur;
int rlim_max;
};
#define RLIMIT_NOFILE 7
#endif // _WIN32

namespace Envoy {
namespace Api {

Expand Down
3 changes: 3 additions & 0 deletions envoy/common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ typedef DWORD signal_t; // NOLINT(modernize-use-using)

typedef unsigned int sa_family_t;

#ifndef _STRUCT_IOVEC
// Posix structure for scatter/gather I/O, not present on Windows.
struct iovec {
void* iov_base;
size_t iov_len;
};
#define _STRUCT_IOVEC
#endif // _STRUCT_IOVEC

// Posix structure for describing messages sent by 'sendmsg` and received by
// 'recvmsg'
Expand Down
Loading
Loading