Skip to content

wasmtime: update to v0.32.0 #205

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

Merged
merged 10 commits into from
Jan 2, 2022
Merged

Conversation

kfaseela
Copy link
Contributor

attempting to update wasmtime in Envoy main

Signed-off-by: Faseela K [email protected]

@kfaseela
Copy link
Contributor Author

cc @phlax

@kfaseela
Copy link
Contributor Author

@PiotrSikora : Any idea how to fix the current build error?

ERROR: /home/runner/.cache/bazel/_bazel_runner/ae21fb6b2e26a9267f16b46bb90ea321/external/proxy_wasm_cpp_host__cpufeatures__0_2_1/BUILD.bazel:33:13: Label '@proxy_wasm_cpp_host__libc__0_2_112//:libc' is duplicated in the 'deps' attribute of rule 'cpufeatures'

how do i fix this duplicate?
https://github.com/proxy-wasm/proxy-wasm-cpp-host/pull/205/files#diff-1f31b98481a005cda423a6abf0bf64bcbe3bac116b937a92451df216b02e1f7aR67

@PiotrSikora
Copy link
Member

@kfaseela thanks for working on this! Unfortunately, you need to fix bazel/cargo/remote/BUILD.errno-0.2.8.bazel file manually (just undo the selects change), see comments in #196.

@PiotrSikora
Copy link
Member

@kfaseela oops, it looks that you need to manually collapse them in bazel/cargo/remote/BUILD.cpufeatures-0.2.1.bazel as well, and exclude that file from format check in .github/workflows/cargo.yml.

Signed-off-by: Faseela K <[email protected]>
@PiotrSikora
Copy link
Member

This is a bit more complex than a simple update, but we're getting close. You need to:

  1. Add this to bazel/cargo/Cargo.toml:
[package.metadata.raze.crates.rustix.'*'.buildrs_additional_environment_variables]
CARGO_CFG_RUSTIX_USE_LIBC="1"
  1. Regenerate everything using cargo raze --generate-lockfile (it looks that some crates are outdated in current PR).
  2. Update bazel/cargo/remote/BUILD.rustix-0.26.2.bazel so that the first select is merged into the second one, so that all targets depend on libc and errno, and not on linux_raw_sys.
  3. Exclude bazel/cargo/remote/BUILD.rustix-0.26.2.bazel from format check.

@kfaseela
Copy link
Contributor Author

This is a bit more complex than a simple update, but we're getting close. You need to:

  1. Add this to bazel/cargo/Cargo.toml:
[package.metadata.raze.crates.rustix.'*'.buildrs_additional_environment_variables]
CARGO_CFG_RUSTIX_USE_LIBC="1"
  1. Regenerate everything using cargo raze --generate-lockfile (it looks that some crates are outdated in current PR).
  2. Update bazel/cargo/remote/BUILD.rustix-0.26.2.bazel so that the first select is merged into the second one, so that all targets depend on libc and errno, and not on linux_raw_sys.
  3. Exclude bazel/cargo/remote/BUILD.rustix-0.26.2.bazel from format check.

Done. And thanks a lot for all the detailed feedback!

@PiotrSikora
Copy link
Member

@kfaseela thanks for all the work, this looks good now! Would you mind updating proxy-wasm-cpp-host in your Envoy PR to your latest commit to verify that it works end-to-end before I merge this? Thanks!

@PiotrSikora PiotrSikora changed the title WIP: wasmtime: update to v0.32.0 wasmtime: update to v0.32.0 Dec 31, 2021
@kfaseela
Copy link
Contributor Author

kfaseela commented Jan 1, 2022

@PiotrSikora It still failed : envoyproxy/envoy#19285

ERROR: /build/tmp/_bazel_envoybuild/400406edc57d332f0b9b805d2b8e33a1/external/envoy/test/extensions/common/wasm/BUILD:18:14: Linking external/envoy/test/extensions/common/wasm/wasm_vm_test failed: (Exit 1): clang failed: error executing command
(cd /build/tmp/_bazel_envoybuild/400406edc57d332f0b9b805d2b8e33a1/execroot/envoy_filter_example &&
exec env -
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
BAZEL_LINKLIBS=-l%:libstdc++.a
BAZEL_LINKOPTS=-lm
CC=clang
CXX=clang++
PATH=/usr/sbin:/usr/bin:/sbin:/bin:/opt/llvm/bin
PWD=/proc/self/cwd
/opt/llvm/bin/clang @bazel-out/k8-dbg/bin/external/envoy/test/extensions/common/wasm/wasm_vm_test-2.params)
Execution platform: @envoy_build_tools//toolchains:rbe_linux_clang_platform
ld.lld: error: undefined symbol: renameat2

