Skip to content

Commit 7504898

Browse files
committed
Ignore rust-toolchain in workspace root
1 parent 9c1264d commit 7504898

6 files changed

Lines changed: 26 additions & 13 deletions

File tree

.gitignore

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

24+
**/concordium-out
25+
2426
**/*.nix
2527
**/flake.lock
2628
**/result

cargo-concordium/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Unreleased
44

55
- Support specifying a profile using the `--profile` flag.
6-
- Support for workspaces.
6+
- Building/testing a single package in a workspace is now possible by calling
7+
`cargo concordium` from the smart contract directory in the workspace.
78

89
## 4.2.0
910

cargo-concordium/src/build.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ fn build_in_container(
292292
{
293293
target_dir = target_dir.canonicalize()?;
294294
};
295-
let tar_archive = create_archive(package, workspace_root, &[out_path, tar_path, &target_dir])?;
295+
let toolchain_file = workspace_root.join("rust-toolchain.toml");
296+
let tar_archive = create_archive(
297+
package,
298+
workspace_root,
299+
&[out_path, tar_path, &target_dir, &toolchain_file],
300+
)?;
296301

297302
let archive_hash = sha2::Sha256::digest(&tar_archive.tar_archive);
298303

@@ -1155,7 +1160,9 @@ pub(crate) fn build_and_run_integration_tests(
11551160
};
11561161
crate::handle_build(build_options.clone(), false)?;
11571162
let metadata = get_crate_metadata(&cargo_args)?;
1158-
let package = metadata.root_package().unwrap();
1163+
let package = metadata
1164+
.root_package()
1165+
.context("Unable to determine root package")?;
11591166
let build_info = build_contract(build_options.clone(), &cargo_args, package, &metadata)?;
11601167

11611168
let cargo_args = build_options.cargo_args.clone();
@@ -1443,7 +1450,10 @@ pub fn build_and_run_wasm_test(
14431450
}
14441451
}
14451452

1446-
// NOTE: This seems to not work if there's a rust-toolchain file
1453+
// NOTE: This seems to not work if there's a rust-toolchain file, reproducible
1454+
// builds still fail without proper error messages if a toolchain file is
1455+
// provided without the wasm target.
1456+
//
14471457
/// Checks if the `wasm32-unknown-unknown` target is installed, and returns an
14481458
/// error if not.
14491459
fn check_wasm_target() -> anyhow::Result<()> {

cargo-concordium/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ fn handle_print_build_info(source: PathBuf) -> anyhow::Result<()> {
10151015
Ok(())
10161016
}
10171017

1018+
/// Handles the build of a single package.
10181019
fn handle_package(
10191020
build_info: &BuildInfo,
10201021
options: &BuildOptions,
@@ -1163,24 +1164,23 @@ fn handle_package(
11631164
Ok(())
11641165
}
11651166

1166-
/// Get a list of packages in the workspace from the metadata.
1167-
/// If it's a non-workspace package, get the single package.
1167+
/// Gets the `root_package` from the workspace i.e. the package of the current dir.
1168+
///
1169+
/// It returns a `Vec<Package>` to support getting all the packages in the
1170+
/// workspace if there is no `root_package`.
11681171
fn get_packages(metadata: &Metadata) -> anyhow::Result<Vec<Package>> {
11691172
let root_package = metadata.root_package();
11701173
if let Some(package) = root_package {
11711174
Ok(vec![package.clone()])
11721175
} else {
1173-
let smart_contract_pkgs: Vec<Package> =
1174-
metadata.workspace_packages().into_iter().cloned().collect();
1175-
if smart_contract_pkgs.is_empty() {
1176-
Ok(smart_contract_pkgs)
1177-
} else {
1178-
bail!("Error: No package found!");
1179-
}
1176+
bail!("Error: No package found!");
11801177
}
11811178
}
11821179

11831180
/// Build the smart contract module using the provided options.
1181+
/// If it's in a workspace context it will build the smart contract in the
1182+
// current directory, if one exists otherwise it will build all smart contracts
1183+
// in the workspace.
11841184
///
11851185
/// This method is used by both the build and test command.
11861186
/// When building, i.e. when running `cargo concordium build`, the schema
-19.7 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)