Skip to content

Commit b1c3af2

Browse files
committed
Self review and changelog
1 parent a91d1d7 commit b1c3af2

7 files changed

Lines changed: 28 additions & 27 deletions

File tree

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ pkg
2121
*.state
2222
**/.idea
2323

24-
*.nix
25-
flake.lock
24+
**/*.nix
25+
**/flake.lock
26+
**/result

cargo-concordium/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Support specifying a profile using the `--profile` flag.
6+
- Support for workspaces.
7+
38
## 4.2.0
49

510
- Unit tests now run in parallel and the results are printed sequentially. Pass

cargo-concordium/src/build.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ fn to_snake_case(string: &str) -> String {
5555

5656
/// Get the crate's metadata either by looking for the `Cargo.toml` file at the
5757
/// `--manifest-path` or at the ancestors of the current directory.
58-
///
59-
/// If successful, the return value is a pair of metadata and all of the
60-
/// `cargo_args` except the `--manifest-path` and the path to the manifest file.
61-
/// This last part is used for reproducible builds. There we want to keep the
62-
/// remaining `cargo` arguments, but the manifest path does not make sense since
63-
/// the project is built from a specific location inside the container.
6458
pub fn get_crate_metadata(cargo_args: &[String]) -> anyhow::Result<Metadata> {
6559
let mut cmd = MetadataCommand::new();
6660
let mut args = cargo_args
@@ -170,7 +164,6 @@ fn create_archive(
170164
for file in files {
171165
let file = file?;
172166
let file_path = file.path();
173-
println!("{file_path:?}");
174167
if file_path == workspace_root || omit_files.iter().any(|f| file_path.starts_with(f)) {
175168
// We don't want to add the root path since we are adding all
176169
// relative paths under it.
@@ -268,16 +261,18 @@ struct ContainerBuildOutput {
268261
/// tar archive. The arguments are
269262
///
270263
/// - `image`, the docker image that will be used to build.
271-
/// - `package_target_dir`,
272-
/// - `package_root_path`,
264+
/// - `package`, the package to build.
265+
/// - `package_root_path`, the cargo metadata object.
273266
/// - `extra_args`, the extra arguments to pass to the cargo build command.
274267
/// - `container_runtime`, the container runtime to use, e.g. `docker` or
275268
/// `podman`
276-
/// - `out_path`, - the path to the out file for the wasm artifact. This should
269+
/// - `out_path`, the path to the out file for the wasm artifact. This should
277270
/// be a fully expanded, canonical path.
278-
/// - `tar_path`, - the path to the tar archive. This should be a fully
271+
/// - `tar_path`, the path to the tar archive. This should be a fully
279272
/// expanded, canonical path.
280-
fn build_in_container<'a>(
273+
/// - `source_link`, the link to where the source code will be located
274+
#[allow(clippy::too_many_arguments)]
275+
fn build_in_container(
281276
image: String,
282277
package: &Package,
283278
metadata: &Metadata,
@@ -307,7 +302,7 @@ fn build_in_container<'a>(
307302
locked: true,
308303
features: &[],
309304
package: Some(&package.name),
310-
extra_args: &extra_args,
305+
extra_args,
311306
}
312307
.get_cargo_cmd_as_strings()?;
313308

@@ -376,7 +371,6 @@ fn build_in_container<'a>(
376371
///
377372
/// Note that even if a verifiable build is requested the schemas are built on
378373
/// the host machine.
379-
#[allow(clippy::too_many_arguments)]
380374
pub(crate) fn build_contract(
381375
options: BuildOptions,
382376
cargo_args: &[String],
@@ -526,7 +520,7 @@ pub(crate) fn build_contract(
526520
} = build_in_container(
527521
image,
528522
package,
529-
&metadata,
523+
metadata,
530524
&args_without_manifest,
531525
&container_runtime,
532526
&out_filename,
@@ -774,11 +768,10 @@ pub fn build_contract_schema<A>(
774768
anyhow::bail!("Compilation failed.");
775769
}
776770

777-
let filename = format!(
778-
"{}/wasm32-unknown-unknown/release/{}.wasm",
779-
target_dir,
780-
to_snake_case(package.name.as_str())
781-
);
771+
let filename = target_dir
772+
.join("wasm32-unknown-unknown")
773+
.join("release")
774+
.join(format!("{}.wasm", to_snake_case(package.name.as_str())));
782775

783776
if !skip_wasm_opt {
784777
wasm_opt::OptimizationOptions::new_opt_level_0()
@@ -1493,6 +1486,7 @@ struct CargoBuildParameters<'a> {
14931486
}
14941487

14951488
impl<'a> CargoBuildParameters<'a> {
1489+
/// Get the cargo arguments as a list of strings, i.e. `Vec!["cargo", "build", ...]`.
14961490
fn get_cargo_cmd_as_strings(&self) -> anyhow::Result<Vec<String>> {
14971491
let mut args = vec![
14981492
"cargo",
@@ -1524,6 +1518,7 @@ impl<'a> CargoBuildParameters<'a> {
15241518
Ok(args)
15251519
}
15261520

1521+
/// Run the `cargo build` command with the specified parameters.
15271522
fn run_cargo_cmd(&self) -> anyhow::Result<std::process::Output> {
15281523
let mut args = self.get_cargo_cmd_as_strings()?;
15291524
let executable = args.remove(0); // "cargo"

cargo-concordium/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl v0::HasReceiveContext for ReceiveContextV1Opt {
195195
}
196196

197197
impl v1::HasReceiveContext for ReceiveContextV1Opt {
198-
fn entrypoint(&self) -> ExecResult<EntrypointName> {
198+
fn entrypoint(&self) -> ExecResult<EntrypointName<'_>> {
199199
let ep = unwrap_ctx_field(self.entrypoint.as_ref(), "entrypoint")?;
200200
Ok(ep.as_entrypoint_name())
201201
}

cargo-concordium/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ fn handle_package(
10771077
fs::write(schema_out, &module_schema_bytes).context("Could not write schema file.")?;
10781078
}
10791079
if let Some(schema_json_out) = &options.schema_json_out {
1080-
write_json_schema(&schema_json_out, module_schema)
1080+
write_json_schema(schema_json_out, module_schema)
10811081
.context("Could not write JSON schema files.")?;
10821082
}
10831083
if let Some(schema_template_out) = &options.schema_template_out {
@@ -1163,14 +1163,16 @@ fn handle_package(
11631163
Ok(())
11641164
}
11651165

1166+
/// Get a list of packages in the workspace from the metadata.
1167+
/// If it's a non-workspace package, get the single package.
11661168
fn get_packages(metadata: &Metadata) -> anyhow::Result<Vec<Package>> {
11671169
let root_package = metadata.root_package();
11681170
if let Some(package) = root_package {
11691171
Ok(vec![package.clone()])
11701172
} else {
11711173
let smart_contract_pkgs: Vec<Package> =
11721174
metadata.workspace_packages().into_iter().cloned().collect();
1173-
if smart_contract_pkgs.len() != 0 {
1175+
if smart_contract_pkgs.is_empty() {
11741176
Ok(smart_contract_pkgs)
11751177
} else {
11761178
bail!("Error: No package found!");

reproducible/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

reproducible/run-copy.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ shift 2
2222
# execute the supplied command which consists of everything apart from the first
2323
# 2 arguments to the `run-copy` script.
2424
"$@"
25-
ls "$BUILD_DIR"
2625
mv "$BUILD_DIR"/*.wasm "$TMP"/out.wasm
2726
wasm-opt -O0 -o /artifacts/out.wasm "$TMP"/out.wasm

0 commit comments

Comments
 (0)