CosmWasm / optimizer

Dockerfile and script to deterministically produce the smallest possible Wasm for your Rust contract
Apache License 2.0
118 stars 57 forks source link

Unable to optimize contract when a local project is added as a dependency #132

Closed emperorjm closed 11 months ago

emperorjm commented 11 months ago

I have two contracts with both projects in the following folder structure:

nft-card is a dependency for the card contract. The following is added to my Cargo.toml dependencies for the card contract:

nft-card = { path = "../nft-card", version = "0.1.0", features = ["library"] }

When I run the optimizer I get the following error:

Building contract in /code ...
error: failed to get `nft-card` as a dependency of package `card v2.0.0 (/code)`

Caused by:
  failed to load source for dependency `nft-card`

Caused by:
  Unable to update /nft-card

Caused by:
  failed to read `/nft-card/Cargo.toml`

Both `cargo build` and `cargo wasm` run with no issues.

Caused by:
  No such file or directory (os error 2)

Both cargo build and cargo wasm run with no issues.

webmaster128 commented 11 months ago

If you have a workspace with multiple projects you need to use workspace-optimizer instead of rust-optimizer. Then all your contracts need to go to the ./contracts/ folder and non-contract projects should be in a different place, e.g. packages. See for example the folder layout in https://github.com/CosmWasm/cw-plus.

emperorjm commented 11 months ago

Thanks a lot, @webmaster128. I had to restructure my entire project to utilize workspaces. For those curious about how I achieved this, I used version 2.0.0-beta.1 of the Archway CLI (https://github.com/archway-network/archway-cli/tree/2.0.0-beta.1). This version uses workspaces by default and facilitates the creation of multiple contracts within a project, leveraging the workspace-optimizer. I only became aware of this just now.