Skip to content

Commit

Permalink
refactor: migrate rest of makefile, clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed Sep 8, 2024
1 parent 3d35d9b commit 1c98aee
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 202 deletions.
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,19 @@ incremental = true
lto = "fat"
opt-level = 3
panic = "unwind"
strip = true

# For testing cargo bloat
[profile.release-no-strip]
inherits = "release"
strip = false

# This one optimizes binary size
[profile.release-small]
inherits = "release"
opt-level = "z"
strip = true

[profile.release-big]
inherits = "release"
codegen-units = 16
incremental = true
lto = "thin"
opt-level = 1
panic = "unwind"

[workspace.dependencies]
aleo-std = "=0.1.24"
Expand Down
178 changes: 0 additions & 178 deletions Makefile.toml

This file was deleted.

2 changes: 1 addition & 1 deletion crates/snops/src/persist/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl PersistStorage {

// load accounts json
for name in &self.accounts {
let path = storage_path.join(&format!("{name}.json"));
let path = storage_path.join(format!("{name}.json"));

let res = if *name == *ACCOUNTS_KEY_ID {
read_to_addrs(pick_additional_addr, &path).await
Expand Down
2 changes: 1 addition & 1 deletion crates/snops/src/schema/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl Document {

if let Some(generation) = &self.generate {
for (name, account) in &generation.accounts {
let path = base.join(&format!("{}.json", name));
let path = base.join(format!("{}.json", name));

if !path.exists() {
info!("generating accounts for {name}");
Expand Down
78 changes: 63 additions & 15 deletions crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ enum Command {
InstallUpx,
/// Builds the project
Build(Build),
/// For watching the project and auto-rebuilding
Dev { target: BuildTarget },
}

#[derive(Parser)]
Expand All @@ -53,32 +55,53 @@ impl Build {
fn run(self, sh: &Shell) -> Result<()> {
let profile = self.profile.as_ref();
let package = self.target.as_ref();
// -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
let cmd = cmd!(sh, "cargo build");
let cmd = if matches!(self.target, BuildTarget::All) {
cmd

// if crane lift is enabled, we need to build with nightly
let cmd = if self.cranelift {
cmd!(sh, "cargo +nightly build")
} else {
cmd.arg("-p").arg(package)
cmd!(sh, "cargo build")
};
let cmd = cmd.arg("--profile").arg(profile).arg("-p").arg(package);

let cmd = cmd.arg("--profile").arg(profile);
// let cmd = cmd.arg("--target x86_64-unknown-linux-gnu");
// This is broken idk why
// // if cranelift is enabled, and the target is not AOT, we can pass additional
// // flags
// let cmd = if !matches!(self.target, BuildTarget::Aot) && self.cranelift {
// cmd.arg("-Zbuild-std=std,panic_abort")
// .arg("-Zbuild-std-features=panic_immediate_abort")
// } else {
// cmd
// };

// if cranelift is enabled we need to set the env var, and also specify the
// target
let cmd = if self.cranelift {
cmd.arg("-Zcodegen-backend=cranelift")
// -C panic=abort
cmd.env(
"RUSTFLAGS",
"-Zlocation-detail=none -Zcodegen-backend=cranelift",
)
.arg("--target")
.arg("x86_64-unknown-linux-gnu")
} else {
cmd
};

cmd.run()?;

if self.compress {
let profile = if profile == "dev" { "debug" } else { profile };

cmd!(sh, "upx --best -f --lzma -o ./target/{package}-compressed ./target/x86_64-unknown-linux-gnu/{profile}/{package}").run()?;
}

Ok(())
}
}

#[derive(Clone, ValueEnum)]
enum BuildTarget {
All,
Aot,
Snops,
SnopsAgent,
Expand All @@ -88,8 +111,7 @@ enum BuildTarget {
impl AsRef<str> for BuildTarget {
fn as_ref(&self) -> &str {
match self {
BuildTarget::All => "",
BuildTarget::Aot => "-snarkos-aot",
BuildTarget::Aot => "snarkos-aot",
BuildTarget::Snops => "snops",
BuildTarget::SnopsAgent => "snops-agent",
BuildTarget::SnopsCli => "snops-cli",
Expand All @@ -101,15 +123,15 @@ impl AsRef<str> for BuildTarget {
enum Profile {
ReleaseBig,
ReleaseSmall,
Debug,
Dev,
}

impl AsRef<str> for Profile {
fn as_ref(&self) -> &str {
match self {
Profile::ReleaseBig => "release-big",
Profile::ReleaseSmall => "release-small",
Profile::Debug => "debug",
Profile::Dev => "dev",
}
}
}
Expand All @@ -130,6 +152,7 @@ impl Command {
#[cfg(target_os = "linux")]
Command::InstallUpx => install_upx(sh),
Command::Build(build) => build.run(sh),
Command::Dev { target } => dev(sh, target),
}
}
}
Expand Down Expand Up @@ -187,13 +210,13 @@ fn fmt(sh: &Shell, check: bool) -> Result<()> {
Ok(())
}

fn insall_cargo_subcommands(sh: &Shell, subcmd: &'static str) -> Result<()> {
fn install_cargo_subcommands(sh: &Shell, subcmd: &'static str) -> Result<()> {
cmd!(sh, "cargo install {subcmd} --locked").run()?;
Ok(())
}

fn udeps(sh: &Shell, fix: bool) -> Result<()> {
insall_cargo_subcommands(sh, "cargo-machete")?;
install_cargo_subcommands(sh, "cargo-machete")?;
let cmd = cmd!(sh, "cargo-machete");
let cmd = if fix { cmd.arg("fix") } else { cmd };
cmd.run()?;
Expand Down Expand Up @@ -221,3 +244,28 @@ fn install_upx(sh: &Shell) -> Result<()> {
.run()?;
Ok(())
}

fn dev(sh: &Shell, target: BuildTarget) -> Result<()> {
install_cargo_subcommands(sh, "cargo-watch")?;

match target {
BuildTarget::Aot => cmd!(
sh,
"cargo watch -x 'build -p snarkos-aot --profile release-big' -w ./crates/aot"
)
.run(),
BuildTarget::Snops => cmd!(sh, "cargo watch -x 'run -p snops' -w ./crates/snops").run(),
BuildTarget::SnopsAgent => cmd!(
sh,
"cargo watch -x 'build -p snops-agent --profile release-big' -w ./crates/snops-agent"
)
.run(),
BuildTarget::SnopsCli => cmd!(
sh,
"cargo watch -x 'build -p snops-cli' -w ./crates/snops-cli"
)
.run(),
}?;

Ok(())
}

0 comments on commit 1c98aee

Please sign in to comment.