Skip to content
This repository has been archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
Build features (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 authored Mar 5, 2024
1 parent ad58970 commit 0e33fb1
Show file tree
Hide file tree
Showing 15 changed files with 48,393 additions and 24 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ homepage = "https://github.com/Cardinal-Cryptography/drink"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/Cardinal-Cryptography/drink"
version = "0.11.0"
version = "0.11.1"

[workspace.dependencies]
anyhow = { version = "1.0.71" }
Expand Down Expand Up @@ -57,5 +57,5 @@ sp-runtime-interface = { version = "24.0.0" }

# Local dependencies

drink = { version = "0.11.0", path = "drink" }
drink-test-macro = { version = "0.11.0", path = "drink/test-macro" }
drink = { version = "0.11.1", path = "drink" }
drink-test-macro = { version = "0.11.1", path = "drink/test-macro" }
39 changes: 32 additions & 7 deletions drink/test-macro/src/contract_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ pub fn build_contracts() -> BundleProviderGenerator {
)
}

fn get_contract_crates(metadata: &Metadata) -> (Option<&Package>, impl Iterator<Item = &Package>) {
/// Contract package together with the features it should be built with.
struct FeaturedPackage<'metadata> {
package: &'metadata Package,
features_on: Vec<String>,
}

fn get_contract_crates(
metadata: &Metadata,
) -> (
Option<FeaturedPackage>,
impl Iterator<Item = FeaturedPackage>,
) {
let pkg_lookup = |id| {
metadata
.packages
Expand All @@ -64,7 +75,14 @@ fn get_contract_crates(metadata: &Metadata) -> (Option<&Package>, impl Iterator<
node.features
.contains(&INK_AS_DEPENDENCY_FEATURE.to_string())
})
.map(move |node| pkg_lookup(node.id.clone()));
.map(move |node| {
let mut features_on = node.features.clone();
features_on.retain(|feature| feature != INK_AS_DEPENDENCY_FEATURE && feature != "std");
FeaturedPackage {
package: pkg_lookup(node.id.clone()),
features_on,
}
});

let root = dep_graph
.root
Expand All @@ -75,13 +93,20 @@ fn get_contract_crates(metadata: &Metadata) -> (Option<&Package>, impl Iterator<
(
root.features
.contains_key(INK_AS_DEPENDENCY_FEATURE)
.then_some(root),
.then_some(FeaturedPackage {
package: root,
features_on: vec![],
}),
contract_deps,
)
}

fn build_contract_crate(pkg: &Package) -> (String, PathBuf) {
let manifest_path = get_manifest_path(pkg);
fn build_contract_crate(pkg: FeaturedPackage) -> (String, PathBuf) {
let manifest_path = get_manifest_path(pkg.package);
let mut features = Features::default();
for feature in pkg.features_on {
features.push(&feature);
}

match CONTRACTS_BUILT
.get_or_init(|| Mutex::new(HashMap::new()))
Expand All @@ -95,7 +120,7 @@ fn build_contract_crate(pkg: &Package) -> (String, PathBuf) {
manifest_path,
verbosity: Verbosity::Default,
build_mode: BuildMode::Release,
features: Features::default(),
features,
network: Network::Online,
build_artifact: BuildArtifacts::All,
unstable_flags: UnstableFlags::default(),
Expand All @@ -115,7 +140,7 @@ fn build_contract_crate(pkg: &Package) -> (String, PathBuf) {
.expect("Metadata should have been generated")
.dest_bundle;

let new_entry = (pkg.name.clone(), bundle_path);
let new_entry = (pkg.package.name.clone(), bundle_path);
todo.insert(new_entry.clone());
new_entry
}
Expand Down
9 changes: 7 additions & 2 deletions drink/test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ type SynResult<T> = Result<T, syn::Error>;
/// Contracts to be built:
/// - current cargo package if contains a `ink-as-dependency` feature
/// - all dependencies declared in the `Cargo.toml` file with the `ink-as-dependency` feature
/// enabled
/// enabled (works with non-local packages as well).
///
/// Note: Depending on a non-local contract is not tested yet.
/// ## Compilation features
///
/// 1. The root contract package (if any) is assumed to be built without any features.
///
/// 2. All contract dependencies will be built with a union of all features enabled on that package (through potentially
/// different configurations or dependency paths), **excluding** `ink-as-dependency` and `std` features.
///
/// # Creating a session object
///
Expand Down
Loading

0 comments on commit 0e33fb1

Please sign in to comment.