Skip to content

Commit

Permalink
feat(zinkc): embed cli in zinkc
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Dec 16, 2023
1 parent 914dc53 commit dd20a84
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 27 deletions.
22 changes: 2 additions & 20 deletions cli/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
# `zinkup`
# `ccli`

The zink components are gathered here, you can install all of the
components directly with:

```bash
cargo install zinkup
```

For installing only specified binaries:

```bash
cargo install zinkup --features elko,zinkc
```

Available binaries:

| Name | Description |
| ------- | ----------------------- |
| `elko` | Zink\'s package manager |
| `zinkc` | The zink compiler |
Common command line interface.

## LICENSE

Expand Down
2 changes: 1 addition & 1 deletion cli/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Common command line inteface.
//! Common command line interface.
use anyhow::Error;
pub use clap::{self, Parser};
Expand Down
2 changes: 1 addition & 1 deletion cli/elko/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ thiserror.workspace = true
toml.workspace = true
tracing.workspace = true
wasm-opt.workspace = true
zinkc.workspace = true
zinkc = { workspace = true, features = [ "cli" ] }
6 changes: 4 additions & 2 deletions cli/elko/src/bin/elko.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Zink's package manager
//! The package manager of zink.
#![deny(missing_docs)]

use ccli::{clap::Subcommand, App, Parser, Result};
use elko::{Build, New};
use elko::{Build, Compile, New};

/// Elko commands
#[derive(Debug, Subcommand)]
enum Command {
New(New),
Build(Build),
Compile(Compile),
}

/// The package manager of zink.
Expand All @@ -31,6 +32,7 @@ impl App for Elko {
match &self.command {
Command::Build(build) => build.run(),
Command::New(new) => new.run(),
Command::Compile(compile) => compile.run(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/elko/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ mod new;
pub mod utils;

pub use self::{build::Build, new::New};
pub use zinkc::cli::Compile;
4 changes: 4 additions & 0 deletions compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[[bin]]
name = "zinkc"
required-features = [ "cli" ]

[dependencies]
anyhow.workspace = true
thiserror.workspace = true
Expand Down
32 changes: 32 additions & 0 deletions compiler/src/bin/zinkc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Zink compiler.
#![deny(missing_docs)]
#![cfg(feature = "cli")]

use ccli::{clap, App, Parser, Result};
use zinkc::cli::Compile;

/// The Zink Compiler.
#[derive(Debug, Parser)]
#[command(name = "zinkc", version, arg_required_else_help(true))]
pub struct Zinkc {
#[clap(flatten)]
command: Compile,
/// Verbose mode (-v, -vv, -vvv, etc.)
#[clap(short, long, action = clap::ArgAction::Count)]
verbose: u8,
}

impl App for Zinkc {
fn verbose(&self) -> u8 {
self.verbose
}

fn run(&self) -> anyhow::Result<()> {
self.command.run()
}
}

/// The main function.
fn main() -> Result<()> {
Zinkc::start()
}
5 changes: 2 additions & 3 deletions compiler/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
#![cfg(feature = "cli")]

use crate::Compiler;
use ccli::{Parser, Result};
use ccli::{clap, Parser};
use std::{env, fs, path::PathBuf};

/// Compile WASM to EVM bytecode.
#[derive(Debug, Parser)]
#[command(name = "build", version)]
pub struct Compile {
/// The path of the wasm file.
#[clap(value_name = "INPUT")]
input: PathBuf,
/// Write output to \<filename\>
/// Write output to <filename>
#[clap(short, long)]
output: Option<PathBuf>,
/// If enable dispatcher.
Expand Down
1 change: 1 addition & 0 deletions compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use crate::{
result::{Error, Result},
};

pub mod cli;
mod compiler;
mod config;
mod parser;
Expand Down

0 comments on commit dd20a84

Please sign in to comment.