Skip to content

Commit

Permalink
chore: make it so we can opt w/o docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed May 30, 2024
1 parent 562cbaa commit 5d36285
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 6 deletions.
9 changes: 4 additions & 5 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --bin schema"

[net]
git-fetch-with-cli = true
unit-test = "test --lib"
wasm = "run --package xtask -- wasm"
wasm-opt = "run --package xtask -- wasm-opt"
xtask = "run --package xtask --"
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"contract",
# "fuzz",
"xtask",
]

[profile.release]
Expand All @@ -17,6 +18,7 @@ incremental = false
overflow-checks = true

[workspace.dependencies]
anyhow = "1.0"
arbitrary = "1.3"
cosmwasm-schema = "1.5"
cosmwasm-std = { version = "1.5" }
Expand All @@ -37,4 +39,5 @@ serde_json = "1.0"
sha3 = "0.10"
thiserror = { version = "1.0" }
semver = { version = "1.0", features = ["serde"] }
vrf-rs = { version = "0.0.0" }
vrf-rs = "0.0.0"
xshell = "0.2"
9 changes: 9 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"


[dependencies]
anyhow.workspace = true
xshell.workspace = true
66 changes: 66 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::{env, process::Command};

use anyhow::{bail, Context, Result};
use xshell::{cmd, Shell};

fn main() {
if let Err(e) = try_main() {
eprintln!("{e}");
std::process::exit(1);
}
}

const TASKS: &[&str] = &["help", "wasm"];

fn try_main() -> Result<()> {
// Ensure our working directory is the toplevel
{
let toplevel_path = Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.output()
.context("Invoking git rev-parse")?;
if !toplevel_path.status.success() {
bail!("Failed to invoke git rev-parse");
}
let path = String::from_utf8(toplevel_path.stdout)?;
std::env::set_current_dir(path.trim()).context("Changing to toplevel")?;
}

let task = env::args().nth(1);
let sh = Shell::new()?;
match task.as_deref() {
Some("help") => print_help()?,
Some("wasm") => wasm(&sh)?,
Some("wasm-opt") => wasm_opt(&sh)?,
_ => print_help()?,
}

Ok(())
}

fn print_help() -> Result<()> {
println!("Tasks:");
for name in TASKS {
println!(" - {name}");
}
Ok(())
}

fn wasm(sh: &Shell) -> Result<()> {
cmd!(
sh,
"cargo build --release --lib --target wasm32-unknown-unknown --locked"
)
.env("RUSTFLAGS", "-C link-arg=-s")
.run()?;
Ok(())
}

fn wasm_opt(sh: &Shell) -> Result<()> {
wasm(sh)?;
cmd!(
sh,
"wasm-opt -Os --signext-lowering target/wasm32-unknown-unknown/release/seda_contract.wasm -o target/seda_contract.wasm"
).run()?;
Ok(())
}

0 comments on commit 5d36285

Please sign in to comment.