Skip to content

Commit

Permalink
nightly build plus wasm opt (#17)
Browse files Browse the repository at this point in the history
* fix: add clap-cargo-extra and clean up
* feat: rebuild only when needed
* fix: display filename that errored
* feat: nightly optimizations
* feat: upgrade to use clap-cargo-extra and add transitive deps
* fix(CI): add toolchain file
* chore: update readme and ensure examples are not published

Co-authored-by: Willem Wyndham <[email protected]>
Co-authored-by: Willem Wyndham <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2022
1 parent 3174c8d commit 4bdac75
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 185 deletions.
268 changes: 221 additions & 47 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ anyhow = "1.0.51"

## CLI
clap = {version = "=3.1.8", features = ["derive", "cargo"]}
# escargot = "0.5.7"
clap-cargo = { version = "0.8.0", features = ['cargo_metadata'] }
cargo_metadata = "0.14.2"
clap-cargo-extra = "0.2.0"

## Utilities
once_cell = "1.10.0"
brotli = {version= "3.3.4", features = ["std"] }
bat = "0.21.0"
cargo_metadata = "0.15"
filetime = "0.2.17"

[dev-dependencies]
assert_cmd = "2.0.4"
Expand All @@ -46,6 +45,5 @@ path = "src/lib.rs"
name = "raen"
path = "src/main.rs"

[[bin]]
name = "near-cli-build"
path = "src/main.rs"
# [patch.crates-io]
# clap-cargo-extra = {path = "../clap-cargo-extra"}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ use witgen::witgen;
type Amount = Balance;
```

## Changes

Now including the following in your Cargo.toml will allow projects to include your wit types in their generated wit.

```toml
[package.metadata.witgen]
export = true
```

# Contribute

* Clone this repository
Expand Down
5 changes: 2 additions & 3 deletions examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[package]
name = "rust-counter-tutorial"
version = "0.1.0"
authors = ["Near Inc <[email protected]>"]
edition = "2018"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
brotli = "3.3.4"
near-sdk = { git = "https://github.com/ahalabs/near-sdk-rs", tag = "v4.0.0-4" }
4 changes: 2 additions & 2 deletions examples/rust-status-message-advanced/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "status-message-advanced"
version = "0.1.0"
authors = ["Near Inc <[email protected]>"]
edition = "2018"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
Expand Down
6 changes: 3 additions & 3 deletions examples/rust-status-message/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "status-message"
version = "0.1.0"
authors = ["Near Inc <[email protected]>"]
edition = "2018"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
near-sdk = { git = "https://github.com/ahalabs/near-sdk-rs", tag = "v4.0.0-4" }

witgen-dep = { path = "../witgen-dep"}
2 changes: 2 additions & 0 deletions examples/witgen-dep-dep/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["-C", "link-args=-s"]
14 changes: 14 additions & 0 deletions examples/witgen-dep-dep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "witgen-dep-dep"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
witgen = "0.15.0"

[package.metadata.witgen]
export = true
6 changes: 6 additions & 0 deletions examples/witgen-dep-dep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use witgen::witgen;

#[witgen]
pub struct InnerType {
pub text: String,
}
2 changes: 2 additions & 0 deletions examples/witgen-dep/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["-C", "link-args=-s"]
15 changes: 15 additions & 0 deletions examples/witgen-dep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "witgen-dep"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
witgen = "0.15.0"
witgen-dep-dep = { path = "../witgen-dep-dep" }

[package.metadata.witgen]
export = true
7 changes: 7 additions & 0 deletions examples/witgen-dep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use witgen::witgen;
use witgen_dep_dep::InnerType;

#[witgen]
pub struct TestDep {
pub inner: InnerType,
}
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
targets = ["wasm32-unknown-unknown"]
components = ["rustc", "cargo", "rustfmt", "clippy", "rust-src"]
37 changes: 37 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::{Context, Result};
use cargo_metadata::Package;
use filetime::FileTime;
use std::{fs, path::Path};

pub trait PackageExt {
fn witgen_dep(&self) -> bool;
}

impl PackageExt for Package {
fn witgen_dep(&self) -> bool {
self.metadata
.as_object()
.map_or(false, |metadata| metadata.contains_key("witgen"))
}
}

pub fn get_time(path: &Path) -> Result<FileTime> {
Ok(FileTime::from_last_modification_time(
&fs::metadata(path).context(format!("failed to access {}", path.to_string_lossy()))?,
))
}

pub fn compress_file(p: &Path) -> Result<Vec<u8>> {
let buf = fs::read(p)
.map_err(anyhow::Error::from)
.with_context(|| format!("{}", p.to_string_lossy()))?
.into_boxed_slice();
let mut out = Vec::<u8>::new();
let params = brotli::enc::BrotliEncoderParams {
quality: 11,
..Default::default()
};

brotli::BrotliCompress(&mut buf.as_ref(), &mut out, &params)?;
Ok(out)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod ext;
pub mod raen;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::env;
use anyhow::{Context, Result};
use clap::{crate_version, FromArgMatches, IntoApp};

mod ext;
mod raen;
use crate::raen::Raen;

Expand Down
Loading

0 comments on commit 4bdac75

Please sign in to comment.