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

use bazel build #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 0 additions & 66 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,68 +1,2 @@
licenses(["notice"]) # Apache 2

package(default_visibility = ["//visibility:public"])

cc_library(
name = "api_lib",
hdrs = ["proxy_wasm_api.h"],
)

cc_library(
name = "common_lib",
hdrs = [
"proxy_wasm_common.h",
"proxy_wasm_enums.h",
],
)

cc_library(
name = "proxy_wasm_intrinsics_lite",
srcs = [
"proxy_wasm_intrinsics.cc",
"proxy_wasm_intrinsics_lite.pb.cc",
"struct_lite.pb.cc",
],
hdrs = [
"proxy_wasm_api.h",
"proxy_wasm_common.h",
"proxy_wasm_enums.h",
"proxy_wasm_externs.h",
"proxy_wasm_intrinsics.h",
"proxy_wasm_intrinsics_lite.pb.h",
"struct_lite.pb.h",
],
copts = ["-DPROXY_WASM_PROTOBUF_LITE=1"],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf_lite",
],
)

cc_library(
name = "proxy_wasm_intrinsics",
srcs = [
"proxy_wasm_intrinsics.cc",
"proxy_wasm_intrinsics.pb.cc",
],
hdrs = [
"proxy_wasm_api.h",
"proxy_wasm_common.h",
"proxy_wasm_enums.h",
"proxy_wasm_externs.h",
"proxy_wasm_intrinsics.h",
"proxy_wasm_intrinsics.pb.h",
"struct_lite.pb.h",
],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf",
],
)

filegroup(
name = "jslib",
srcs = [
"proxy_wasm_intrinsics.js",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

18 changes: 18 additions & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("//:bazel/api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
name = "proxy_wasm_intrinsics",
srcs = [
"proxy_wasm_intrinsics.proto",
],
)

api_proto_package(
name = "proxy_wasm_intrinsics_lite",
srcs = [
"proxy_wasm_intrinsics_lite.proto",
"struct_lite.proto",
],
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
syntax = 'proto3';
option optimize_for = LITE_RUNTIME;

import "struct_lite.proto";
import "api/struct_lite.proto";

message WKT {
google.protobuf.Struct struct = 1;
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions bazel/api_build_system.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

_CC_PROTO_SUFFIX = "_cc_proto"
_COMMON_PROTO_DEPS = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:struct_proto",
]

def api_proto_package(
name = "pkg",
srcs = [],
deps = [],
visibility = ["//visibility:public"]):
if srcs == []:
srcs = native.glob(["*.proto"])

proto_library(
name = name,
srcs = srcs,
deps = deps + _COMMON_PROTO_DEPS,
visibility = visibility,
)

relative_name = ":" + name
cc_proto_library_name = name + _CC_PROTO_SUFFIX

cc_proto_library(
name = cc_proto_library_name,
deps = [relative_name],
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions bazel/wasm_build_system.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def wasm_binary(
name = "binary",
out = "",
lite = False,
srcs = []):
if out == "":
out = name + ".wasm"
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions example/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("//:bazel/wasm_build_system.bzl", "wasm_binary")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

wasm_binary(
name = "example_base",
)

wasm_binary(
name = "example_lite",
lite = True,
)
22 changes: 22 additions & 0 deletions example/example.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <string>
#include <unordered_map>

#include "proxy_wasm_intrinsics.h"

class ExampleContext : public Context {
public:
explicit ExampleContext(uint32_t id, RootContext *root) : Context(id, root) {}

FilterHeadersStatus onRequestHeaders(uint32_t headers) override;
void onDone() override;
};
static RegisterContextFactory register_ExampleContext(CONTEXT_FACTORY(ExampleContext));

FilterHeadersStatus ExampleContext::onRequestHeaders(uint32_t headers) {
logInfo(std::string("onRequestHeaders ") + std::to_string(id()));
auto path = getRequestHeader(":path");
logInfo(std::string("header path ") + std::string(path->view()));
return FilterHeadersStatus::Continue;
}

void ExampleContext::onDone() { logInfo("onDone " + std::to_string(id())); }