mandrean / cw-optimizoor

A blazingly fast compiling & optimization tool for CosmWasm smart contracts.
MIT License
50 stars 6 forks source link

Sometimes creates empty wasm binaries #3

Closed de-husk closed 2 years ago

de-husk commented 2 years ago

Awesome project!

I ran into an issue trying to use it with this workspace: https://github.com/DA0-DA0/dao-contracts

It produced nearly empty optimized wasm binaries for cw20_stake and cw_core contracts.

When I tried to use them, I got this error:

Error calling the VM: Error during static Wasm validation: Wasm contract doesn't have required export: "instantiate". Exports required by VM: ["allocate", "deallocate", "instantiate"].: create wasm contract failed: invalid request

Im wondering if optimizoor is compiling them with the library feature enabled?

mandrean commented 2 years ago

Hey @de-husk, thanks for reporting! Appreciate it. Will have a look.

mandrean commented 2 years ago

Okay, found the issue. Basically this can happen in monorepos where each member of the workspace has its own lockfile, like the DA0-DA0 contracts

Current implementation assumes the monorepo shares one lockfile. Shouldn't be too difficult to support both cases

mandrean commented 2 years ago

I digged quite a bit deeper into this, and the lockfile hypothesis was just a coincidence. It's actually a bug(/feature) in cargo itself: https://github.com/rust-lang/cargo/issues/3620 https://github.com/rust-lang/cargo/issues/8157#issuecomment-619417124 https://github.com/rust-lang/cargo/issues/4463 https://github.com/rust-lang/cargo/issues/4866 https://github.com/rust-lang/cargo/issues/10266#issuecomment-1006800857

ehuss commented on Jul 6, 2020 Thanks for the report! This is a known issue /.../ The --workspace flag causes all features of all workspace members to be unified.

If you have a workspace where a member (e.g. DA0-DA0/cw_core) is both a release binary and a library/dependency to some other binary, then cargo will "simplify" the dependency graph by only compiling that member (cw_core in this case) once - with the feature flag set - causing that to spill over into the release binary as well!

image

Looking into if there is a way to influence/work around this in an efficient way

mandrean commented 2 years ago

Okay @de-husk, I have a workaround! Check https://github.com/mandrean/cw-optimizoor/pull/5

de-husk commented 2 years ago

This is looking good btw. Thanks for the quick fix!

mandrean commented 2 years ago

Thanks for reporting the bug! Much appreciated.