diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..233563e --- /dev/null +++ b/.bazelrc @@ -0,0 +1,9 @@ +# NOTE: incompatible_enable_cc_toolchain_resolution is set by default on Bazel +# versions 7.0+, see https://github.com/bazelbuild/bazel/issues/7260. +# +# emsdk documentation asks to set this flag (see +# https://github.com/emscripten-core/emsdk/blob/main/bazel/README.md). And even +# though things seem to work even without this flag, given that this flag +# enables improved Bazel C++ toolchain resolution method that became the +# default in newer Bazel version and does not cause problems, we keep it. +build --incompatible_enable_cc_toolchain_resolution diff --git a/Dockerfile-sdk b/Dockerfile-sdk index 3dc28c1..ff77ed3 100644 --- a/Dockerfile-sdk +++ b/Dockerfile-sdk @@ -1,7 +1,7 @@ -FROM ubuntu:bionic +FROM ubuntu:noble COPY ./sdk_container.sh / COPY ./build_wasm.sh / -COPY *.cc *.h *.js *.proto Makefile* *.a /sdk/ +COPY *.cc *.h *.js *.proto Makefile* /sdk/ RUN ./sdk_container.sh diff --git a/Makefile b/Makefile index 550a4c2..93c2d76 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,10 @@ proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h: proxy_wasm_intrinsics_lite.pro protoc --cpp_out=. struct_lite.proto ${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a: - rm -rf protobuf-wasm && git clone https://github.com/protocolbuffers/protobuf protobuf-wasm \ - && cd protobuf-wasm && git checkout v3.9.1 \ - && rm -rf wasm-patches && git clone https://github.com/kwonoj/protobuf-wasm wasm-patches \ - && cd wasm-patches && git checkout 4bba8b2f38b5004f87489642b6ca4525ae72fe7f \ - && cd .. && git apply wasm-patches/*.patch \ + rm -rf protobuf-wasm \ + && git clone https://github.com/protocolbuffers/protobuf protobuf-wasm \ + && cd protobuf-wasm \ + && git checkout v3.9.1 \ && ./autogen.sh \ && emconfigure ./configure --disable-shared CXXFLAGS="-O3 -flto" \ && emmake make \ diff --git a/bazel/dependencies_extra.bzl b/bazel/dependencies_extra.bzl index 7bfa2e4..48622e3 100644 --- a/bazel/dependencies_extra.bzl +++ b/bazel/dependencies_extra.bzl @@ -13,7 +13,9 @@ # limitations under the License. load("@emsdk//:emscripten_deps.bzl", "emscripten_deps") +load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains") # Requires proxy_wasm_cpp_sdk_dependencies() to be loaded first. def proxy_wasm_cpp_sdk_dependencies_extra(): emscripten_deps() + register_emscripten_toolchains() diff --git a/bazel/emsdk.patch b/bazel/emsdk.patch deleted file mode 100644 index 21ee899..0000000 --- a/bazel/emsdk.patch +++ /dev/null @@ -1,48 +0,0 @@ -diff --git a/bazel/emscripten_deps.bzl b/bazel/emscripten_deps.bzl -index 95801ba..95fdabd 100644 ---- a/bazel/emscripten_deps.bzl -+++ b/bazel/emscripten_deps.bzl -@@ -69,31 +69,3 @@ def emscripten_deps(emscripten_version = "latest"): - build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD", - type = "zip", - ) -- -- if "emscripten_npm_linux" not in excludes: -- npm_install( -- name = "emscripten_npm_linux", -- package_json = "@emscripten_bin_linux//:emscripten/package.json", -- package_lock_json = "@emscripten_bin_linux//:emscripten/package-lock.json", -- ) -- -- if "emscripten_npm_mac" not in excludes: -- npm_install( -- name = "emscripten_npm_mac", -- package_json = "@emscripten_bin_mac//:emscripten/package.json", -- package_lock_json = "@emscripten_bin_mac//:emscripten/package-lock.json", -- ) -- -- if "emscripten_npm_mac_arm64" not in excludes: -- npm_install( -- name = "emscripten_npm_mac", -- package_json = "@emscripten_bin_mac_arm64//:emscripten/package.json", -- package_lock_json = "@emscripten_bin_mac_arm64//:emscripten/package-lock.json", -- ) -- -- if "emscripten_npm_win" not in excludes: -- npm_install( -- name = "emscripten_npm_win", -- package_json = "@emscripten_bin_win//:emscripten/package.json", -- package_lock_json = "@emscripten_bin_win//:emscripten/package-lock.json", -- ) -diff --git a/bazel/emscripten_toolchain/BUILD.bazel b/bazel/emscripten_toolchain/BUILD.bazel -index eb36959..12dba37 100644 ---- a/bazel/emscripten_toolchain/BUILD.bazel -+++ b/bazel/emscripten_toolchain/BUILD.bazel -@@ -13,7 +13,6 @@ filegroup( - "env.sh", - "env.bat", - "@emsdk//:binaries", -- "@emsdk//:node_modules", - "@nodejs//:node_files", - ], - ) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 59ec24b..7ca6517 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -19,12 +19,9 @@ def proxy_wasm_cpp_sdk_repositories(): maybe( http_archive, name = "emsdk", - sha256 = "1ca0ff918d476c55707bb99bc0452be28ac5fb8f22a9260a8aae8a38d1bc0e27", - # v3.1.7 with Bazel fixes - strip_prefix = "emsdk-0ea8f8a8707070e9a7c83fbb4a3065683bcf1799/bazel", - url = "https://github.com/emscripten-core/emsdk/archive/0ea8f8a8707070e9a7c83fbb4a3065683bcf1799.tar.gz", - patches = ["@proxy_wasm_cpp_sdk//bazel:emsdk.patch"], - patch_args = ["-p2"], + sha256 = "0cb0eabd6e3ceb1a970a2363e67f2b1689c2d83fbeae1e75901213c1f84de2e2", + strip_prefix = "emsdk-3.1.67/bazel", + url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.67.tar.gz", ) maybe( diff --git a/docs/building.md b/docs/building.md index 76f8ec2..50472f7 100644 --- a/docs/building.md +++ b/docs/building.md @@ -163,9 +163,10 @@ sudo make install ```bash git clone https://github.com/emscripten-core/emsdk.git cd emsdk -./emsdk update-tags -./emsdk install 3.1.7 -./emsdk activate 3.1.7 +git checkout 3.1.67 + +./emsdk install 3.1.67 +./emsdk activate 3.1.67 source ./emsdk_env.sh ``` @@ -178,21 +179,19 @@ It is possible later versions will work, e.g. ./emsdk activate latest ``` -However 3.1.7 is known to work. +However 3.1.67 is known to work. ### Rebuilding the libprotobuf.a files -If want to rebuild the libprotobuf.a files using a version of protobuf prior to -3.15, see the instructions at https://github.com/kwonoj/protobuf-wasm. Commit -4bba8b2f38b5004f87489642b6ca4525ae72fe7f works for protobuf v3.9.x. +To build the protobuf static libraries for use in your proxy-wasm wasm module, +if you need them, you may use Emscripten in the same way sdk\_container.sh does +it: ```bash git clone https://github.com/protocolbuffers/protobuf protobuf-wasm cd protobuf-wasm git checkout v3.9.1 -git clone https://github.com/kwonoj/protobuf-wasm wasm-patches -cd wasm-patches && git checkout 4bba8b2f38b5004f87489642b6ca4525ae72fe7f && cd .. -git apply wasm-patches/*.patch +git submodule update --init --recursive ./autogen.sh emconfigure ./configure --disable-shared CXXFLAGS="-O3 -flto" emmake make diff --git a/libprotobuf-lite.a b/libprotobuf-lite.a deleted file mode 100644 index 30a3604..0000000 Binary files a/libprotobuf-lite.a and /dev/null differ diff --git a/libprotobuf.a b/libprotobuf.a deleted file mode 100644 index e8652eb..0000000 Binary files a/libprotobuf.a and /dev/null differ diff --git a/sdk_container.sh b/sdk_container.sh index c3de25b..2b4885f 100755 --- a/sdk_container.sh +++ b/sdk_container.sh @@ -20,16 +20,20 @@ set -e export DEBIAN_FRONTEND=noninteractive apt-get update apt-get upgrade -y -apt-get install -y --no-install-recommends apt-utils ca-certificates apt-get autoremove -y apt-get clean -apt-get install -y --no-install-recommends software-properties-common apt-transport-https git wget curl pkg-config autoconf autotools-dev automake libtool cmake python zlib1g-dev +apt-get install -y --no-install-recommends ca-certificates git autoconf autotools-dev automake libtool cmake python-is-python3 zlib1g-dev make xz-utils libzstd-dev -# gcc-7 -apt-get install -y --no-install-recommends gcc-7 g++-7 cpp-7 -export CC=gcc-7 -export CXX=g++-7 -export CPP=cpp-7 +# The specific version of GCC does not actually matter as long as it's confirmed to work. +# That's why we explicitly pin gcc version (in this case to gcc 13) - it's the version +# which was tested to work. +apt-get install -y --no-install-recommends gcc-13 g++-13 cpp-13 +export CC=gcc-13 +export CXX=g++-13 +export CPP=cpp-13 + +NUM_CPUS=$(nproc) +JOBS=$((NUM_CPUS>1 ? NUM_CPUS-1 : NUM_CPUS)) # get $HOME cd @@ -41,36 +45,43 @@ git checkout v3.9.1 git submodule update --init --recursive ./autogen.sh ./configure -make +make -j $JOBS make check make install cd rm -rf protobuf +# This makes sure that installed dynamic libraries are visible to the dynamic +# linker, because it seems like make install does not take care of that +ldconfig + # emscripten git clone https://github.com/emscripten-core/emsdk.git cd emsdk -./emsdk update-tags -./emsdk install 3.1.7 -./emsdk activate 3.1.7 +git checkout 3.1.67 +./emsdk install --shallow 3.1.67 +./emsdk activate 3.1.67 source ./emsdk_env.sh cd +git clone https://github.com/protocolbuffers/protobuf protobuf-wasm +cd protobuf-wasm +git checkout v3.9.1 +git submodule update --init --recursive +./autogen.sh +emconfigure ./configure --disable-shared CXXFLAGS="-O3 -flto" +emmake make -j $JOBS +cd + +cp protobuf-wasm/src/.libs/libprotobuf-lite.a /sdk/libprotobuf-lite.a +cp protobuf-wasm/src/.libs/libprotobuf.a /sdk/libprotobuf.a +rm -rf protobuf-wasm + # abseil (optional) git clone https://github.com/abseil/abseil-cpp cd abseil-cpp -git checkout 14550beb3b7b97195e483fb74b5efb906395c31e -b Jul302019 # Jul 30 2019 +git checkout 4447c7562e3bc702ade25105912dce503f0c4010 -b lts20240722 # Abseil LTS release 20240722.0 emcmake cmake -DCMAKE_CXX_STANDARD=17 "." -emmake make +emmake make -j $JOBS cd -# WAVM (optional) -apt-get install -y --no-install-recommends llvm-6.0-dev -git clone https://github.com/WAVM/WAVM -cd WAVM -git checkout 1ec06cd202a922015c9041c5ed84f875453c4dc7 -b Oct152019 # Oct 15 2019 -cmake "." -make -make install -cd -rm -rf WAVM