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

dynamic_modules: switch to crate_universe to remove manual bindgen #36240

Merged
merged 11 commits into from
Sep 23, 2024
Merged
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
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ envoy_python_dependencies()
load("//bazel:dependency_imports.bzl", "envoy_dependency_imports")

envoy_dependency_imports()

load("//bazel:dependency_imports_extra.bzl", "envoy_dependency_imports_extra")

envoy_dependency_imports_extra()
12 changes: 12 additions & 0 deletions bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains")
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
load("@rules_rust//rust:defs.bzl", "rust_common")
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set")

Expand Down Expand Up @@ -51,6 +53,8 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y
"wasm32-wasi",
],
)
crate_universe_dependencies()
crates_repositories()
shellcheck_dependencies()
proxy_wasm_rust_sdk_dependencies()
rules_fuzzing_dependencies(
Expand Down Expand Up @@ -196,3 +200,11 @@ def envoy_download_go_sdks(go_version):
goarch = "arm64",
version = go_version,
)

def crates_repositories():
crates_repository(
name = "dynamic_modules_rust_sdk_crate_index",
cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock",
lockfile = Label("//source/extensions/dynamic_modules/sdk/rust:Cargo.Bazel.lock"),
manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"],
)
5 changes: 5 additions & 0 deletions bazel/dependency_imports_extra.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "crate_repositories")

# Dependencies that rely on a first stage of envoy_dependency_imports() in dependency_imports.bzl.
def envoy_dependency_imports_extra():
crate_repositories()
8 changes: 5 additions & 3 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1453,9 +1453,11 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_desc = "Bazel rust rules (used by Wasm)",
project_url = "https://github.com/bazelbuild/rules_rust",
version = "0.51.0",
strip_prefix = "rules_rust-{version}",
sha256 = "44ffa703f95fe693c15fefb58432ad009379848d24012338a3c2eb9951b371e7",
urls = ["https://github.com/bazelbuild/rules_rust/archive/{version}.tar.gz"],
sha256 = "042acfb73469b2d1848fe148d81c3422c61ea47a9e1900f1c9ec36f51e8e7193",
# Note: rules_rust should point to the releases, not archive to avoid the hassle of bootstrapping in crate_universe.
# This is described in https://bazelbuild.github.io/rules_rust/crate_universe.html#setup, otherwise bootstrap
# is required which in turn requires a system CC toolchains, not the bazel controlled ones.
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz"],
use_category = [
"controlplane",
"dataplane_core",
Expand Down
4 changes: 0 additions & 4 deletions source/extensions/dynamic_modules/abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
// same version of the ABI.

#ifdef __cplusplus
#include <cstddef>

extern "C" {
#else
#include <stddef.h>
#endif

// -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/dynamic_modules/abi_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace DynamicModules {
#endif
// This is the ABI version calculated as a sha256 hash of the ABI header files. When the ABI
// changes, this value must change, and the correctness of this value is checked by the test.
const char* kAbiVersion = "749b1e6bf97309b7d171009700a80e651ac61e35f9770c24a63460d765895a51";
const char* kAbiVersion = "4293760426255b24c25b97a18d9fd31b4d1956f10ba0ff2f723580a46ee8fa21";

#ifdef __cplusplus
} // namespace DynamicModules
Expand Down
4 changes: 0 additions & 4 deletions source/extensions/dynamic_modules/sdk/README.md

This file was deleted.

19 changes: 19 additions & 0 deletions source/extensions/dynamic_modules/sdk/rust/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "all_crate_deps")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library")
load(
"//bazel:envoy_build_system.bzl",
Expand All @@ -8,8 +10,25 @@ licenses(["notice"]) # Apache 2

envoy_extension_package()

cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
data = [
"//source/extensions/dynamic_modules:abi.h",
"//source/extensions/dynamic_modules:abi_version.h",
],
edition = "2021",
deps = all_crate_deps(
build = True,
normal = True,
),
)

rust_library(
name = "envoy_proxy_dynamic_modules_rust_sdk",
srcs = glob(["src/**/*.rs"]),
edition = "2021",
deps = all_crate_deps(
normal = True,
) + [":build_script"],
)
Loading