GithubHelp home page GithubHelp logo

gear-foundation / cargo-program Goto Github PK

View Code? Open in Web Editor NEW
1.0 5.0 0.0 230 KB

Utility to simplify Gear programs development

License: GNU General Public License v3.0

Makefile 9.42% Rust 90.58%

cargo-program's Introduction

cargo-program

CI Status License crates.io

Utility to simplify Gear programs development.

โš ๏ธ The project is currently under active development. Some features may be unstable.

Install

  • (recommended) Latest version from the repo:
cargo install --git https://github.com/gear-tech/cargo-program.git
cargo install cargo-program

Usage

Create a new Gear program

cargo program new my-program

Create a new async Gear program

cargo program new my-async-program --async

Build the Gear program

cargo program build

๐Ÿšง (in progress) Run the Gear program on-chain using the local node

cargo program run

... or specifying the running script:

cargo program run --script run.rhai

... or specifying the node's URL:

cargo program run --node "ws://127.0.0.1:9944"

๐Ÿšง (in progress) Run tests

cargo program test

๐Ÿšง (in progress) Login to the Gear backend

cargo program login
# or
cargo program login --host https://my-gear-backend.tld:8123

๐Ÿšง (in progress) Publish the Gear program to the chain

cargo program publish

License

cargo-program is licensed under GPL v3.0 with a classpath linking exception.

cargo-program's People

Contributors

shamilsan avatar dependabot[bot] avatar

Stargazers

Nikolay Volf avatar

Watchers

Andrey Neporada avatar Nikolay Volf avatar Eugene Way avatar  avatar  avatar

cargo-program's Issues

Replace `gear-wasm-builder` with another solution

Problem to Solve

gear-wasm-builder is fine for a single contract, but it becomes a real problem for big workspaces like gear-foundation/dapps. And there's also a lot of other small issues that can be considered reasons to completely replace it with another solution.

  1. For each contract, Cargo builds a separate executable with a build script, and since gear-wasm-builder isn't very lightweight, almost every one of them turns out to be a couple dozen megabytes. In case of the dapps repo, they consume around 9 gigabytes of storage out of 16 gigabytes of the build cache after a clean repo clone & cargo c, and with code changes, they can take even more storage.
  2. gear-wasm-builder runs on each check & compiles only in the release mode. Thus, even on a change of one line of code, gear-wasm-builder forcibly recompiles a contract before letting Cargo do a check. Yes, we have the __GEAR_WASM_BUILDER_NO_BUILD environment variable, but because it disables all gear-wasm-builder's checks, this isn't a really good solution.
  3. gear-wasm-builder doesn't work well with rust-analyzer because it can't parse compilation errors from the build script output.
  4. For some reason, gear-wasm-builder doesn't use all CPU while performing a build.
  5. Build scripts aren't really convenient for a customization because the only way to pass some arguments to them is through environment variables or a code change & recompilation.
  6. .binpath files like any build artifacts shouldn't be placed anywhere except the target directory. I managed to move *.meta.txts to it, but .binpath is trickier since it's used by gtest.

So, in overall, the current solution for the contract building is very heavy & slow. I suppose some of these issues can be fixed pretty easily, but I really wish there'd be a more elegant

Possible Solution

like cargo-contract. Actually @shamilsan worked on a similar tool: cargo-program - but it was abandoned. I propose to revive this project & try to fix all the issues above by not repeating them in it & switching to it.

Notes

No response

Add support for Rhai script for testing programs

Problem to Solve

We need to describe a running scenario for in-chain testing (using local dev-node). The best choice seems to be the Rhai script (https://rhai.rs/).

Possible Solution

Script example:

let init_msg = #{
    name: "Smith",
    age: 42,
};

let prog = program();
prog.salt = salt("new salt");
print("Program ID:", prog.id);

submit_program(prog, init_msg);

let msg = #{
    currency: "GEAR",
    value: 11,
};

let msg_id = send_message(prog_id, msg, gas(1_000_000));

let reply = get_from_mailbox(msecs(5000));

assert_eq(reply.dest, me());
assert_eq(reply.to, msg_id);
assert_eq(reply.payload, "success");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.