Skip to content

Commit b9fd33a

Browse files
sanityple1n
andauthored
fdev: log build steps with tracing (supersedes #1756) (#1757)
Co-authored-by: plein <68096727+planetoryd@users.noreply.github.com>
1 parent d4fa97b commit b9fd33a

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fdev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ license-file = "LICENSE.md"
99
repository = "https://github.com/freenet/freenet"
1010

1111
[dependencies]
12+
bytesize = "1.3"
1213
anyhow = "1"
1314
axum = { default-features = false, features = ["http1", "matched-path", "query", "tower-log", "ws"], workspace = true }
1415
bincode = "1"

crates/fdev/src/build.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bytesize::ByteSize;
12
use freenet::server::WebApp;
23
use serde::{Deserialize, Serialize};
34
use serde_with::skip_serializing_none;
@@ -102,14 +103,20 @@ fn compile_rust_wasm_lib(cli_config: &BuildToolConfig, work_dir: &Path) -> anyho
102103
};
103104

104105
let package_type = cli_config.package_type;
105-
println!("Compiling {package_type} with rust");
106+
tracing::info!("Compiling {package_type} with rust, args: {:?}", cmd_args);
106107

107108
// Set CARGO_TARGET_DIR if not already set to ensure consistent output location
108109
let mut command = Command::new("cargo");
109110
if env::var("CARGO_TARGET_DIR").is_err() {
110111
command.env("CARGO_TARGET_DIR", get_workspace_target_dir());
111112
}
112113

114+
tracing::info!(
115+
command = ?"cargo",
116+
args = ?cmd_args,
117+
"Executing cargo command"
118+
);
119+
113120
let child = command
114121
.args(&cmd_args)
115122
.current_dir(work_dir)
@@ -186,7 +193,7 @@ mod contract {
186193
build_web_state(&config, embedded, cwd)?
187194
}
188195
ContractType::Standard => {
189-
println!("Packaging generic contract type");
196+
tracing::warn!("Packaging generic contract type");
190197
build_generic_state(&mut config, cwd)?
191198
}
192199
}
@@ -425,13 +432,20 @@ mod contract {
425432
.map(Ok)
426433
.unwrap_or_else(|| get_default_ouput_dir(cwd).map(|p| p.join(DEFAULT_OUTPUT_NAME)))?;
427434

428-
println!("Bundling contract state");
435+
tracing::info!("Bundling contract state");
429436
let state: PathBuf = (sources.len() == 1)
430437
.then(|| sources.pop().unwrap())
431438
.ok_or_else(|| Error::MissConfiguration(REQ_ONE_FILE_ERR.into()))?
432439
.into();
433-
std::fs::copy(cwd.join(state), output_path)?;
434-
println!("Finished bundling state");
440+
let src_path = cwd.join(&state);
441+
let bytes_written = std::fs::copy(&src_path, &output_path)?;
442+
let human_size = bytesize::ByteSize(bytes_written).to_string();
443+
tracing::info!(
444+
path = ?output_path,
445+
human_size = %human_size,
446+
"Wrote contract state file"
447+
);
448+
tracing::info!("Finished bundling state");
435449
Ok(())
436450
}
437451

@@ -483,8 +497,15 @@ mod contract {
483497
get_default_ouput_dir(cwd)?.join(package_name)
484498
};
485499
let output = get_versioned_contract(&output_lib, cli_config)?;
486-
let mut file = File::create(out_file)?;
500+
let mut file = File::create(&out_file)?;
487501
file.write_all(output.as_slice())?;
502+
let size = output.len();
503+
let human_size = ByteSize(size as u64).to_string();
504+
tracing::info!(
505+
path = ?out_file,
506+
size = %human_size,
507+
"Wrote contract output file"
508+
);
488509
}
489510
None => println!("no lang specified, skipping contract compilation"),
490511
}

0 commit comments

Comments
 (0)