Skip to content

Commit 5f4384e

Browse files
committed
Merge branch 'main' into emscripten-build-options
Signed-off-by: Michael Warres <[email protected]>
2 parents 20545e5 + 4f53e7a commit 5f4384e

25 files changed

+18033
-17860
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.0
1+
6.5.0

.github/workflows/cpp.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,6 @@ jobs:
6060
export PATH=$PATH:$(go env GOPATH)/bin
6161
addlicense -ignore="**/BUILD" -check .
6262
63-
protobuf:
64-
runs-on: ubuntu-22.04
65-
66-
steps:
67-
- uses: actions/checkout@v2
68-
69-
- name: Install protobuf v3.9.1
70-
run: |
71-
git clone https://github.com/protocolbuffers/protobuf
72-
cd protobuf
73-
git checkout v3.9.1
74-
./autogen.sh
75-
./configure
76-
make
77-
sudo make install
78-
sudo ldconfig
79-
80-
- name: Re-generate and verify protobuf artifacts
81-
run: |
82-
rm *.pb.{cc,h}
83-
make protobuf
84-
git diff --exit-code -G "(^[^ /])|(^\s+[^\*])" *.pb.{cc,h}
85-
8663
build:
8764
runs-on: ubuntu-22.04
8865

Dockerfile-sdk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM ubuntu:noble
22

3-
COPY ./sdk_container.sh /
4-
COPY ./build_wasm.sh /
3+
COPY *.sh /
54
COPY *.cc *.h *.js *.proto Makefile* /sdk/
65

76
RUN ./sdk_container.sh

Makefile

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,57 @@
1-
CPP_API ?= .
1+
ifdef NO_CONTEXT
2+
CPP_CONTEXT_LIB =
3+
else
4+
CPP_CONTEXT_LIB = ${PROXY_WASM_CPP_SDK}/proxy_wasm_intrinsics.cc
5+
endif
26