referenced by syscalls.rs:189 (external/proxy_wasm_cpp_host__rustix__0_26_2/src/imp/libc/fs/syscalls.rs:189)
rustix-2123923521.rustix.d78db92e-cgu.5.rcgu.o:(rustix::imp::libc::fs::syscalls::renameat2::h9a4de3c870cc34f4) in archive bazel-out/k8-dbg/bin/external/com_github_wasmtime/librust_c_api-220117231.a
did you mean: renameat
defined in: /lib/x86_64-linux-gnu/libc.so.6
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

The build rules are fine, and I was able to sucessfully build envoyproxy/envoy#19285 locally. The issue is with the build image used in Envoy's CI (Ubuntu 18.04 with glibc 2.27), because rustix requires glibc 2.28 or newer for renameat2 when using libc backend. Interestingly, while the version of rustix (previously rsix) in wasmtime v0.32.0 defaults to linux-raw, it previously defaulted to libc, so this shouldn't be a new dependency, and it would be good to investigate why this became an issue.

Separately, the successfully built binary and tests crash in Envoy when initializing WasmVM, so there is a lot more work that needs to be done before this can be merged. I looked a bit into it, but I don't have any idea why it's broken.

If you want to investigate this, then I'd start with:

  1. Figuring out the difference between tests here and in Envoy (i.e. why tests in this repository pass, but those in Envoy crash). It could be because of multiple WasmVM instances and canarying in Envoy that's missing in tests here, or simply because we don't have a good test coverage in this repository.
  2. Figuring out why glibc became an issue (bisecting / looking at changes in rustix between v0.23.2 and v0.26.2, and in wasmtime between v0.31.0 and v0.32.0).

@PiotrSikora
Copy link
Member

Separately, the successfully built binary and tests crash in Envoy when initializing WasmVM, so there is a lot more work that needs to be done before this can be merged. I looked a bit into it, but I don't have any idea why it's broken.

OK, I found the issue.

It looks that the ownership model for vectors was changed in wasmtime v0.32.0 (bytecodealliance/wasmtime@ce67e7f), so you need to remove those 3 lines from src/wasmtime/wasmtime.cc:

for (auto i = ps.begin(); i < ps.end(); i++) { // TODO(mathetake): better way to handle?
wasm_valtype_delete(*i);
}

Once those lines are removed, all tests in Envoy pass, but we still need to figure out the glibc issue before this can be used in Envoy on Ubuntu 18.04.

@PiotrSikora
Copy link
Member

PiotrSikora commented Jan 2, 2022

  1. Add this:
        "--cfg=feature=\"cc\"",

to rustc_flags in rustix_build_script target in bazel/cargo/remote/BUILD.rustix-0.26.2.bazel. This is temporary hack, until the bug is fixed in cargo-raze (see: google/cargo-raze#461).

@kfaseela you've missed this step (you'll also need to restore the exclusion for rustix in the format check - basically, revert .github/workflows/cargo.yml to the version from yesterday).

Other than that, everything looks fine now, so you could update Envoy PR once you incorporate those changes. Thanks!

Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Could you update envoyproxy/envoy#19285 to verify this end-to-end on Envoy's CI before merging?

@PiotrSikora PiotrSikora merged commit f2f90be into proxy-wasm:master Jan 2, 2022
PiotrSikora added a commit to PiotrSikora/proxy-wasm-cpp-host that referenced this pull request Jan 3, 2022
@PiotrSikora
Copy link
Member

  • Figuring out the difference between tests here and in Envoy (i.e. why tests in this repository pass, but those in Envoy crash). It could be because of multiple WasmVM instances and canarying in Envoy that's missing in tests here, or simply because we don't have a good test coverage in this repository.

OK, I finally figured this out. This PR didn't update wasmtime to v0.32.0 in bazel/repositories.bzl, so the Wasmtime C API was still using v0.31.0 (without the aforementioned ownership changes from bytecodealliance/wasmtime@ce67e7f), whereas the Envoy PR updated sources, so it was building and failing tests against updated Wasmtime C API v0.32.0.

Verified and fixed in #209.

@kfaseela
Copy link
Contributor Author

kfaseela commented Jan 3, 2022

@PiotrSikora : Thank you so much for all the help with this PR!

PiotrSikora added a commit that referenced this pull request Jan 3, 2022
Missed in #205.

Signed-off-by: Piotr Sikora <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants