Compare commits

...

10 Commits

Author SHA1 Message Date
Cainã Costa 622b0d51b0 chore: update flake 2023-07-27 10:23:10 -04:00
Cainã Costa acbbcc7f72 chore[nix]: remove unused cargoBuildFlags
We are overriding the buildPhase, so no need to have that anymore.
2023-07-27 10:23:10 -04:00
Cainã Costa 529749f204 feat[nix]: add cargo-insta
It was not packaged before on nixpkgs, it is now, so let's use it.
2023-07-27 10:23:10 -04:00
Cainã Costa a1d7a29482 chore: remove unused deno dependency 2023-07-27 10:23:10 -04:00
Cainã Costa c4810e7035 fix: use pure mkShell for devShell
For some reason, having mkShell with the interface they used makes the
environment not consistent. This changes fixes it.
2023-07-27 10:23:10 -04:00
Cainã Costa 49cc76cf77 chore: cargo fmt 2023-07-25 14:00:29 -04:00
Cainã Costa a0f0c20f03 feat: add completions to generated nix package 2023-07-25 14:00:29 -04:00
Cainã Costa 2cecb099d7 feat: add a generator for shell completions 2023-07-25 14:00:29 -04:00
Cainã Costa eac27eff41 feat: add nix overlay
This allows for easier usage of aiken on both NixOS and home-manager
setups, without having to add them to the main nixos repository.
2023-07-25 00:30:36 -04:00
rvcas 152e847e26
chore: no longer need this env var 2023-07-24 10:30:02 -04:00
8 changed files with 135 additions and 88 deletions

10
Cargo.lock generated vendored
View File

@ -59,6 +59,7 @@ dependencies = [
"anyhow", "anyhow",
"built", "built",
"clap", "clap",
"clap_complete",
"hex", "hex",
"ignore", "ignore",
"indoc", "indoc",
@ -493,6 +494,15 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "clap_complete"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fc443334c81a804575546c5a8a79b4913b50e28d69232903604cada1de817ce"
dependencies = [
"clap",
]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.2.0" version = "4.2.0"

View File

@ -31,6 +31,7 @@ aiken-lang = { path = "../aiken-lang", version = "1.0.13-alpha" }
aiken-lsp = { path = "../aiken-lsp", version = "1.0.13-alpha" } aiken-lsp = { path = "../aiken-lsp", version = "1.0.13-alpha" }
aiken-project = { path = '../aiken-project', version = "1.0.13-alpha" } aiken-project = { path = '../aiken-project', version = "1.0.13-alpha" }
uplc = { path = '../uplc', version = "1.0.13-alpha" } uplc = { path = '../uplc', version = "1.0.13-alpha" }
clap_complete = "4.3.2"
[build-dependencies] [build-dependencies]
built = { version = "0.6.0", features = ["git2"] } built = { version = "0.6.0", features = ["git2"] }

View File

@ -0,0 +1,33 @@
use clap::{Command, Subcommand};
use clap_complete::{generate, Shell};
use crate::cmd::Cmd as MainCmd;
/// Generates shell completion scripts
#[derive(Subcommand)]
pub enum Cmd {
Bash,
Zsh,
Fish,
}
pub fn exec(sub_cmd: Cmd) -> miette::Result<()> {
let shell = match sub_cmd {
Cmd::Bash => Shell::Bash,
Cmd::Zsh => Shell::Zsh,
Cmd::Fish => Shell::Fish,
};
let cli = Command::new("aiken").disable_version_flag(true);
let mut main = MainCmd::augment_subcommands(cli);
generate(
shell,
&mut main,
"aiken".to_string(),
&mut std::io::stdout(),
);
Ok(())
}

View File

@ -1,6 +1,9 @@
use clap::Parser;
pub mod blueprint; pub mod blueprint;
pub mod build; pub mod build;
pub mod check; pub mod check;
pub mod completion;
pub mod docs; pub mod docs;
pub mod fmt; pub mod fmt;
pub mod lsp; pub mod lsp;
@ -8,3 +11,51 @@ pub mod new;
pub mod packages; pub mod packages;
pub mod tx; pub mod tx;
pub mod uplc; pub mod uplc;
use crate::built_info;
/// Aiken: a smart-contract language and toolchain for Cardano
#[derive(Parser)]
#[clap(version = version(), about, long_about = None)]
#[clap(propagate_version = true)]
pub enum Cmd {
New(new::Args),
Fmt(fmt::Args),
Build(build::Args),
Address(blueprint::address::Args),
Check(check::Args),
Docs(docs::Args),
Add(packages::add::Args),
#[clap(subcommand)]
Blueprint(blueprint::Cmd),
#[clap(subcommand)]
Packages(packages::Cmd),
#[clap(subcommand)]
Tx(tx::Cmd),
#[clap(subcommand)]
Uplc(uplc::Cmd),
#[clap(subcommand)]
Completion(completion::Cmd),
#[clap(hide = true)]
Lsp(lsp::Args),
}
impl Default for Cmd {
fn default() -> Self {
Self::parse()
}
}
fn version() -> String {
format!(
"v{} {}",
built_info::PKG_VERSION,
built_info::GIT_COMMIT_HASH_SHORT.unwrap_or("unknown")
)
}

View File

@ -22,7 +22,7 @@ pub struct Args {
#[clap(long)] #[clap(long)]
pub version: String, pub version: String,
#[clap(hide = true)] #[clap(hide = true, long)]
pub overwrite: bool, pub overwrite: bool,
} }

View File

@ -1,50 +1,12 @@
use aiken::{ use aiken::cmd::{
built_info, blueprint::{self, address},
cmd::{ build, check, completion, docs, fmt, lsp, new,
blueprint::{self, address}, packages::{self, add},
build, check, docs, fmt, lsp, new, tx, uplc, Cmd,
packages::{self, add},
tx, uplc,
},
}; };
use clap::Parser;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
/// Aiken: a smart-contract language and toolchain for Cardano
#[derive(Parser)]
#[clap(version = version(), about, long_about = None)]
#[clap(propagate_version = true)]
pub enum Cmd {
New(new::Args),
Fmt(fmt::Args),
Build(build::Args),
Address(address::Args),
Check(check::Args),
Docs(docs::Args),
Add(add::Args),
#[clap(subcommand)]
Blueprint(blueprint::Cmd),
#[clap(subcommand)]
Packages(packages::Cmd),
#[clap(subcommand)]
Tx(tx::Cmd),
#[clap(subcommand)]
Uplc(uplc::Cmd),
#[clap(hide = true)]
Lsp(lsp::Args),
}
impl Default for Cmd {
fn default() -> Self {
Self::parse()
}
}
fn main() -> miette::Result<()> { fn main() -> miette::Result<()> {
panic_handler(); panic_handler();
@ -61,20 +23,10 @@ fn main() -> miette::Result<()> {
Cmd::Lsp(args) => lsp::exec(args), Cmd::Lsp(args) => lsp::exec(args),
Cmd::Tx(sub_cmd) => tx::exec(sub_cmd), Cmd::Tx(sub_cmd) => tx::exec(sub_cmd),
Cmd::Uplc(sub_cmd) => uplc::exec(sub_cmd), Cmd::Uplc(sub_cmd) => uplc::exec(sub_cmd),
Cmd::Completion(sub_cmd) => completion::exec(sub_cmd),
} }
} }
fn version() -> String {
use std::env;
let nix_git_rev = env::var("GIT_REVISION").unwrap_or("unknown".to_string());
format!(
"v{} {}",
built_info::PKG_VERSION,
built_info::GIT_COMMIT_HASH_SHORT.unwrap_or(&nix_git_rev)
)
}
fn panic_handler() { fn panic_handler() {
std::panic::set_hook(Box::new(move |info| { std::panic::set_hook(Box::new(move |info| {
let message = info let message = info

18
flake.lock generated vendored
View File

@ -5,11 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1681202837, "lastModified": 1689068808,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401", "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -38,11 +38,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1682773483, "lastModified": 1690463849,
"narHash": "sha256-FN7Zf+gQpYQUzt9LeJv6yGnvbqaBb97RjFtNnfu9OB4=", "narHash": "sha256-n/ej009hs6+q/wxPR+OlYrNMXXv9qVK+FRyl7IyDuG0=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d7fa40f31e8c8fa46f5d06b0cd0cb02f0d4c3fa0", "rev": "3173ae5d63ebd44ce99b70965557906800a1fb02",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -80,11 +80,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1682734733, "lastModified": 1690424156,
"narHash": "sha256-oAoNMgWQveSF1Vv16OJ2GVU+BGGdzazTHpPu/VKy/BQ=", "narHash": "sha256-Bpml+L280tHTQpwpC5/BJbU4HSvEzMvW8IZ4gAXimhE=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "0bb45c519ebd64f6b4223e1bb6b4e08df80834ca", "rev": "f335a0213504c7e6481c359dc1009be9cf34432c",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -17,8 +17,6 @@
lib.optionals stdenv.isDarwin lib.optionals stdenv.isDarwin
[ darwin.apple_sdk.frameworks.Security ]; [ darwin.apple_sdk.frameworks.Security ];
deno = nixpkgs.legacyPackages.${system}.deno;
cargoTomlContents = builtins.readFile ./crates/aiken/Cargo.toml; cargoTomlContents = builtins.readFile ./crates/aiken/Cargo.toml;
version = (builtins.fromTOML cargoTomlContents).package.version; version = (builtins.fromTOML cargoTomlContents).package.version;
@ -29,12 +27,22 @@
buildInputs = with pkgs; [ openssl ] ++ osxDependencies; buildInputs = with pkgs; [ openssl ] ++ osxDependencies;
nativeBuildInputs = with pkgs; [ pkg-config openssl.dev ]; nativeBuildInputs = with pkgs; [ pkg-config openssl.dev ];
cargoBuildFlags = [ "--package aiken" ];
src = pkgs.lib.cleanSourceWith { src = self; }; src = pkgs.lib.cleanSourceWith { src = self; };
cargoLock.lockFile = ./Cargo.lock; cargoLock.lockFile = ./Cargo.lock;
postInstall = ''
mkdir -p $out/share/zsh/site-functions
$out/bin/aiken completion zsh > $out/share/zsh/site-functions/_aiken
mkdir -p $out/share/bash-completion/completions
$out/bin/aiken completion bash > $out/share/bash-completion/completions/aiken
mkdir -p $out/share/fish/vendor_completions.d
$out/bin/aiken completion fish > $out/share/fish/vendor_completions.d/aiken.fish
'';
meta = with pkgs.lib; { meta = with pkgs.lib; {
description = "Cardano smart contract language and toolchain"; description = "Cardano smart contract language and toolchain";
homepage = "https://github.com/aiken-lang/aiken"; homepage = "https://github.com/aiken-lang/aiken";
@ -43,37 +51,29 @@
}; };
}; };
commonCategory = y: builtins.map (x: x // { category = y; });
packages = { packages = {
aiken = aiken; aiken = aiken;
default = packages.aiken; default = packages.aiken;
}; };
aikenCmds = commonCategory "Aiken Development" [{ overlays.default = final: prev: { aiken = packages.aiken; };
name = "aiken";
help = "Aiken toolchain";
package = packages.aiken;
}];
gitRev = if (builtins.hasAttr "rev" self) then self.rev else "dirty"; gitRev = if (builtins.hasAttr "rev" self) then self.rev else "dirty";
in { in {
inherit packages; inherit packages overlays;
devShells.aiken = pkgs.mkShell { devShell = pkgs.mkShell {
name = "aiken"; buildInputs = with pkgs;
motd = '' [
Aiken pkg-config
$(type -p menu &>/dev/null && menu)''; openssl
commands = aikenCmds;
packages = [ cargo-insta
deno
(pkgs.rust-bin.stable.latest.default.override { (pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "clippy" "rustfmt" ]; extensions = [ "rust-src" "clippy" "rustfmt" ];
}) })
] ++ osxDependencies; ] ++ osxDependencies;
shellHook = '' shellHook = ''
export GIT_REVISION=${gitRev} export GIT_REVISION=${gitRev}