Skip to content

Commit

Permalink
Merge 28a0a1a into e1b1c2b
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel authored Jul 3, 2024
2 parents e1b1c2b + 28a0a1a commit 0c7ff0b
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 6 deletions.
196 changes: 192 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions forc-pkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository.workspace = true
[dependencies]
ansi_term = "0.12"
anyhow = "1"
byte-unit = "5.1.4"
cid = "0.10"
forc-tracing = { version = "0.61.2", path = "../forc-tracing" }
forc-util = { version = "0.61.2", path = "../forc-util" }
Expand Down
21 changes: 19 additions & 2 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
BuildProfile,
};
use anyhow::{anyhow, bail, Context, Error, Result};
use byte_unit::{Byte, UnitType};
use forc_tracing::{println_action_green, println_warning};
use forc_util::{
default_output_directory, find_file_name, kebab_to_snake_case, print_compiling,
Expand Down Expand Up @@ -497,7 +498,11 @@ impl BuiltPackage {
let json_abi_path = output_dir.join(program_abi_stem).with_extension("json");
self.write_json_abi(&json_abi_path, minify)?;

debug!(" Bytecode size: {} bytes", self.bytecode.bytes.len());
debug!(
" Bytecode size: {} bytes ({})",
self.bytecode.bytes.len(),
format_bytecode_size(self.bytecode.bytes.len())
);
// Additional ops required depending on the program type
match self.tree_type {
TreeType::Contract => {
Expand Down Expand Up @@ -2107,6 +2112,12 @@ fn profile_target_string(profile_name: &str, build_target: &BuildTarget) -> Stri
};
format!("{profile_name} [{}] target(s)", targets.join(" + "))
}
/// Returns the size of the bytecode in a human-readable format.
pub fn format_bytecode_size(bytes_len: usize) -> String {
let size = Byte::from_u64(bytes_len as u64);
let adjusted_byte = size.get_appropriate_unit(UnitType::Decimal);
adjusted_byte.to_string()
}

/// Check if the given node is a contract dependency of any node in the graph.
fn is_contract_dependency(graph: &Graph, node: NodeIx) -> bool {
Expand Down Expand Up @@ -2173,12 +2184,17 @@ pub fn build_with_options(build_options: &BuildOpts) -> Result<Built> {
},
)?;
let output_dir = pkg.output_directory.as_ref().map(PathBuf::from);
let total_size = built_packages
.iter()
.map(|(_, pkg)| pkg.bytecode.bytes.len())
.sum::<usize>();

println_action_green(
"Finished",
&format!(
"{} in {:.2}s",
"{} [{}] in {:.2}s",
profile_target_string(&build_profile.name, build_target),
format_bytecode_size(total_size),
build_start.elapsed().as_secs_f32()
),
);
Expand Down Expand Up @@ -2294,6 +2310,7 @@ pub fn build(

let mut lib_namespace_map = HashMap::default();
let mut compiled_contract_deps = HashMap::new();

for &node in plan
.compilation_order
.iter()
Expand Down

0 comments on commit 0c7ff0b

Please sign in to comment.