Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Support Cargo workspace with multiple contracts #26

Open
h3xag0nx opened this issue Mar 14, 2022 · 2 comments
Open

Support Cargo workspace with multiple contracts #26

h3xag0nx opened this issue Mar 14, 2022 · 2 comments

Comments

@h3xag0nx
Copy link

Let say I have 2 or more contracts, as

├── config.terrain.json
├── contracts
│   ├── contract-a
│   │   ├── Cargo.toml
│   │   ...
│   └── contract-b
│       ├── Cargo.toml

Terrain can deploy both contracts with no issue.
But when I define a workspace using root level Cargo.toml:

[workspace]
members = [ "contracts/*" ]

cargo build work fine but terrain cannot deploy because of the failure of the optimize script

Running script 'optimize': 'docker run --rm -v "$(pwd)":/code --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry cosmwasm/rust-optimizer:0.12.3
'
Info: RUSTC_WRAPPER=sccache
Info: sccache stats before build
Compile requests                      0
Compile requests executed             0
Cache hits                            0
Cache misses                          0
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  0
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                   0
Non-compilation calls                 0
Unsupported compiler calls            0
Average cache write               0.000 s
Average cache read miss           0.000 s
Average cache read hit            0.000 s
Failed distributed compilations       0
Cache location                  Local disk: "/root/.cache/sccache"
Cache size                            0 bytes
Max cache size                       10 GiB
Building contract in /code ...
    Updating crates.io index
error: the lock file /code/Cargo.lock needs to be updated but --locked was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
Finished, status of exit status: 101

I skimmed the rust-optimizer doc and find out that in this case optimze should be ran through workspace-optimizer container, as described here

Please show me how to change it with terrain or support this feature if it not available yet. Many thanks.

@bbqaaq
Copy link

bbqaaq commented Apr 8, 2022

Hi, after doing some researches, I think my issue is same as this issue so I should close my issue.
I think the way to solve my issue is using workspace-optimizer as mentioned.

Will there be any update for this?

@bbqaaq
Copy link

bbqaaq commented Apr 8, 2022

As seems no one is working on this issue, I have done my workaround on this today.

From rust-optimizer readme, there are two ways to handle workspace's contracts.
One is using workspace-optimizer and one is running the optimize.sh on workspace root.

So my way is to change the contract-a's cargo.toml optimize command to this:

[package.metadata.scripts]
optimize = """base=$(basename "$(pwd)") \
  && cd ../../ \
	&& docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(echo $base)_cache",target=/code/contracts/$base/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.12.5 ./contracts/$base \
	&& rm -rf ./contracts/$base/artifacts \
	&& mv -f artifacts ./contracts/$base \
	&& cd ./contracts/$base \
"""

This is to make the rust-optimize to run on the workspace root, and move the artifacts back to the right directory.
I don't know if this will be problematic but so far my side works. Hope it helps if someone stuck here also.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants