Repository: bytecodealliance/wasmtime
Pull request #2781 (2021-03-26 19:30:05)

Use unpacked debuginfo on macOS CI
This shaves ~10 minutes off the testing builder since `dsymutil` is
never run and the linker isn't exactly speedy moving around so much debuginfo.

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

- [ ] This has been discussed in issue #..., or if not, please tell us why
  here.
- [ ] A short description of what this does, why it is needed; if the
  description becomes long, the matter should probably be discussed in an issue
  first.
- [ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
  If you don't know who could review this, please indicate so. The list of
  suggested reviewers on the right can help you.

Please ensure all communication adheres to the [code of
conduct](https://github.com/bytecodealliance/wasmtime/blob/master/CODE_OF_CONDUCT.md).
-->



Patch:
diff --git a/.github/actions/install-rust/main.js b/.github/actions/install-rust/main.js
index 9f16b8183..2de34dbf1 100644
--- a/.github/actions/install-rust/main.js
+++ b/.github/actions/install-rust/main.js
@@ -30,3 +30,8 @@ set_env("CARGO_INCREMENTAL", "0");
 // Turn down debuginfo from 2 to 1 to help save disk space
 set_env("CARGO_PROFILE_DEV_DEBUG", "1");
 set_env("CARGO_PROFILE_TEST_DEBUG", "1");
+
+if (process.platform === 'darwin') {
+  set_env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "unpacked");
+  set_env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "unpacked");
+}
diff --git a/Cargo.lock b/Cargo.lock
index 9aa8863d4..0e40dba03 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3269,7 +3269,6 @@ name = "wasmtime-cli"
 version = "0.25.0"
 dependencies = [
  "anyhow",
- "cap-std",
  "env_logger 0.8.3",
  "file-per-thread-logger",
  "filecheck",
@@ -3285,8 +3284,6 @@ dependencies = [
  "tempfile",
  "test-programs",
  "tracing-subscriber",
- "wasi-cap-std-sync",
- "wasi-common",
  "wasmparser",
  "wasmtime",
  "wasmtime-cache",
@@ -3513,6 +3510,7 @@ name = "wasmtime-wasi"
 version = "0.25.0"
 dependencies = [
  "anyhow",
+ "wasi-cap-std-sync",
  "wasi-common",
  "wasmtime",
  "wasmtime-wiggle",
diff --git a/Cargo.toml b/Cargo.toml
index 6bcd156b6..be37d8cec 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,8 +32,6 @@ wasmtime-wast = { path = "crates/wast", version = "0.25.0" }
 wasmtime-wasi = { path = "crates/wasi", version = "0.25.0" }
 wasmtime-wasi-crypto = { path = "crates/wasi-crypto", version = "0.25.0", optional = true }
 wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "0.25.0", optional = true }
-wasi-common = { path = "crates/wasi-common", version = "0.25.0" }
-wasi-cap-std-sync = { path = "crates/wasi-common/cap-std-sync", version = "0.25.0" }
 structopt = { version = "0.3.5", features = ["color", "suggestions"] }
 object = { version = "0.23.0", default-features = false, features = ["write"] }
 anyhow = "1.0.19"
@@ -46,7 +44,6 @@ log = "0.4.8"
 rayon = "1.2.1"
 humantime = "2.0.0"
 wasmparser = "0.77.0"
-cap-std = "0.13"
 
 [dev-dependencies]
 env_logger = "0.8.1"
diff --git a/crates/c-api/src/wasi.rs b/crates/c-api/src/wasi.rs
index 8fa15f0c2..441fa6fa5 100644
--- a/crates/c-api/src/wasi.rs
+++ b/crates/c-api/src/wasi.rs
@@ -1,7 +1,6 @@
 //! The WASI embedding API definitions for Wasmtime.
 use crate::{wasm_extern_t, wasm_importtype_t, wasm_store_t, wasm_trap_t};
 use anyhow::Result;
-use cap_std::fs::Dir;
 use std::cell::RefCell;
 use std::collections::HashMap;
 use std::ffi::CStr;
@@ -11,11 +10,12 @@ use std::path::{Path, PathBuf};
 use std::rc::Rc;
 use std::slice;
 use std::str;
-use wasi_cap_std_sync::WasiCtxBuilder;
-use wasi_common::WasiCtx;
 use wasmtime::{Extern, Linker, Trap};
 use wasmtime_wasi::{
-    snapshots::preview_0::Wasi as WasiSnapshot0, snapshots::preview_1::Wasi as WasiPreview1,
+    snapshots::preview_0::Wasi as WasiSnapshot0,
+    snapshots::preview_1::Wasi as WasiPreview1,
+    sync::{Dir, WasiCtxBuilder},
+    WasiCtx,
 };
 
 unsafe fn cstr_to_path<'a>(path: *const c_char) -> Option<&'a Path> {
@@ -186,7 +186,7 @@ pub unsafe extern "C" fn wasi_config_preopen_dir(
     };
 
     let dir = match cstr_to_path(path) {
-        Some(p) => match cap_std::fs::Dir::open_ambient_dir(p) {
+        Some(p) => match Dir::open_ambient_dir(p) {
             Ok(d) => d,
             Err(_) => return false,
         },
diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs
index c1f9b1e03..289e584de 100644
--- a/crates/fuzzing/src/oracles.rs
+++ b/crates/fuzzing/src/oracles.rs
@@ -126,15 +126,27 @@ pub fn instantiate_with_config(
 
     match linker.instantiate(&module) {
         Ok(_) => {}
-        // Allow traps which can happen normally with `unreachable` or a timeout
-        Err(e) if e.downcast_ref::<Trap>().is_some() => {}
-        // Allow resource exhaustion since this is something that our wasm-smith
-        // generator doesn't guarantee is forbidden.
-        Err(e) if e.to_string().contains("resource limit exceeded") => {}
-        // Also allow errors related to fuel consumption
-        Err(e) if e.to_string().contains("all fuel consumed") => {}
-        // Everything else should be a bug in the fuzzer
-        Err(e) => panic!("failed to instantiate {}", e),
+        Err(e) => {
+            let string = e.to_string();
+            // Allow traps which can happen normally with `unreachable` or a
+            // timeout
+            if e.downcast_ref::<Trap>().is_some()
+                // Allow resource exhaustion since this is something that
+                // our wasm-smith generator doesn't guarantee is forbidden.
+                || string.contains("resource limit exceeded")
+                // Also allow errors related to fuel consumption
+                || string.contains("all fuel consumed")
+                // Currently we instantiate with a `Linker` which can't instantiate
+                // every single module under the sun due to using name-based resolution
+                // rather than positional-based resolution
+                || string.contains("incompatible import type")
+            {
+                return;
+            }
+
+            // Everything else should be a bug in the fuzzer
+            panic!("failed to instantiate {:?}", e);
+        }
     }
 }
 
diff --git a/crates/wasi-common/cap-std-sync/src/lib.rs b/crates/wasi-common/cap-std-sync/src/lib.rs
index fe3895129..ac8ee602e 100644
--- a/crates/wasi-common/cap-std-sync/src/lib.rs
+++ b/crates/wasi-common/cap-std-sync/src/lib.rs
@@ -14,6 +14,10 @@
 //! `cap_std::fs::Dir`, and provides convenience methods for inheriting the
 //! parent process's stdio, args, and env.
 //!
+//! For the convenience of consumers, `cap_std::fs::Dir` is re-exported from
+//! this crate. This saves consumers tracking an additional dep on the exact
+//! version of cap_std used by this crate, if they want to avoid it.
+//!
 //! The only place we expect to run into long-term compatibility issues
 //! between `wasi-cap-std-sync` and the other impl crates that will come later
 //! is in the `Sched` abstraction. Once we can build an async scheduler based
@@ -33,6 +37,7 @@ pub mod file;
 pub mod sched;
 pub mod stdio;
 
+pub use cap_std::fs::Dir;
 pub use clocks::clocks_ctx;
 pub use sched::sched_ctx;
 
@@ -110,13 +115,9 @@ impl WasiCtxBuilder {
     pub fn inherit_stdio(self) -> Self {
         self.inherit_stdin().inherit_stdout().inherit_stderr()
     }
-    pub fn preopened_dir(
-        self,
-        dir: cap_std::fs::Dir,
-        path: impl AsRef<Path>,
-    ) -> Result<Self, Error> {
+    pub fn preopened_dir(self, dir: Dir, guest_path: impl AsRef<Path>) -> Result<Self, Error> {
         let dir = Box::new(crate::dir::Dir::from_cap_std(dir));
-        Ok(WasiCtxBuilder(self.0.preopened_dir(dir, path)?))
+        Ok(WasiCtxBuilder(self.0.preopened_dir(dir, guest_path)?))
     }
     pub fn build(self) -> Result<WasiCtx, Error> {
         self.0.build()
diff --git a/crates/wasi/Cargo.toml b/crates/wasi/Cargo.toml
index 5937ec55a..a6db19e5b 100644
--- a/crates/wasi/Cargo.toml
+++ b/crates/wasi/Cargo.toml
@@ -14,7 +14,12 @@ build = "build.rs"
 
 [dependencies]
 wasi-common = { path = "../wasi-common", version = "0.25.0" }
+wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", version = "0.25.0", optional = true }
 wiggle = { path = "../wiggle", default-features = false, version = "0.25.0" }
 wasmtime-wiggle = { path = "../wiggle/wasmtime", default-features = false, version = "0.25.0" }
 wasmtime = { path = "../wasmtime", default-features = false, version = "0.25.0" }
 anyhow = "1.0"
+
+[features]
+default = ["sync"]
+sync = ["wasi-cap-std-sync"]
diff --git a/crates/wasi/src/lib.rs b/crates/wasi/src/lib.rs
index 1c3ad448a..2b71d7ab3 100644
--- a/crates/wasi/src/lib.rs
+++ b/crates/wasi/src/lib.rs
@@ -12,6 +12,14 @@ use std::rc::Rc;
 pub use wasi_common::{Error, WasiCtx, WasiCtxBuilder, WasiDir, WasiFile};
 use wasmtime::{Config, Linker, Store};
 
+/// Re-export the commonly used wasi-cap-std-sync crate here. This saves
+/// consumers of this library from having to keep additional dependencies
+/// in sync.
+#[cfg(feature = "sync")]
+pub mod sync {
+    pub use wasi_cap_std_sync::*;
+}
+
 /// An instantiated instance of all available wasi exports. Presently includes
 /// both the "preview1" snapshot and the "unstable" (preview0) snapshot.
 pub struct Wasi {
diff --git a/crates/wiggle/generate/src/funcs.rs b/crates/wiggle/generate/src/funcs.rs
index 4fcdcba47..69a5d89ee 100644
--- a/crates/wiggle/generate/src/funcs.rs
+++ b/crates/wiggle/generate/src/funcs.rs
@@ -69,8 +69,9 @@ pub fn define_func(
         ) -> Result<#abi_ret, #rt::Trap> {
             use std::convert::TryFrom as _;
 
+            // This span is present at all levels (ERROR and below)
             let _span = #rt::tracing::span!(
-                #rt::tracing::Level::TRACE,
+                #rt::tracing::Level::ERROR,
                 "wiggle abi",
                 module = #mod_name,
                 function = #func_name
diff --git a/crates/wiggle/wasmtime/macro/src/lib.rs b/crates/wiggle/wasmtime/macro/src/lib.rs
index 6dc7b1447..24732c7f2 100644
--- a/crates/wiggle/wasmtime/macro/src/lib.rs
+++ b/crates/wiggle/wasmtime/macro/src/lib.rs
@@ -288,7 +288,7 @@ fn generate_func(
             let #name_ident = wasmtime::Func::#wrapper(
                 store,
                 ctx.clone(),
-                move |caller: wasmtime::Caller<'_>, my_ctx: &Rc<RefCell<_>> #(,#arg_decls)*|
+                move |caller: wasmtime::Caller<'_>, my_ctx: &std::rc::Rc<std::cell::RefCell<_>> #(,#arg_decls)*|
                     -> Box<dyn std::future::Future<Output = Result<#ret_ty, wasmtime::Trap>>> {
                     Box::new(async move { Self::#fn_ident(&caller, &mut my_ctx.borrow_mut() #(, #arg_names)*).await })
                 }
diff --git a/examples/linking.rs b/examples/linking.rs
index 11f4022bc..b4cee53a4 100644
--- a/examples/linking.rs
+++ b/examples/linking.rs
@@ -3,9 +3,8 @@
 // You can execute this example with `cargo run --example linking`
 
 use anyhow::Result;
-use wasi_cap_std_sync::WasiCtxBuilder;
 use wasmtime::*;
-use wasmtime_wasi::Wasi;
+use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi};
 
 fn main() -> Result<()> {
     let engine = Engine::default();
diff --git a/examples/wasi/main.rs b/examples/wasi/main.rs
index f1487171f..f808be3ec 100644
--- a/examples/wasi/main.rs
+++ b/examples/wasi/main.rs
@@ -4,9 +4,8 @@
 // You can execute this example with `cargo run --example wasi`
 
 use anyhow::Result;
-use wasi_cap_std_sync::WasiCtxBuilder;
 use wasmtime::*;
-use wasmtime_wasi::Wasi;
+use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi};
 
 fn main() -> Result<()> {
     tracing_subscriber::FmtSubscriber::builder()
diff --git a/src/commands/run.rs b/src/commands/run.rs
index 89f9ec120..f8b701014 100644
--- a/src/commands/run.rs
+++ b/src/commands/run.rs
@@ -2,7 +2,6 @@
 
 use crate::{init_file_per_thread_logger, CommonOptions};
 use anyhow::{bail, Context as _, Result};
-use cap_std::fs::Dir;
 use std::thread;
 use std::time::Duration;
 use std::{
@@ -11,9 +10,11 @@ use std::{
     process,
 };
 use structopt::{clap::AppSettings, StructOpt};
-use wasi_cap_std_sync::WasiCtxBuilder;
 use wasmtime::{Engine, Func, Linker, Module, Store, Trap, Val, ValType};
-use wasmtime_wasi::Wasi;
+use wasmtime_wasi::{
+    sync::{Dir, WasiCtxBuilder},
+    Wasi,
+};
 
 #[cfg(feature = "wasi-nn")]
 use wasmtime_wasi_nn::{WasiNn, WasiNnCtx};


Test patch:
diff --git a/cranelift/filetests/filetests/isa/x64/popcnt.clif b/cranelift/filetests/filetests/isa/x64/popcnt.clif
index a06f5a27c..4d0f08cf6 100644
--- a/cranelift/filetests/filetests/isa/x64/popcnt.clif
+++ b/cranelift/filetests/filetests/isa/x64/popcnt.clif
@@ -2,8 +2,6 @@ test compile
 target x86_64
 feature "experimental_x64"
 
-; TODO: test with popcnt feature available too, once new backend supports that.
-
 function %popcnt64(i64) -> i64 {
 block0(v0: i64):
     v1 = popcnt v0
diff --git a/tests/all/host_funcs.rs b/tests/all/host_funcs.rs
index 26d432994..360e2526a 100644
--- a/tests/all/host_funcs.rs
+++ b/tests/all/host_funcs.rs
@@ -1,8 +1,7 @@
 use anyhow::Result;
 use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
-use wasi_cap_std_sync::WasiCtxBuilder;
 use wasmtime::*;
-use wasmtime_wasi::Wasi;
+use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi};
 
 #[test]
 fn async_required() {
diff --git a/tests/all/traps.rs b/tests/all/traps.rs
index b83ac38da..a4686e907 100644
--- a/tests/all/traps.rs
+++ b/tests/all/traps.rs
@@ -512,7 +512,7 @@ fn parse_dwarf_info() -> Result<()> {
     let mut linker = Linker::new(&store);
     wasmtime_wasi::Wasi::new(
         &store,
-        wasi_cap_std_sync::WasiCtxBuilder::new()
+        wasmtime_wasi::sync::WasiCtxBuilder::new()
             .inherit_stdio()
             .build()?,
     )