Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration to cargo near #184

Merged
merged 73 commits into from
Jan 31, 2025
Merged

feat: migration to cargo near #184

merged 73 commits into from
Jan 31, 2025

Conversation

frolvanya
Copy link
Contributor

@frolvanya frolvanya commented Jan 13, 2025

Usage Guide

Compilation

There're two options to compile contract:

  1. Using methods in Makefile from the root of repo
# I have added all packages, so general command looks like this: rust-build-<package-name>
$ make rust-build-evm-prover

# We can also build all contracts like this:
$ make rust-build-near
  1. Using cargo near command directly:
$ cargo near build reproducible-wasm
# or we might need to specify `manifest-path` if the current pwd is not a contract (e.g pwd is ./near)
$ cargo near build reproducible-wasm --manifest-path ./omni-prover/evm-prover/Cargo.toml

Warning

If you have darwin-arm64 (aka MacBook with M chip) you would need to have rosetta installed (softwareupdate --install-rosetta). Otherwise, you might run in an issue during compilation with Docker

Deployment

There're two options to deploy as well:

  1. If we have already a wasm file that we want to deploy:
near contract deploy <account-id> use-file <path-to-wasm> with-init-call init json-args '{...}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' network-config <network> sign-with-keychain send
  1. If we don't have a wasm we can either compile it using cargo near build or use cargo near deploy:
cargo near deploy build-reproducible-wasm <account-id> without-init-call network-config testnet sign-with-keychain send

This command will build and deploy wasm for us

Note

cargo near works in interactive mode as well just like near-cli-rs. Meaning you can call cargo near and process the rest in interactive mode by building command with a correct options

@frolvanya
Copy link
Contributor Author

rustc 1.84.0 + building wasm using cargo-near-build directly during testing works correctly: https://github.com/Near-One/omni-bridge/actions/runs/12738704841/job/35501410832?pr=184

@frolvanya frolvanya changed the base branch from main to feat/mpc-getter January 13, 2025 01:31
@frolvanya frolvanya marked this pull request as ready for review January 13, 2025 03:10
@frolvanya frolvanya linked an issue Jan 13, 2025 that may be closed by this pull request
@frolvanya frolvanya changed the base branch from feat/mpc-getter to main January 16, 2025 03:53
@frolvanya frolvanya force-pushed the feat/migration-to-cargo-near branch 10 times, most recently from 509fa26 to bd8dbf2 Compare January 16, 2025 10:31
@frolvanya frolvanya force-pushed the feat/migration-to-cargo-near branch 10 times, most recently from cdf0f64 to 11cbf7f Compare January 22, 2025 02:30
dj8yfo added a commit to near/cargo-near that referenced this pull request Jan 22, 2025
…e in tests context (#292)

reason for this pr is that [LazyLock initialization
block](https://github.com/NEAR-DevHub/neardevhub-contract/blob/083fdde69d147f43bd320094db1b3a8acf64c841/tests/test_env/mod.rs#L20-L27)
doesn't work to ensure tested contracts are built only once for `cargo
nextest run` as **cargo-nextest** uses a process-per-test runner,
and for usual `cargo test` workflows it may not be convenient/possible
to unite all tests into a single test module, thus contracts' build will
run at least once per each test module.

This pr minimizes time spent on contracts' rebuilding after initial
build, so that LazyLock init block isn't that much needed any more, but
it depends on separating target folders of different contracts being
tested similar to
dj8yfo/neardevhub-contract@cbbf0ee
to avoid partially rebuilding contracts starting with `near-sdk-macros`
crate, if it's shared in common release profile when different contracts
are in a workspace.

---

this results in 

```bash
• Building contract
 │     Finished `release` profile [optimized] target(s) in 0.08s

• Running an optimize for size post-step with wasm-opt...
/home/user/Documents/code/near/neardevhub-contract/target/wasm32-unknown-unknown/release/devhub.wasm -> /tmp/optimized-s2bmSK.wasm
• done

✓ Contract successfully built! (in CARGO_NEAR_BUILD_ENVIRONMENT=host)
     -                Binary: /home/user/Documents/code/near/neardevhub-contract/target/near/devhub.wasm
     - SHA-256 checksum hex : 1f568ea4c5eabf9c947a201f3adf38a4e47056658aa512fdfc722f17de9d3aa3
     - SHA-256 checksum bs58: 37LC32jmZFmZN8KesPipwUn4ZyhW4994coXqSWMdnDQv
     -                   ABI: /home/user/Documents/code/near/neardevhub-contract/target/near/devhub_abi.json
     -          Embedded ABI: /home/user/Documents/code/near/neardevhub-contract/target/near/devhub_abi.zst
    Finished cargo near build in 5s
Here is the console command if you ever need to re-run it again:
cargo near build non-reproducible-wasm
```

instead of

```bash
• Building contract
 │    Compiling near-sdk-macros v5.5.0
 │    Compiling near-sdk v5.5.0
 │    Compiling devhub_common v0.1.0 (/home/user/Documents/code/near/neardevhub-contract/d
evhub_common)
 │    Compiling near-contract-standards v5.5.0
 │    Compiling devhub v0.2.0 (/home/user/Documents/code/near/neardevhub-contract)
 │     Finished `release` profile [optimized] target(s) in 15.52s

• Running an optimize for size post-step with wasm-opt...
/home/user/Documents/code/near/neardevhub-contract/target/wasm32-unknown-unknown/release/d
evhub.wasm -> /tmp/optimized-FbzCfP.wasm
• done

✓ Contract successfully built! (in CARGO_NEAR_BUILD_ENVIRONMENT=host)
     -                Binary: /home/user/Documents/code/near/neardevhub-contract/target/ne
ar/devhub.wasm
     - SHA-256 checksum hex : 1f568ea4c5eabf9c947a201f3adf38a4e47056658aa512fdfc722f17de9d3aa3
     - SHA-256 checksum bs58: 37LC32jmZFmZN8KesPipwUn4ZyhW4994coXqSWMdnDQv
     -                   ABI: /home/user/Documents/code/near/neardevhub-contract/target/ne
ar/devhub_abi.json
     -          Embedded ABI: /home/user/Documents/code/near/neardevhub-contract/target/ne
ar/devhub_abi.zst
    Finished cargo near build in 20s
```
on rebuilds. 

and wasm-opt stage skipping was handled in
e746699
. No file locks were added, it would still waste some cpu, if multiple
builders enter the wasm-opt stage around the same time, but it does save
on time and locks are perceived as unneeded complexity at this time.

---

vaguely related to Near-One/omni-bridge#184

---------

Co-authored-by: dj8yf0μl <noreply@nowhere.org>
Co-authored-by: Vlad Frolov <frolvlad@gmail.com>
@frolvanya frolvanya force-pushed the feat/migration-to-cargo-near branch from 5e2f84b to 7206017 Compare January 22, 2025 17:18
@frolvanya frolvanya force-pushed the feat/migration-to-cargo-near branch from 7206017 to 841b997 Compare January 22, 2025 17:19
@frolvanya frolvanya force-pushed the feat/migration-to-cargo-near branch from b25eccd to 61b80d6 Compare January 22, 2025 17:49
@frolvanya frolvanya force-pushed the feat/migration-to-cargo-near branch from d8331d9 to 5211a34 Compare January 24, 2025 05:11
@karim-en karim-en merged commit cca59b2 into main Jan 31, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OmniBridge]: build contracts using cargo-near
3 participants