Skip to content

Commit

Permalink
changes linera project new so that binary files uses underscores in…
Browse files Browse the repository at this point in the history
…stead of dashes (#1454)
  • Loading branch information
ma2bd authored Jan 9, 2024
1 parent 99e6a65 commit 0f501d6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions linera-service/src/cli_wrappers/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@ impl ClientWrapper {
let contract = release_dir.join(format!("{}_contract.wasm", name.replace('-', "_")));
let service = release_dir.join(format!("{}_service.wasm", name.replace('-', "_")));

let contract_size = tokio::fs::metadata(&contract)
.await
.with_context(|| format!("Cannot find bytecode file {contract:?}"))?
.len();
let service_size = tokio::fs::metadata(&service)
.await
.with_context(|| format!("Cannot find bytecode file {service:?}"))?
.len();
info!("Done building application {name}: contract_size={contract_size}, service_size={service_size}");

Ok((contract, service))
}
}
Expand Down
3 changes: 2 additions & 1 deletion linera-service/src/linera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,8 @@ enum ProjectCommand {
/// This is used to locate the generated bytecode. The generated bytecode should
/// be of the form `<name>_{contract,service}.wasm`.
///
/// Defaults to the package name in Cargo.toml.
/// Defaults to the package name in Cargo.toml, with dashes replaced by
/// underscores.
name: Option<String>,

/// An optional chain ID to publish the bytecode. The default chain of the wallet
Expand Down
10 changes: 9 additions & 1 deletion linera-service/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ impl Project {
) -> Result<()> {
let toml_path = project_root.join("Cargo.toml");
let (linera_sdk_dep, linera_sdk_dev_dep) = Self::linera_sdk_dependencies(linera_root);
let binary_root_name = project_name.replace('-', "_");
let contract_binary_name = format!("{binary_root_name}_contract");
let service_binary_name = format!("{binary_root_name}_service");
let toml_contents = format!(
include_str!("../template/Cargo.toml.template"),
project_name = project_name,
contract_binary_name = contract_binary_name,
service_binary_name = service_binary_name,
linera_sdk_dep = linera_sdk_dep,
linera_sdk_dev_dep = linera_sdk_dev_dep,
);
Expand Down Expand Up @@ -253,7 +258,10 @@ impl Project {
}

pub fn build(&self, name: Option<String>) -> Result<(PathBuf, PathBuf), anyhow::Error> {
let name = name.unwrap_or(self.project_package_name()?);
let name = match name {
Some(name) => name,
None => self.project_package_name()?.replace('-', "_"),
};
let contract_name = format!("{}_contract", name);
let service_name = format!("{}_service", name);
let cargo_build = Command::new("cargo")
Expand Down
4 changes: 2 additions & 2 deletions linera-service/template/Cargo.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ thiserror = "1.0.38"
webassembly-test = "0.1.0"

[[bin]]
name = "{project_name}_contract"
name = "{contract_binary_name}"
path = "src/contract.rs"

[[bin]]
name = "{project_name}_service"
name = "{service_binary_name}"
path = "src/service.rs"

[profile.release]
Expand Down

0 comments on commit 0f501d6

Please sign in to comment.