Skip to content

Commit 0e33fb1

Browse files
Build features (#104)
1 parent ad58970 commit 0e33fb1

File tree

15 files changed

+48393
-24
lines changed

15 files changed

+48393
-24
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ homepage = "https://github.com/Cardinal-Cryptography/drink"
1818
license = "Apache-2.0"
1919
readme = "README.md"
2020
repository = "https://github.com/Cardinal-Cryptography/drink"
21-
version = "0.11.0"
21+
version = "0.11.1"
2222

2323
[workspace.dependencies]
2424
anyhow = { version = "1.0.71" }
@@ -57,5 +57,5 @@ sp-runtime-interface = { version = "24.0.0" }
5757

5858
# Local dependencies
5959

60-
drink = { version = "0.11.0", path = "drink" }
61-
drink-test-macro = { version = "0.11.0", path = "drink/test-macro" }
60+
drink = { version = "0.11.1", path = "drink" }
61+
drink-test-macro = { version = "0.11.1", path = "drink/test-macro" }

drink/test-macro/src/contract_building.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ pub fn build_contracts() -> BundleProviderGenerator {
4343
)
4444
}
4545

46-
fn get_contract_crates(metadata: &Metadata) -> (Option<&Package>, impl Iterator<Item = &Package>) {
46+
/// Contract package together with the features it should be built with.
47+
struct FeaturedPackage<'metadata> {
48+
package: &'metadata Package,
49+
features_on: Vec<String>,
50+
}
51+
52+
fn get_contract_crates(
53+
metadata: &Metadata,
54+
) -> (
55+
Option<FeaturedPackage>,
56+
impl Iterator<Item = FeaturedPackage>,
57+
) {
4758
let pkg_lookup = |id| {
4859
metadata
4960
.packages
@@ -64,7 +75,14 @@ fn get_contract_crates(metadata: &Metadata) -> (Option<&Package>, impl Iterator<
6475
node.features
6576
.contains(&INK_AS_DEPENDENCY_FEATURE.to_string())
6677
})
67-
.map(move |node| pkg_lookup(node.id.clone()));
78+
.map(move |node| {
79+
let mut features_on = node.features.clone();
80+
features_on.retain(|feature| feature != INK_AS_DEPENDENCY_FEATURE && feature != "std");
81+
FeaturedPackage {
82+
package: pkg_lookup(node.id.clone()),
83+
features_on,
84+
}
85+
});
6886

6987
let root = dep_graph
7088
.root
@@ -75,13 +93,20 @@ fn get_contract_crates(metadata: &Metadata) -> (Option<&Package>, impl Iterator<
7593
(
7694
root.features
7795
.contains_key(INK_AS_DEPENDENCY_FEATURE)
78-
.then_some(root),
96+
.then_some(FeaturedPackage {
97+
package: root,
98+
features_on: vec![],
99+
}),
79100
contract_deps,
80101
)
81102
}
82103

83-
fn build_contract_crate(pkg: &Package) -> (String, PathBuf) {
84-
let manifest_path = get_manifest_path(pkg);
104+
fn build_contract_crate(pkg: FeaturedPackage) -> (String, PathBuf) {
105+
let manifest_path = get_manifest_path(pkg.package);
106+
let mut features = Features::default();
107+
for feature in pkg.features_on {
108+
features.push(&feature);
109+
}
85110

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

118-
let new_entry = (pkg.name.clone(), bundle_path);
143+
let new_entry = (pkg.package.name.clone(), bundle_path);
119144
todo.insert(new_entry.clone());
120145
new_entry
121146
}

drink/test-macro/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ type SynResult<T> = Result<T, syn::Error>;
3232
/// Contracts to be built:
3333
/// - current cargo package if contains a `ink-as-dependency` feature
3434
/// - all dependencies declared in the `Cargo.toml` file with the `ink-as-dependency` feature
35-
/// enabled
35+
/// enabled (works with non-local packages as well).
3636
///
37-
/// Note: Depending on a non-local contract is not tested yet.
37+
/// ## Compilation features
38+
///
39+
/// 1. The root contract package (if any) is assumed to be built without any features.
40+
///
41+
/// 2. All contract dependencies will be built with a union of all features enabled on that package (through potentially
42+
/// different configurations or dependency paths), **excluding** `ink-as-dependency` and `std` features.
3843
///
3944
/// # Creating a session object
4045
///

0 commit comments

Comments
 (0)