3-
all: proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h ${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a
7+
PROTOBUF ?= none
8+
ifeq ($(PROTOBUF), full)
9+
PROTO_DEPS := protobuf
10+
PROTO_OPTS := -DPROXY_WASM_PROTOBUF_FULL=1 \
11+
${PROXY_WASM_CPP_SDK}/proxy_wasm_intrinsics.pb.cc
12+
else ifeq ($(PROTOBUF), lite)
13+
PROTO_DEPS := protobuf-lite
14+
PROTO_OPTS := -DPROXY_WASM_PROTOBUF_LITE=1 \
15+
${PROXY_WASM_CPP_SDK}/proxy_wasm_intrinsics_lite.pb.cc \
16+
${PROXY_WASM_CPP_SDK}/struct_lite.pb.cc
17+
else
18+
PROTO_DEPS :=
19+
PROTO_OPTS :=
20+
endif
421

5-
protobuf: proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h
22+
# Provide a list of libraries that the wasm depends on (absl_*, re2, etc).
23+
WASM_DEPS ?=
624

7-
proxy_wasm_intrinsics.pb.h: proxy_wasm_intrinsics.proto
8-
protoc --cpp_out=. proxy_wasm_intrinsics.proto
25+
# Determine dependency link options.
26+
# NOTE: Strip out -pthread which RE2 claims to need...
27+
PKG_CONFIG ?= pkg-config
28+
PKG_CONFIG_PATH = ${EMSDK}/upstream/emscripten/cache/sysroot/lib/pkgconfig
29+
WASM_LIBS = $(shell $(PKG_CONFIG) $(WASM_DEPS) $(PROTO_DEPS) \
30+
--with-path=$(PKG_CONFIG_PATH) --libs | sed -e 's/-pthread //g')
931

10-
proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h: proxy_wasm_intrinsics_lite.proto
11-
protoc --cpp_out=. -I. proxy_wasm_intrinsics_lite.proto
12-
protoc --cpp_out=. struct_lite.proto
32+
debug-deps:
33+
# WASM_DEPS : ${WASM_DEPS}
34+
# WASM_LIBS : ${WASM_LIBS}
35+
# PROTO_DEPS: ${PROTO_DEPS}
36+
# PROTO_OPTS: ${PROTO_OPTS}
1337

14-
${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a:
15-
rm -rf protobuf-wasm \
16-
&& git clone https://github.com/protocolbuffers/protobuf protobuf-wasm \
17-
&& cd protobuf-wasm \
18-
&& git checkout v3.9.1 \
19-
&& ./autogen.sh \
20-
&& emconfigure ./configure --disable-shared CXXFLAGS="-O3 -flto" \
21-
&& emmake make \
22-
&& cd .. \
23-
&& cp protobuf-wasm/src/.libs/libprotobuf-lite.a ${CPP_API}/libprotobuf-lite.a \
24-
&& cp protobuf-wasm/src/.libs/libprotobuf.a ${CPP_API}/libprotobuf.a
38+
# TODO(mpwarres): Add Emscripten stack/heap size params in PR#174.
39+
%.wasm %.wat: %.cc
40+
em++ --no-entry -sSTANDALONE_WASM -sEXPORTED_FUNCTIONS=_malloc \
41+
--std=c++17 -O3 -flto \
42+
--js-library ${PROXY_WASM_CPP_SDK}/proxy_wasm_intrinsics.js \
43+
-I${PROXY_WASM_CPP_SDK} \
44+
${CPP_CONTEXT_LIB} \
45+
${PROTO_OPTS} \
46+
${WASM_LIBS} \
47+
$*.cc -o $*.wasm
2548

2649
clean:
27-
rm -f proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h ${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a
50+
rm *.wasm
51+
52+
# NOTE: How to regenerate .pb.h and .pb.cc files for a protobuf update:
53+
# - download + extract protobuf release (currently v26.1)
54+
# - regenerate:
55+
# ./bin/protoc --cpp_out=../ -I../ -Iinclude/google/protobuf/ ../struct_lite.proto
56+
# ./bin/protoc --cpp_out=../ -I../ -Iinclude/google/protobuf/ ../proxy_wasm_intrinsics_lite.proto
57+
# ./bin/protoc --cpp_out=../ -I../ -Iinclude/google/protobuf/ ../proxy_wasm_intrinsics.proto

Makefile.base

Lines changed: 0 additions & 11 deletions
This file was deleted.

Makefile.base_lite

Lines changed: 0 additions & 11 deletions
This file was deleted.

bazel/defs.bzl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
1616
load("@rules_cc//cc:defs.bzl", "cc_binary")
1717

1818
def _optimized_wasm_cc_binary_transition_impl(settings, attr):
19-
# TODO(PiotrSikora): Add -flto to copts/linkopts when fixed in emsdk.
20-
# See: https://github.com/emscripten-core/emsdk/issues/971
19+
# Define STANDALONE_WASM at compile time as well as link time (below).
20+
# This fixes Abseil by not including Emscripten JS stacktraces + symbolization.
21+
# TODO(martijneken): Remove after Abseil stops using this define.
2122
return {
22-
"//command_line_option:copt": ["-O3"],
23+
"//command_line_option:copt": ["-O3", "-flto", "-DSTANDALONE_WASM"],
2324
"//command_line_option:cxxopt": [],
2425
"//command_line_option:linkopt": [],
2526
"//command_line_option:collect_code_coverage": False,
@@ -117,6 +118,8 @@ def proxy_wasm_cc_binary(
117118
)
118119

119120
wasm_cc_binary(
121+
standalone = True,
122+
threads = "off",
120123
name = "wasm_" + name,
121124
cc_target = ":proxy_wasm_" + name.rstrip(".wasm"),
122125
tags = tags + [

bazel/dependencies.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
1616
load("@emsdk//:deps.bzl", emsdk_deps = "deps")
17+
load("@rules_python//python:repositories.bzl", "py_repositories")
1718

1819
# Requires proxy_wasm_cpp_sdk_repositories() to be loaded first.
1920
def proxy_wasm_cpp_sdk_dependencies():
21+
py_repositories()
2022
protobuf_deps()
2123
emsdk_deps()

bazel/repositories.bzl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,35 @@ def proxy_wasm_cpp_sdk_repositories():
2424
url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.67.tar.gz",
2525
)
2626

27+
# protobuf depends on rules_python py_repositories
28+
maybe(
29+
http_archive,
30+
name = "rules_python",
31+
sha256 = "778aaeab3e6cfd56d681c89f5c10d7ad6bf8d2f1a72de9de55b23081b2d31618",
32+
strip_prefix = "rules_python-0.34.0",
33+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.34.0/rules_python-0.34.0.tar.gz",
34+
)
35+
2736
maybe(
2837
http_archive,
2938
name = "com_google_protobuf",
30-
sha256 = "77ad26d3f65222fd96ccc18b055632b0bfedf295cb748b712a98ba1ac0b704b2",
31-
strip_prefix = "protobuf-3.17.3",
32-
url = "https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-all-3.17.3.tar.gz",
39+
sha256 = "4fc5ff1b2c339fb86cd3a25f0b5311478ab081e65ad258c6789359cd84d421f8",
40+
strip_prefix = "protobuf-26.1",
41+
url = "https://github.com/protocolbuffers/protobuf/releases/download/v26.1/protobuf-26.1.tar.gz",
42+
)
43+
44+
maybe(
45+
http_archive,
46+
name = "com_google_absl",
47+
sha256 = "95e90be7c3643e658670e0dd3c1b27092349c34b632c6e795686355f67eca89f",
48+
strip_prefix = "abseil-cpp-20240722.0",
49+
urls = ["https://github.com/abseil/abseil-cpp/archive/20240722.0.zip"],
50+
)
51+
52+
maybe(
53+
http_archive,
54+
name = "com_google_re2",
55+
sha256 = "18cf85922e27fad3ed9c96a27733037da445f35eb1a2744c306a37c6d11e95c4",
56+
strip_prefix = "re2-2023-07-01",
57+
url = "https://github.com/google/re2/archive/2023-07-01.tar.gz",
3358
)

build_wasm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
source /root/emsdk/emsdk_env.sh
1818
export PATH=/usr/local/bin:$PATH
19-
make
19+
make "$@"

0 commit comments

Comments
 (0)