Skip to content

Commit

Permalink
Update t3rn-contract with latest cargo-contract
Browse files Browse the repository at this point in the history
  • Loading branch information
beqaabu committed Oct 5, 2021
1 parent 1f53996 commit 332077a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 160 deletions.
56 changes: 6 additions & 50 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
members = [".", "metadata"]

[package]
<<<<<<< HEAD
name = "cargo-t3rn-contract"
version = "0.4.1"
authors = ["Parity Technologies <admin@parity.io>", "Maciej Baj <maciej@maciejbaj.com>"]
=======
name = "cargo-contract"
version = "0.14.0"
authors = ["Parity Technologies <admin@parity.io>"]
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7
authors = ["Parity Technologies <admin@parity.io>", ]
build = "build.rs"
edition = "2018"

Expand All @@ -25,48 +19,13 @@ categories = ["command-line-utilities", "development-tools::build-utils", "devel
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE", "build.rs", "templates"]

[dependencies]
<<<<<<< HEAD
env_logger = "0.7.1"
anyhow = "1.0.26"
structopt = "0.3.9"
log = "0.4.8"
heck = "0.3.1"
zip = { version = "0.5.4", default-features = false }
pwasm-utils = "0.12.0"
parity-wasm = "0.41.0"
cargo_metadata = "0.9.1"
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive", "full"] }

which = "3.1.0"
colored = "1.9"
toml = "0.5.4"
cargo-xbuild = "0.6.0"
rustc_version = "0.2.3"
blake2 = "0.9.0"
semver = { version = "0.10.0", features = ["serde"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
tempfile = "3.1.0"
url = { version = "2.1.1", features = ["serde"] }
wabt = "0.10.0"
wat = { version = "1.0", default-features = false }

# dependencies for optional extrinsics feature
async-std = { version = "1.6.2", optional = true }
sp-core = { version = "2.0.0-rc5", optional = true }
subxt = { version = "0.12.0", package = "substrate-subxt", git = "https://github.com/MaciejBaj/substrate-subxt", branch = "development", optional = true }
futures = { version = "0.3.2", optional = true }
hex = { version = "0.4.0", optional = true }
meval = "0.2"
regex = "1"
=======
env_logger = "0.9.0"
anyhow = "1.0.44"
structopt = "0.3.23"
log = "0.4.14"
heck = "0.3.3"
zip = { version = "0.5.13", default-features = false }
parity-wasm = "0.42.2"
parity-wasm = "0.41.0"
cargo_metadata = "0.14.0"
codec = { package = "parity-scale-codec", version = "2.1", features = ["derive"] }
which = "4.2.2"
Expand All @@ -82,17 +41,19 @@ tempfile = "3.2.0"
url = { version = "2.2.2", features = ["serde"] }
impl-serde = "0.3.1"
regex = "1.4"
wat = { version = "1.0", default-features = false }
cargo-xbuild = "0.6.0"
pwasm-utils = "0.12.0"

# dependencies for optional extrinsics feature
async-std = { version = "1.10.0", optional = true }
sp-core = { version = "2.0.1", optional = true }
subxt = { version = "0.14.0", package = "substrate-subxt", optional = true }
subxt = { version = "0.12.0", package = "substrate-subxt", path = "../subxt", optional = true }
futures = { version = "0.3.17", optional = true }
hex = { version = "0.4.3", optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
funty = "=1.1.0"
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7

[build-dependencies]
anyhow = "1.0.44"
Expand All @@ -102,14 +63,9 @@ substrate-build-script-utils = "3.0.0"
platforms = "1.1"

[dev-dependencies]
<<<<<<< HEAD
assert_matches = "1.3.0"
pretty_assertions = "0.6.1"
=======
assert_matches = "1.5.0"
pretty_assertions = "1.0.0"
wabt = "0.10.0"
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7

[features]
default = []
Expand Down
5 changes: 0 additions & 5 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,7 @@ fn exec_cargo_for_wasm_target(
} else {
args.push("-Zbuild-std-features=panic_immediate_abort");
}
<<<<<<< HEAD

println!("exit_status {:?}", exit_status);
=======
util::invoke_cargo(command, &args, manifest_path.directory(), verbosity)?;
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7

Ok(())
};
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/composable_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fn build_cargo_project_compose(
);

let verbosity = verbosity.map(|v| match v {
Verbosity::Default => xargo_lib::Verbosity::Verbose,
Verbosity::Verbose => xargo_lib::Verbosity::Verbose,
Verbosity::Quiet => xargo_lib::Verbosity::Quiet,
});
Expand All @@ -111,7 +112,7 @@ fn build_cargo_project_compose(
"--release",
&format!(
"--target-dir={}",
get_compose_target_dest(current_compose_name, target_dir.to_path_buf())
get_compose_target_dest(current_compose_name, target_dir.into())
.to_string_lossy()
),
];
Expand All @@ -120,7 +121,7 @@ fn build_cargo_project_compose(
.context("Creating xargo args")?;

let config = xargo_lib::Config {
sysroot_path: target_dir.join("sysroot"),
sysroot_path: target_dir.join("sysroot").into(),
memcpy: false,
panic_immediate_abort: true,
};
Expand Down Expand Up @@ -412,7 +413,7 @@ fn compile_wat_to_wasm(
/// Reads contract file (lib.rs) as a text.
fn read_contracts_file_as_text(crate_metadata: &CrateMetadata) -> String {
let target_dir = &crate_metadata.cargo_meta.target_directory;
let mut composable_contract_source_path: PathBuf = target_dir.to_path_buf();
let mut composable_contract_source_path: PathBuf = target_dir.into();
composable_contract_source_path.pop();
composable_contract_source_path.push("lib");
composable_contract_source_path.set_extension("rs");
Expand Down
9 changes: 1 addition & 8 deletions src/cmd/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

<<<<<<< HEAD
use anyhow::Result;
use subxt::{
balances::Balances, contracts::*, system::System, ClientBuilder, ContractsTemplateRuntime,
};
=======
use anyhow::{Context, Result};
use subxt::{balances::Balances, contracts::*, system::System, ClientBuilder, DefaultNodeRuntime};
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7
use subxt::{balances::Balances, contracts::*, system::System, ClientBuilder, DefaultNodeRuntime, ContractsTemplateRuntime};

use crate::{ExtrinsicOpts, HexData};

Expand Down
61 changes: 16 additions & 45 deletions src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ pub struct ComposableScheduleMetadata {
pub struct CrateMetadata {
pub manifest_path: ManifestPath,
pub cargo_meta: cargo_metadata::Metadata,
<<<<<<< HEAD
pub package_name: String,
pub t3rn_composable_schedule: Option<ComposableScheduleMetadata>,
=======
pub contract_artifact_name: String,
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7
pub t3rn_composable_schedule: Option<ComposableScheduleMetadata>,
pub root_package: Package,
pub original_wasm: PathBuf,
pub target_directory: PathBuf,
Expand All @@ -66,16 +63,14 @@ pub struct CrateMetadata {
pub documentation: Option<Url>,
pub homepage: Option<Url>,
pub user: Option<Map<String, Value>>,
pub target_directory: PathBuf,
}

impl CrateMetadata {
/// Parses the contract manifest and returns relevant metadata.
pub fn collect(manifest_path: &ManifestPath) -> Result<Self> {
let (metadata, root_package) = get_cargo_metadata(manifest_path)?;
let mut target_directory = metadata.target_directory.as_path().join("ink");

// Normalize the package and lib name.
// Normalize the package name.
let package_name = root_package.name.replace("-", "_");
let lib_name = &root_package
.targets
Expand All @@ -85,31 +80,16 @@ impl CrateMetadata {
.name
.replace("-", "_");

let absolute_manifest_path = manifest_path.absolute_directory()?;
let absolute_workspace_root = metadata.workspace_root.canonicalize()?;
if absolute_manifest_path != absolute_workspace_root {
// If the contract is a package in a workspace, we use the package name
// as the name of the sub-folder where we put the `.contract` bundle.
target_directory = target_directory.join(package_name);
}

<<<<<<< HEAD


// {target_dir}/wasm32-unknown-unknown/release/{package_name}.wasm
let mut original_wasm = metadata.target_directory.clone();
=======
// {target_dir}/wasm32-unknown-unknown/release/{lib_name}.wasm
let mut original_wasm = target_directory.clone();
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7
original_wasm.push("wasm32-unknown-unknown");
original_wasm.push("release");
original_wasm.push(lib_name.clone());
original_wasm.push(package_name.clone());
original_wasm.set_extension("wasm");

// {target_dir}/{lib_name}.wasm
let mut dest_wasm = target_directory.clone();
dest_wasm.push(lib_name.clone());
// {target_dir}/{package_name}.wasm
let mut dest_wasm = metadata.target_directory.clone();
dest_wasm.push(package_name.clone());
dest_wasm.set_extension("wasm");

let mut composable_schedule: Option<ComposableScheduleMetadata> = None;
Expand Down Expand Up @@ -143,31 +123,24 @@ impl CrateMetadata {
None
}
})
.ok_or_else(|| anyhow::anyhow!("No 'ink_lang' dependency found"))?;
.ok_or(anyhow::anyhow!("No 'ink_lang' dependency found"))?;

let ExtraMetadata {
documentation,
homepage,
user,
} = get_cargo_toml_metadata(manifest_path)?;
let (documentation, homepage, user) = get_cargo_toml_metadata(manifest_path)?;

let crate_metadata = CrateMetadata {
manifest_path: manifest_path.clone(),
cargo_meta: metadata.clone(),
root_package,
contract_artifact_name: lib_name.to_string(),
package_name,
original_wasm: original_wasm.into(),
dest_wasm: dest_wasm.into(),
ink_version,
documentation,
homepage,
user,
<<<<<<< HEAD
contract_artifact_name: lib_name.to_string(),
t3rn_composable_schedule: composable_schedule,
target_directory: metadata.target_directory.clone(),
=======
target_directory: target_directory.into(),
>>>>>>> 8e86572b4b4ed2442de131c8e3506dee219fb0b7
target_directory: metadata.target_directory.clone().into(),
};
Ok(crate_metadata)
}
Expand Down Expand Up @@ -205,13 +178,15 @@ struct ExtraMetadata {
}

/// Read extra metadata not available via `cargo metadata` directly from `Cargo.toml`
fn get_cargo_toml_metadata(manifest_path: &ManifestPath) -> Result<ExtraMetadata> {
fn get_cargo_toml_metadata(
manifest_path: &ManifestPath,
) -> Result<(Option<Url>, Option<Url>, Option<Map<String, Value>>)> {
let toml = fs::read_to_string(manifest_path)?;
let toml: value::Table = toml::from_str(&toml)?;

let get_url = |field_name| -> Result<Option<Url>> {
toml.get("package")
.ok_or_else(|| anyhow::anyhow!("package section not found"))?
.ok_or(anyhow::anyhow!("package section not found"))?
.get(field_name)
.and_then(|v| v.as_str())
.map(Url::parse)
Expand All @@ -235,9 +210,5 @@ fn get_cargo_toml_metadata(manifest_path: &ManifestPath) -> Result<ExtraMetadata
})
.transpose()?;

Ok(ExtraMetadata {
documentation,
homepage,
user,
})
Ok((documentation, homepage, user))
}
Loading

0 comments on commit 332077a

Please sign in to comment.