Skip to content

Commit 080845b

Browse files
committed
Fix Envoy build on Windows
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent 9b74448 commit 080845b

34 files changed

Lines changed: 415 additions & 77 deletions

bazel/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ genrule(
6868
stamp = 1,
6969
)
7070

71+
# For Windows, which must list each exported symbol individually.
72+
genrule(
73+
name = "exported_symbols_windows",
74+
srcs = ["//source/extensions/dynamic_modules:abi.h"],
75+
outs = ["exported_symbols_windows.def"],
76+
cmd = "$(location //tools:gen_dynamic_modules_windows_exports) $(location //source/extensions/dynamic_modules:abi.h) $@",
77+
tools = ["//tools:gen_dynamic_modules_windows_exports"],
78+
)
79+
7180
cc_library(
7281
name = "static_stdlib",
7382
linkopts = select({

bazel/com_google_protoconverter.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel
2+
index 732514d..e8e451e 100644
3+
--- a/build_defs/BUILD.bazel
4+
+++ b/build_defs/BUILD.bazel
5+
@@ -14,7 +14,7 @@ package(
6+
7+
create_compiler_config_setting(
8+
name = "config_msvc",
9+
- value = "msvc-cl",
10+
+ values = ["msvc-cl", "clang-cl"],
11+
)
12+
13+
config_setting(
14+
diff --git a/build_defs/compiler_config_setting.bzl b/build_defs/compiler_config_setting.bzl
15+
index 0aca1ad..1457298 100644
16+
--- a/build_defs/compiler_config_setting.bzl
17+
+++ b/build_defs/compiler_config_setting.bzl
18+
@@ -14,7 +14,7 @@
19+
20+
"""Creates config_setting that allows selecting based on 'compiler' value."""
21+
22+
-def create_compiler_config_setting(name, value, visibility = None):
23+
+def create_compiler_config_setting(name, values, visibility = None):
24+
# The "do_not_use_tools_cpp_compiler_present" attribute exists to
25+
# distinguish between older versions of Bazel that do not support
26+
# "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
27+
@@ -24,14 +24,12 @@ def create_compiler_config_setting(name, value, visibility = None):
28+
if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"):
29+
native.config_setting(
30+
name = name,
31+
- flag_values = {
32+
- "@bazel_tools//tools/cpp:compiler": value,
33+
- },
34+
+ flag_values = {"@bazel_tools//tools/cpp:compiler": v for v in values},
35+
visibility = visibility,
36+
)
37+
else:
38+
native.config_setting(
39+
name = name,
40+
- values = {"compiler": value},
41+
+ values = {"compiler": v for v in values},
42+
visibility = visibility,
43+
)
144
diff --git a/src/google/protobuf/stubs/BUILD.bazel b/src/google/protobuf/stubs/BUILD.bazel
245
index a7b8c82..4f66827 100644
346
--- a/src/google/protobuf/stubs/BUILD.bazel

bazel/envoy_internal.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ def envoy_exported_symbols_input():
229229
return [
230230
"@envoy//bazel:exported_symbols.txt",
231231
"@envoy//bazel:exported_symbols_apple.txt",
232-
]
232+
] + select({
233+
"@envoy//bazel:windows_x86_64": ["//bazel:exported_symbols_windows.def"],
234+
"//conditions:default": [],
235+
})
233236

234237
# Default symbols to be exported.
235238
def _envoy_default_exported_symbols():
@@ -240,6 +243,9 @@ def _envoy_default_exported_symbols():
240243
"@envoy//bazel:apple": [
241244
"-Wl,-exported_symbols_list,$(location @envoy//bazel:exported_symbols_apple.txt)",
242245
],
246+
"@envoy//bazel:windows_x86_64": [
247+
"-DEF:$(location //bazel:exported_symbols_windows.def)",
248+
],
243249
"//conditions:default": [],
244250
})
245251

bazel/external/zstd.BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ cc_library(
5454
"lib/zstd_errors.h",
5555
],
5656
includes = ["lib"],
57-
linkopts = ["-pthread"],
57+
linkopts = select({
58+
"@platforms//os:windows": [],
59+
"//conditions:default": ["-pthread"],
60+
}),
5861
linkstatic = True,
5962
local_defines = [
6063
"XXH_NAMESPACE=ZSTD_",

bazel/foreign_cc/BUILD

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ cc_library(
103103

104104
configure_make(
105105
name = "luajit",
106-
configure_command = "luajit_build.sh",
106+
configure_command = select({
107+
"//bazel:windows_x86_64": "luajit_build_win.sh",
108+
"//conditions:default": "luajit_build.sh",
109+
}),
107110
env = select({
108111
# This shouldn't be needed! See
109112
# https://github.com/envoyproxy/envoy/issues/6084
@@ -446,6 +449,28 @@ envoy_cmake(
446449
tags = ["skip_on_windows"],
447450
)
448451

452+
configure_make(
453+
name = "dlfcn_win32_build",
454+
configure_in_place = True,
455+
configure_options = [
456+
"--disable-shared",
457+
"--enable-static",
458+
],
459+
lib_source = "@com_github_dlfcn_win32//:all",
460+
out_static_libs = select({
461+
"//bazel:windows_x86_64": ["libdl.a"],
462+
"//conditions:default": [],
463+
}),
464+
)
465+
466+
cc_library(
467+
name = "dlfcn_win32",
468+
deps = select({
469+
"//bazel:windows_x86_64": [":dlfcn_win32_build"],
470+
"//conditions:default": [],
471+
}),
472+
)
473+
449474
envoy_cmake(
450475
name = "maxmind",
451476
build_args = select({

bazel/foreign_cc/cel-cpp.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
diff --git a/bazel/cel_proto_transitive_descriptor_set.bzl b/bazel/cel_proto_transitive_descriptor_set.bzl
2+
index e65e0b4a..0e143480 100644
3+
--- a/bazel/cel_proto_transitive_descriptor_set.bzl
4+
+++ b/bazel/cel_proto_transitive_descriptor_set.bzl
5+
@@ -21,15 +21,33 @@ load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
6+
def _cel_proto_transitive_descriptor_set(ctx):
7+
output = ctx.actions.declare_file(ctx.attr.name + ".binarypb")
8+
transitive_descriptor_sets = depset(transitive = [dep[ProtoInfo].transitive_descriptor_sets for dep in ctx.attr.deps])
9+
- args = ctx.actions.args()
10+
- args.use_param_file(param_file_arg = "%s", use_always = True)
11+
- args.add_all(transitive_descriptor_sets)
12+
+
13+
+ # Generate script to concatenate files listed in a parameter file into an output file.
14+
+ script = """
15+
+set -euo pipefail
16+
+PARAMS_FILE="$1"
17+
+OUTPUT_FILE="$2"
18+
+if [ ! -f "$PARAMS_FILE" ]; then
19+
+ echo "Error: Parameter file not found at $PARAMS_FILE" >&2
20+
+ exit 1
21+
+fi
22+
+exec > "$OUTPUT_FILE"
23+
+while IFS= read -r file_to_cat || [[ -n "$file_to_cat" ]]; do
24+
+ if [ -f "$file_to_cat" ]; then
25+
+ cat "$file_to_cat"
26+
+ fi
27+
+done < "$PARAMS_FILE"
28+
+"""
29+
+
30+
+ param_file_args = ctx.actions.args()
31+
+ param_file_args.use_param_file(param_file_arg = "%s", use_always = True)
32+
+ param_file_args.add_all(transitive_descriptor_sets)
33+
ctx.actions.run_shell(
34+
outputs = [output],
35+
inputs = transitive_descriptor_sets,
36+
progress_message = "Joining descriptors.",
37+
- command = ("< \"$1\" xargs cat >{output}".format(output = output.path)),
38+
- arguments = [args],
39+
+ command=script,
40+
+ arguments=[param_file_args, output.path],
41+
)
42+
return DefaultInfo(
43+
files = depset([output]),
144
diff --git a/common/internal/byte_string.cc b/common/internal/byte_string.cc
245
index b9f47922..9d096424 100644
346
--- a/common/internal/byte_string.cc

bazel/foreign_cc/luajit.patch

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ index c83abfa0..0276f9e3 100644
5353
##############################################################################
5454
diff --git a/luajit_build.sh b/luajit_build.sh
5555
new file mode 100755
56-
index 00000000..3b4f8eca
56+
index 00000000..8dca96e6
5757
--- /dev/null
5858
+++ b/luajit_build.sh
5959
@@ -0,0 +1,68 @@
@@ -125,3 +125,65 @@ index 00000000..3b4f8eca
125125
+"${MAKE:-make}" -j$(nproc) V=1 PREFIX="$PREFIX" \
126126
+ "${EXTRA_MAKE_ARGS[@]}" \
127127
+ install
128+
diff --git a/luajit_build_win.sh b/luajit_build_win.sh
129+
new file mode 100755
130+
index 00000000..8fb0fbe8
131+
--- /dev/null
132+
+++ b/luajit_build_win.sh
133+
@@ -0,0 +1,39 @@
134+
+#!/bin/bash
135+
+
136+
+set -e
137+
+
138+
+PREFIX=""
139+
+while [[ $# -gt 0 ]]; do
140+
+ case $1 in
141+
+ --prefix=*)
142+
+ PREFIX="${1#*=}"
143+
+ shift
144+
+ ;;
145+
+ --prefix)
146+
+ PREFIX="$2"
147+
+ shift 2
148+
+ ;;
149+
+ *)
150+
+ shift
151+
+ ;;
152+
+ esac
153+
+done
154+
+
155+
+# Copy source tree to a build directory
156+
+SRC_DIR="$(dirname "$(realpath "$0")")"
157+
+BUILD_DIR="$(basename "$SRC_DIR")"
158+
+cp -r "$SRC_DIR" "$BUILD_DIR"
159+
+cd "$BUILD_DIR"
160+
+
161+
+ ls
162+
+ cd src
163+
+./msvcbuild.bat static
164+
+
165+
+mkdir -p "$PREFIX/lib"
166+
+cp lua51.lib "$PREFIX/lib"
167+
+mkdir -p "$PREFIX/include/luajit-2.1"
168+
+for header in lauxlib.h luaconf.h lua.h lua.hpp luajit.h lualib.h; do
169+
+ cp "$header" "$PREFIX/include/luajit-2.1"
170+
+done
171+
+mkdir -p "$PREFIX/bin"
172+
+cp luajit.exe "$PREFIX/bin"
173+
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
174+
index d6aed170..8a86b766 100644
175+
--- a/src/msvcbuild.bat
176+
+++ b/src/msvcbuild.bat
177+
@@ -18,9 +18,9 @@
178+
@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_ASSERT
179+
@set DEBUGCFLAGS=
180+
@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
181+
-@set LJDYNBUILD=/DLUA_BUILD_AS_DLL /MD
182+
-@set LJDYNBUILD_DEBUG=/DLUA_BUILD_AS_DLL /MDd
183+
-@set LJCOMPILETARGET=/Zi
184+
+@set LJDYNBUILD=/DLUA_BUILD_AS_DLL /MT
185+
+@set LJDYNBUILD_DEBUG=/DLUA_BUILD_AS_DLL /MTd
186+
+@set LJCOMPILETARGET=/Z7
187+
@set LJLINKTYPE=/DEBUG /RELEASE
188+
@set LJLINKTYPE_DEBUG=/DEBUG
189+
@set LJLINKTARGET=/OPT:REF /OPT:ICF /INCREMENTAL:NO

bazel/platforms/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ platform(
111111
"@platforms//os:macos",
112112
],
113113
)
114+
115+
platform(
116+
name = "x64_windows-clang-cl",
117+
constraint_values = [
118+
"@platforms//cpu:x86_64",
119+
"@platforms//os:windows",
120+
"@bazel_tools//tools/cpp:clang-cl",
121+
],
122+
)

bazel/repo.bzl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,36 @@ def _envoy_repo_impl(repository_ctx):
6565
6666
"""
6767

68-
# parse container information for use in RBE
69-
json_result = repository_ctx.execute([
70-
repository_ctx.path(repository_ctx.attr.yq),
71-
repository_ctx.path(repository_ctx.attr.envoy_ci_config),
72-
"-ojson",
73-
])
74-
if json_result.return_code != 0:
75-
fail("yq failed: {}".format(json_result.stderr))
76-
repository_ctx.file("ci-config.json", json_result.stdout)
77-
config_data = json.decode(repository_ctx.read("ci-config.json"))
78-
repository_ctx.file("containers.bzl", CONTAINERS.format(
79-
repo = config_data["build-image"]["repo"],
80-
repo_gcr = config_data["build-image"]["repo-gcr"],
81-
sha = config_data["build-image"]["sha"],
82-
sha_gcc = config_data["build-image"]["sha-gcc"],
83-
sha_mobile = config_data["build-image"]["sha-mobile"],
84-
sha_worker = config_data["build-image"]["sha-worker"],
85-
tag = config_data["build-image"]["tag"],
86-
))
68+
if repository_ctx.os.name.lower().find("windows") == -1:
69+
json_result = repository_ctx.execute([
70+
repository_ctx.path(repository_ctx.attr.yq),
71+
repository_ctx.path(repository_ctx.attr.envoy_ci_config),
72+
"-ojson",
73+
])
74+
if json_result.return_code != 0:
75+
fail("yq failed: {}".format(json_result.stderr))
76+
repository_ctx.file("ci-config.json", json_result.stdout)
77+
config_data = json.decode(repository_ctx.read("ci-config.json"))
78+
repository_ctx.file("containers.bzl", CONTAINERS.format(
79+
repo = config_data["build-image"]["repo"],
80+
repo_gcr = config_data["build-image"]["repo-gcr"],
81+
sha = config_data["build-image"]["sha"],
82+
sha_gcc = config_data["build-image"]["sha-gcc"],
83+
sha_mobile = config_data["build-image"]["sha-mobile"],
84+
sha_worker = config_data["build-image"]["sha-worker"],
85+
tag = config_data["build-image"]["tag"],
86+
))
87+
else:
88+
# yq via bazel doesn't work on Windows, but we don't need the file either
89+
repository_ctx.file("containers.bzl", CONTAINERS.format(
90+
repo = "",
91+
repo_gcr = "",
92+
sha = "",
93+
sha_gcc = "",
94+
sha_mobile = "",
95+
sha_worker = "",
96+
tag = "",
97+
))
8798
repo_version_path = repository_ctx.path(repository_ctx.attr.envoy_version)
8899
api_version_path = repository_ctx.path(repository_ctx.attr.envoy_api_version)
89100
version = repository_ctx.read(repo_version_path).strip()

bazel/repositories.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ WINDOWS_SKIP_TARGETS = [
1313
"envoy.filters.http.sxg",
1414
"envoy.tracers.dynamic_ot",
1515
"envoy.tracers.datadog",
16+
# Only implemented for Linux.
17+
"envoy.resource_monitors.cpu_utilization",
1618
# Extensions that require CEL.
1719
"envoy.access_loggers.extension_filters.cel",
1820
"envoy.rate_limit_descriptors.expr",
@@ -215,6 +217,7 @@ def envoy_dependencies(skip_targets = []):
215217
external_http_archive("envoy_examples")
216218
external_http_archive("envoy_toolshed")
217219

220+
_com_github_dlfcn_win32()
218221
_com_github_maxmind_libmaxminddb()
219222

220223
external_http_archive("rules_license")
@@ -918,3 +921,9 @@ def _com_github_maxmind_libmaxminddb():
918921
name = "com_github_maxmind_libmaxminddb",
919922
build_file_content = BUILD_ALL_CONTENT,
920923
)
924+
925+
def _com_github_dlfcn_win32():
926+
external_http_archive(
927+
name = "com_github_dlfcn_win32",
928+
build_file_content = BUILD_ALL_CONTENT,
929+
)

0 commit comments

Comments
 (0)