[SOLVED] Compiling cosmwasm-sgx-vm: error[E0432]: unresolved imports `cranelift`

Hi all,
I’m simply following https://build.scrt.network/dev/contract-dev-guide.html and it compiles well, but afterwards, when running unit/integration tests or cargo scheme I’m getting:

    
 Compiling cosmwasm-sgx-vm v0.9.0-alpha1 (https://github.com/enigmampc/SecretNetwork?tag=v0.5.0-alpha2#b1710787)
error[E0432]: unresolved imports `cranelift`, `crate::backends::get_gas_left`
  --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/backends/mod.rs:24:9
   |
24 | pub use cranelift::{backend, compile, get_gas_left, set_gas_limit};
   |         ^^^^^^^^^ use of undeclared type or module `cranelift`
   | 
  ::: /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:20:5
   |
20 | use crate::backends::get_gas_left;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot find macro `imports` in this scope
  --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:94:13
   |
94 |             imports! { move || { setup_context::(gas_limit) }, "env" => {}, };
   |             ^^^^^^^

error: cannot find macro `imports` in this scope
...

What could be wrong? Do I miss anything?
I run it on Ubuntu 18.04 with SGX working well.

Ah yeah, sorry, that’s a small oversight on our end. I’ll push a PR that fixes it in the secret-template repo now, but in the meanwhile please apply this patch to your Cargo.toml file:

diff --git a/Cargo.toml b/Cargo.toml
index 763d3e5..5e20f38 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,12 +27,10 @@ incremental = false
 overflow-checks = true
 
 [features]
-default = ["cranelift"]
+default = []
 # for quicker tests, cargo test --lib
 # for more explicit tests, cargo test --features=backtraces
 backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
-cranelift = ["cosmwasm-vm/default-cranelift"]
-singlepass = ["cosmwasm-vm/default-singlepass"]
 
 [dependencies]
 cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v0.5.0-alpha2" }

In general though, i don’t think that the integration tests will work. Definitely let us know if they do :sweat_smile: I believe the unittests should be good :+1:

1 Like

@plek and to anyone else that finds this:

The issue should be fixed in the latest commit on the secret-template repository :+1:

1 Like

@reuven thanks for your prompt action!:wink: That indeed helped with the first error, but I’m getting others:

Compiling cosmwasm-sgx-vm v0.9.0-alpha1 (https://github.com/enigmampc/SecretNetwork?tag=v0.5.0-alpha2#b1710787)
error[E0432]: unresolved import `crate::backends::get_gas_left`
  --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:20:5
   |
20 | use crate::backends::get_gas_left;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `get_gas_left` in `backends`

error: cannot find macro `imports` in this scope
  --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:94:13
   |
94 |             imports! { move || { setup_context::<S, Q>(gas_limit) }, "env" => {}, };
   |             ^^^^^^^

error: cannot find macro `imports` in this scope
  --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:98:27
   |
98 |         import_obj.extend(imports! {
   |                           ^^^^^^^

error[E0433]: failed to resolve: use of undeclared type or module `VmError`
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:167:13
    |
167 |             VmError::instantiation_err(format!("Error instantiating module: {:?}", original))
    |             ^^^^^^^ use of undeclared type or module `VmError`

error[E0433]: failed to resolve: use of undeclared type or module `CommunicationError`
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:249:24
    |
249 |             return Err(CommunicationError::zero_address().into());
    |                        ^^^^^^^^^^^^^^^^^^ use of undeclared type or module `CommunicationError`

error[E0412]: cannot find type `Func` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/calls.rs:161:23
    |
161 |             let func: Func<u32, u32> = instance.func(name)?;
    |                       ^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
1   | use parity_wasm::elements::Func;
    |

error[E0412]: cannot find type `Func` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/calls.rs:165:23
    |
165 |             let func: Func<(u32, u32), u32> = instance.func(name)?;
    |                       ^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
1   | use parity_wasm::elements::Func;
    |

error[E0412]: cannot find type `NonNull` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/context.rs:177:29
    |
177 |     wasmer_instance: Option<NonNull<WasmerInstance>>,
    |                             ^^^^^^^ not found in this scope
    |
help: possible candidates are found in other modules, you can import them into scope
    |
6   | use core::ptr::NonNull;
    |
6   | use std::ptr::NonNull;
    |

error[E0412]: cannot find type `WasmerInstance` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/context.rs:177:37
    |
175 | pub fn set_wasmer_instance<S: Storage, Q: Querier>(
    |                                                  - help: you might be missing a type parameter: `, WasmerInstance`
176 |     ctx: &mut Ctx,
177 |     wasmer_instance: Option<NonNull<WasmerInstance>>,
    |                                     ^^^^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `WasmTypeList` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/context.rs:297:11
    |
297 |     Args: WasmTypeList,
    |           ^^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `WasmTypeList` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/context.rs:298:11
    |
298 |     Rets: WasmTypeList,
    |           ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `Func` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/context.rs:299:22
    |
299 |     Callback: FnOnce(Func<Args, Rets, Wasm>) -> VmResult<CallbackData>,
    |                      ^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
6   | use parity_wasm::elements::Func;
    |

error[E0412]: cannot find type `Wasm` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/context.rs:299:39
    |
299 |     Callback: FnOnce(Func<Args, Rets, Wasm>) -> VmResult<CallbackData>,
    |                                       ^^^^ not found in this scope
    |
help: there is an enum variant `cosmwasm_std::CosmosMsg::Wasm` and 1 other; try using the variant's enum
    |
299 |     Callback: FnOnce(Func<Args, Rets, cosmwasm_std::CosmosMsg>) -> VmResult<CallbackData>,
    |                                       ^^^^^^^^^^^^^^^^^^^^^^^
299 |     Callback: FnOnce(Func<Args, Rets, cosmwasm_std::QueryRequest>) -> VmResult<CallbackData>,
    |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: you might be missing a type parameter
    |
289 | pub(crate) fn with_func_from_context<S, Q, Args, Rets, Callback, CallbackData, Wasm>(
    |                                                                              ^^^^^^

error[E0425]: cannot find function `get_memory_info` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:219:10
    |
219 |         (get_memory_info(self.inner.context()).size as u64) * WASM_PAGE_SIZE
    |          ^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `WASM_PAGE_SIZE` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:219:63
    |
219 |         (get_memory_info(self.inner.context()).size as u64) * WASM_PAGE_SIZE
    |                                                               ^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `Func` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:246:20
    |
246 |         let alloc: Func<u32, u32> = self.func("allocate")?;
    |                    ^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
4   | use parity_wasm::elements::Func;
    |

error[E0425]: cannot find function `to_u32` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:247:30
    |
247 |         let ptr = alloc.call(to_u32(size)?)?;
    |                              ^^^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
4   | use crate::conversion::to_u32;
    |

error[E0412]: cannot find type `Func` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:259:22
    |
259 |         let dealloc: Func<u32, ()> = self.func("deallocate")?;
    |                      ^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
4   | use parity_wasm::elements::Func;
    |

error[E0425]: cannot find function `read_region` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:267:9
    |
267 |         read_region(self.inner.context(), region_ptr, max_length)
    |         ^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function `write_region` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:273:9
    |
273 |         write_region(self.inner.context(), region_ptr, data)?;
    |         ^^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `WasmTypeList` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:280:15
    |
280 |         Args: WasmTypeList,
    |               ^^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `WasmTypeList` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:281:15
    |
281 |         Rets: WasmTypeList,
    |               ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `Func` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:278:67
    |
278 |     pub(crate) fn func<Args, Rets>(&self, name: &str) -> VmResult<Func<Args, Rets, Wasm>>
    |                                                                   ^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
4   | use parity_wasm::elements::Func;
    |

error[E0412]: cannot find type `Wasm` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/instance.rs:278:84
    |
278 |     pub(crate) fn func<Args, Rets>(&self, name: &str) -> VmResult<Func<Args, Rets, Wasm>>
    |                                                                                    ^^^^ not found in this scope
    |
help: there is an enum variant `cosmwasm_std::CosmosMsg::Wasm` and 1 other; try using the variant's enum
    |
278 |     pub(crate) fn func<Args, Rets>(&self, name: &str) -> VmResult<Func<Args, Rets, cosmwasm_std::CosmosMsg>>
    |                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^
278 |     pub(crate) fn func<Args, Rets>(&self, name: &str) -> VmResult<Func<Args, Rets, cosmwasm_std::QueryRequest>>
    |                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: you might be missing a type parameter
    |
64  | impl<S, A, Q, Wasm> Instance<S, A, Q>
    |             ^^^^^^

error[E0405]: cannot find trait `Storage` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/testing/instance.rs:134:19
    |
134 | pub fn test_io<S: Storage + 'static, A: Api + 'static, Q: Querier + 'static>(
    |                   ^^^^^^^ not found in this scope
    |
help: possible candidates are found in other modules, you can import them into scope
    |
4   | use cosmwasm_std::Storage;
    |
4   | use crate::traits::Storage;
    |

error[E0405]: cannot find trait `Api` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/testing/instance.rs:134:41
    |
134 | pub fn test_io<S: Storage + 'static, A: Api + 'static, Q: Querier + 'static>(
    |                                         ^^^ not found in this scope
    |
help: possible candidates are found in other modules, you can import them into scope
    |
4   | use cosmwasm_std::Api;
    |
4   | use crate::traits::Api;
    |

error[E0405]: cannot find trait `Querier` in this scope
   --> /home/p1/.cargo/git/checkouts/secretnetwork-2885a5c51d1243af/b171078/cosmwasm/packages/sgx-vm/src/testing/instance.rs:134:59
    |
134 | pub fn test_io<S: Storage + 'static, A: Api + 'static, Q: Querier + 'static>(
    |                                                           ^^^^^^^ not found in this scope
    |
help: possible candidates are found in other modules, you can import them into scope
    |
4   | use cosmwasm_std::Querier;
    |
4   | use crate::traits::Querier;
    |

error: aborting due to 27 previous errors

Some errors have detailed explanations: E0405, E0412, E0425, E0432, E0433.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `cosmwasm-sgx-vm`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

yikes
what command did you run to get this output?

also, please edit your last comment to surround the console output with triple back-ticks:
```

It will make it a lot easier to read.
Ideally paste big outputs to pastebin.com and then link to it

I’m getting it with any of RUST_BACKTRACE=1 cargo unit-test , cargo integration-test, or cargo schema.

alright, remove the default-features = false part from the cosmwas-vm line in Cargo.toml please :slight_smile:

Thanks, that helped!:wink:

1 Like

Happy to hear that!
Definitely let us know if you run into any other issues or questions along the way :smiley:
We’re still pre-testnet so we’re still polishing a lot of rough edges like this one.