Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: make dynamic modules work on macos #38437

Merged
merged 17 commits into from
Feb 16, 2025
1 change: 1 addition & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports_files([
"test_for_benchmark_wrapper.sh",
"repository_locations.bzl",
"exported_symbols.txt",
"exported_symbols_apple.txt",
])

sh_library(
Expand Down
9 changes: 7 additions & 2 deletions bazel/envoy_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,20 @@ def _envoy_select_perfetto(xs):
})

def envoy_exported_symbols_input():
return ["@envoy//bazel:exported_symbols.txt"]
return [
"@envoy//bazel:exported_symbols.txt",
"@envoy//bazel:exported_symbols_apple.txt",
]

# Default symbols to be exported.
# TODO(wbpcode): make this work correctly for apple/darwin.
def _envoy_default_exported_symbols():
return select({
"@envoy//bazel:linux": [
"-Wl,--dynamic-list=$(location @envoy//bazel:exported_symbols.txt)",
],
"@envoy//bazel:apple": [
"-Wl,-exported_symbols_list,$(location @envoy//bazel:exported_symbols_apple.txt)",
],
"//conditions:default": [],
})

Expand Down
1 change: 1 addition & 0 deletions bazel/exported_symbols.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
lua*;
envoyGo*;
envoy_dynamic_module_callback_*;
};
3 changes: 3 additions & 0 deletions bazel/exported_symbols_apple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_lua*
_envoyGo*
_envoy_dynamic_module_callback_*
1 change: 1 addition & 0 deletions ci/mac_ci_steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DEFAULT_TEST_TARGETS=(
"//test/integration:protocol_integration_test"
"//test/integration:tcp_proxy_integration_test"
"//test/integration:extension_discovery_integration_test"
"//test/extensions/dynamic_modules/http:filter_test"
Copy link
Member Author

Choose a reason for hiding this comment

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

note: this is the minimal test that ensures the dynamic loading/symbol resolution working

"//test/integration:listener_lds_integration_test")

if [[ $# -gt 0 ]]; then
Expand Down
39 changes: 0 additions & 39 deletions source/extensions/dynamic_modules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,6 @@ envoy_cc_library(
"abi.h",
"dynamic_modules.h",
],
linkopts = select({
Copy link
Member Author

Choose a reason for hiding this comment

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

note: we no longer need to manually list callback symbols here!

"//bazel:apple": [],
"//conditions:default": [
# Export callback symbols so that they can be found by the dynamic modules when loaded via dlopen.
#
# Note: with lld, we can use the glob matching to avoid listing all the symbols, but gold and ld are
# not able to do that. So we list all the symbols here.
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_header",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_headers",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_headers_count",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_set_request_header",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_trailer",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_trailers",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_trailers_count",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_set_request_trailer",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_header",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_headers",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_headers_count",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_set_response_header",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_trailer",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_trailers",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_trailers_count",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_set_response_trailer",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_send_response",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_set_dynamic_metadata_number",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_dynamic_metadata_number",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_set_dynamic_metadata_string",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_dynamic_metadata_string",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_body_vector",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_request_body_vector_size",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_append_request_body",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_drain_request_body",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_body_vector",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_get_response_body_vector_size",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_append_response_body",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_drain_response_body",
"-Wl,--export-dynamic-symbol=envoy_dynamic_module_callback_http_clear_route_cache",
],
}),
deps = [
":abi_version_lib",
"//envoy/common:exception_lib",
Expand Down
13 changes: 11 additions & 2 deletions test/extensions/dynamic_modules/test_data/c/test_data.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_shared_library")

# This declares a cc_library target that is used to build a shared library.
# name + ".c" is the source file that is compiled to create the shared library.
def test_program(name):
_name = "_" + name
cc_library(
name = name,
name = _name,
srcs = [name + ".c"],
hdrs = [
"//source/extensions/dynamic_modules:abi.h",
Expand All @@ -18,3 +19,11 @@ def test_program(name):
tags = ["notidy"],
linkstatic = False,
)

# Use cc_shared_library to create a shared library in a consistent naming across
# platforms.
cc_shared_library(
name = name,
shared_lib_name = "lib{}.so".format(name),
deps = [_name],
)
18 changes: 15 additions & 3 deletions test/extensions/dynamic_modules/test_data/rust/test_data.bzl
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_rust//rust:defs.bzl", "rust_clippy", "rust_shared_library", "rust_test", "rustfmt_test")

def test_program(name):
srcs = [name + ".rs"]
if name + "_test.rs" in native.glob(["*.rs"]):
srcs = srcs + [name + "_test.rs"]

_name = "_" + name
rust_shared_library(
name = name,
name = _name,
srcs = srcs,
edition = "2021",
crate_root = name + ".rs",
deps = [
"//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk",
],
rustc_flags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"],
)

# As per the discussion in https://github.com/envoyproxy/envoy/pull/35627,
# we set the rust_fmt and clippy target here instead of the part of //tools/code_format target for now.
rustfmt_test(
name = "fmt_" + name,
tags = ["nocoverage"],
targets = [":" + name],
targets = [":" + _name],
testonly = True,
)
rust_clippy(
name = "clippy_" + name,
tags = ["nocoverage"],
deps = [":" + name],
deps = [":" + _name],
testonly = True,
)

Expand All @@ -50,3 +54,11 @@ def test_program(name):
"nocoverage",
],
)

# Copy the shared library to the expected name especially for MacOS which
# defaults to lib<name>.dylib.
copy_file(
name = name,
src = _name,
out = "lib{}.so".format(name),
)
Loading