From 286f745021fb645ce5e187b759d329c56ecb582d Mon Sep 17 00:00:00 2001 From: Miraculous Owonubi Date: Mon, 29 Aug 2022 13:36:52 +0400 Subject: [PATCH] ABI embedding (#31) --- cargo-near/Cargo.toml | 3 +- cargo-near/src/abi/mod.rs | 62 +++++++--- cargo-near/src/build.rs | 72 ++++++++++++ cargo-near/src/cargo/manifest.rs | 17 ++- cargo-near/src/cargo/metadata.rs | 10 +- cargo-near/src/lib.rs | 65 +++++++---- cargo-near/src/main.rs | 6 +- cargo-near/src/util.rs | 106 ++++++++++++++---- integration-tests/src/lib.rs | 1 + integration-tests/templates/_Cargo.toml | 6 +- .../templates/_Cargo_no_abi_feature.toml | 5 +- .../sdk-dependency/_Cargo_explicit.toml | 3 +- .../_Cargo_multiple_features.toml | 6 +- .../_Cargo_no_default_features.toml | 7 +- .../sdk-dependency/_Cargo_patch.toml | 2 +- .../_Cargo_platform_specific.toml | 12 +- .../sdk-dependency/_Cargo_renamed.toml | 7 +- integration-tests/tests/cargo/mod.rs | 6 +- 18 files changed, 310 insertions(+), 86 deletions(-) create mode 100644 cargo-near/src/build.rs diff --git a/cargo-near/Cargo.toml b/cargo-near/Cargo.toml index 619eb141..88c084aa 100644 --- a/cargo-near/Cargo.toml +++ b/cargo-near/Cargo.toml @@ -1,13 +1,14 @@ [package] name = "cargo-near" version = "0.1.0" +authors = ["Near Inc "] edition = "2021" rust-version = "1.56.0" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/near/cargo-near" description = """ -Cargo extension for building Rust smart contracts on NEAR. +Cargo extension for building Rust smart contracts on NEAR """ [dependencies] diff --git a/cargo-near/src/abi/mod.rs b/cargo-near/src/abi/mod.rs index 147567d5..c726ff1f 100644 --- a/cargo-near/src/abi/mod.rs +++ b/cargo-near/src/abi/mod.rs @@ -1,7 +1,8 @@ use crate::cargo::{manifest::CargoManifestPath, metadata::CrateMetadata}; -use crate::util; +use crate::{util, AbiCommand}; use std::collections::HashMap; -use std::{fs, path::PathBuf}; +use std::fs; +use std::path::PathBuf; mod generation; @@ -13,11 +14,10 @@ pub(crate) struct AbiResult { pub path: PathBuf, } -pub(crate) fn execute( - manifest_path: &CargoManifestPath, +pub(crate) fn write_to_file( + crate_metadata: &CrateMetadata, generate_docs: bool, ) -> anyhow::Result { - let crate_metadata = CrateMetadata::collect(manifest_path)?; let near_abi_gen_dir = &crate_metadata .target_directory .join(crate_metadata.root_package.name.clone() + "-near-abi-gen"); @@ -27,16 +27,28 @@ pub(crate) fn execute( near_abi_gen_dir.display() ); - let dylib_path = util::compile_dylib_project(manifest_path)?; + let dylib_artifact = util::compile_project( + &crate_metadata.manifest_path, + &["--features", "near-sdk/__abi-generate"], + vec![ + ("CARGO_PROFILE_DEV_OPT_LEVEL", "0"), + ("CARGO_PROFILE_DEV_DEBUG", "0"), + ("CARGO_PROFILE_DEV_LTO", "off"), + ], + util::dylib_extension(), + )?; - let cargo_toml = generation::generate_toml(manifest_path)?; - fs::write(near_abi_gen_dir.join("Cargo.toml"), cargo_toml)?; + // todo! experiment with reusing cargo-near for extracting data from the dylib + if dylib_artifact.fresh { + let cargo_toml = generation::generate_toml(&crate_metadata.manifest_path)?; + fs::write(near_abi_gen_dir.join("Cargo.toml"), cargo_toml)?; - let build_rs = generation::generate_build_rs(&dylib_path)?; - fs::write(near_abi_gen_dir.join("build.rs"), build_rs)?; + let build_rs = generation::generate_build_rs(&dylib_artifact.path)?; + fs::write(near_abi_gen_dir.join("build.rs"), build_rs)?; - let main_rs = generation::generate_main_rs(&dylib_path)?; - fs::write(near_abi_gen_dir.join("main.rs"), main_rs)?; + let main_rs = generation::generate_main_rs(&dylib_artifact.path)?; + fs::write(near_abi_gen_dir.join("main.rs"), main_rs)?; + } let stdout = util::invoke_cargo( "run", @@ -44,18 +56,18 @@ pub(crate) fn execute( Some(near_abi_gen_dir), vec![( "LD_LIBRARY_PATH", - &dylib_path.parent().unwrap().to_string_lossy(), + &dylib_artifact.path.parent().unwrap().to_string_lossy(), )], )?; let mut contract_abi = near_abi::__private::ChunkedAbiEntry::combine( serde_json::from_slice::>(&stdout)?.into_iter(), )? - .into_abi_root(extract_metadata(&crate_metadata)); + .into_abi_root(extract_metadata(crate_metadata)); if !generate_docs { strip_docs(&mut contract_abi); } - let near_abi_json = serde_json::to_string_pretty(&contract_abi)?; + let near_abi_json = serde_json::to_string(&contract_abi)?; let out_path_abi = crate_metadata.target_directory.join(ABI_FILE); fs::write(&out_path_abi, near_abi_json)?; @@ -86,3 +98,23 @@ fn strip_docs(abi_root: &mut near_abi::AbiRoot) { } } } + +pub(crate) fn run(args: AbiCommand) -> anyhow::Result<()> { + let crate_metadata = CrateMetadata::collect(CargoManifestPath::try_from( + args.manifest_path.unwrap_or_else(|| "Cargo.toml".into()), + )?)?; + + let out_dir = util::force_canonicalize_dir( + &args + .out_dir + .unwrap_or_else(|| crate_metadata.target_directory.clone()), + )?; + + let AbiResult { path } = write_to_file(&crate_metadata, args.doc)?; + + let abi_path = util::copy(&path, &out_dir)?; + + println!("ABI successfully generated at `{}`", abi_path.display()); + + Ok(()) +} diff --git a/cargo-near/src/build.rs b/cargo-near/src/build.rs new file mode 100644 index 00000000..affd65e3 --- /dev/null +++ b/cargo-near/src/build.rs @@ -0,0 +1,72 @@ +use crate::abi::AbiResult; +use crate::cargo::{manifest::CargoManifestPath, metadata::CrateMetadata}; +use crate::{abi, util, BuildCommand}; +use colored::Colorize; +use std::io::BufRead; + +const COMPILATION_TARGET: &str = "wasm32-unknown-unknown"; + +pub(crate) fn run(args: BuildCommand) -> anyhow::Result<()> { + if !util::invoke_rustup(&["target", "list", "--installed"])? + .lines() + .any(|target| target.as_ref().map_or(false, |t| t == COMPILATION_TARGET)) + { + anyhow::bail!("rust target `{}` is not installed", COMPILATION_TARGET); + } + + let crate_metadata = CrateMetadata::collect(CargoManifestPath::try_from( + args.manifest_path.unwrap_or_else(|| "Cargo.toml".into()), + )?)?; + + let out_dir = util::force_canonicalize_dir( + &args + .out_dir + .unwrap_or_else(|| crate_metadata.target_directory.clone()), + )?; + + let mut build_env = vec![("RUSTFLAGS", "-C link-arg=-s")]; + let mut cargo_args = vec!["--target", COMPILATION_TARGET]; + if args.release { + cargo_args.push("--release"); + } + + let mut abi_path = None; + if !args.no_abi { + let AbiResult { path } = abi::write_to_file(&crate_metadata, args.doc)?; + abi_path.replace(util::copy(&path, &out_dir)?); + } + + if let (true, Some(abi_path)) = (args.embed_abi, &abi_path) { + cargo_args.extend(&["--features", "near-sdk/__abi-embed"]); + build_env.push(("CARGO_NEAR_ABI_PATH", abi_path.to_str().unwrap())); + } + + let mut wasm_artifact = util::compile_project( + &crate_metadata.manifest_path, + &cargo_args, + build_env, + "wasm", + )?; + + wasm_artifact.path = util::copy(&wasm_artifact.path, &out_dir)?; + + // todo! if we embedded, check that the binary exports the __contract_abi symbol + println!("{}", "Contract Successfully Built!".green().bold()); + println!( + " - Binary: {}", + wasm_artifact + .path + .display() + .to_string() + .bright_yellow() + .bold() + ); + if let Some(abi_path) = abi_path { + println!( + " - ABI: {}", + abi_path.display().to_string().yellow().bold() + ); + } + + Ok(()) +} diff --git a/cargo-near/src/cargo/manifest.rs b/cargo-near/src/cargo/manifest.rs index f81f8993..981979bb 100644 --- a/cargo-near/src/cargo/manifest.rs +++ b/cargo-near/src/cargo/manifest.rs @@ -24,12 +24,21 @@ impl TryFrom for CargoManifestPath { fn try_from(manifest_path: PathBuf) -> Result { if let Some(file_name) = manifest_path.file_name() { if file_name != MANIFEST_FILE_NAME { - anyhow::bail!("Manifest file must be a Cargo.toml") + anyhow::bail!("the manifest-path must be a path to a Cargo.toml file") } } - let canonical_manifest_path = manifest_path.canonicalize().map_err(|err| { - anyhow::anyhow!("Failed to canonicalize {:?}: {:?}", manifest_path, err) - })?; + let canonical_manifest_path = + manifest_path + .canonicalize() + .map_err(|err| match err.kind() { + std::io::ErrorKind::NotFound => { + anyhow::anyhow!( + "manifest path `{}` does not exist", + manifest_path.display() + ) + } + _ => err.into(), + })?; Ok(CargoManifestPath { path: canonical_manifest_path, }) diff --git a/cargo-near/src/cargo/metadata.rs b/cargo-near/src/cargo/metadata.rs index 661e9a63..82cdee5f 100644 --- a/cargo-near/src/cargo/metadata.rs +++ b/cargo-near/src/cargo/metadata.rs @@ -8,20 +8,21 @@ use std::path::PathBuf; pub(crate) struct CrateMetadata { pub root_package: Package, pub target_directory: PathBuf, + pub manifest_path: CargoManifestPath, } impl CrateMetadata { /// Parses the contract manifest and returns relevant metadata. - pub fn collect(manifest_path: &CargoManifestPath) -> Result { - let (metadata, root_package) = get_cargo_metadata(manifest_path)?; + pub fn collect(manifest_path: CargoManifestPath) -> Result { + let (metadata, root_package) = get_cargo_metadata(&manifest_path)?; let mut target_directory = metadata.target_directory.as_path().join("near"); // Normalize the package and lib name. let package_name = root_package.name.replace('-', "_"); - let absolute_manifest_path = manifest_path.directory()?; + let absolute_manifest_dir = manifest_path.directory()?; let absolute_workspace_root = metadata.workspace_root.canonicalize()?; - if absolute_manifest_path != absolute_workspace_root { + if absolute_manifest_dir != 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); @@ -30,6 +31,7 @@ impl CrateMetadata { let crate_metadata = CrateMetadata { root_package, target_directory: target_directory.into(), + manifest_path, }; Ok(crate_metadata) } diff --git a/cargo-near/src/lib.rs b/cargo-near/src/lib.rs index f63d5271..8b6c0d40 100644 --- a/cargo-near/src/lib.rs +++ b/cargo-near/src/lib.rs @@ -1,16 +1,21 @@ -use cargo::manifest::CargoManifestPath; use clap::{AppSettings, Args, Parser, Subcommand}; use std::path::PathBuf; mod abi; +mod build; mod cargo; mod util; #[derive(Debug, Parser)] -#[clap(bin_name = "cargo")] +#[clap(bin_name = "cargo", version, author, about)] pub enum Opts { - #[clap(name = "near")] - #[clap(setting = AppSettings::DeriveDisplayOrder)] + #[clap( + name = "near", + version, + author, + about, + setting = AppSettings::DeriveDisplayOrder, + )] Near(NearArgs), } @@ -25,31 +30,51 @@ pub enum NearCommand { /// Generates ABI for the contract #[clap(name = "abi")] Abi(AbiCommand), + /// Build a NEAR contract and optionally embed ABI + #[clap(name = "build")] + Build(BuildCommand), } #[derive(Debug, clap::Args)] -#[clap(name = "abi")] +#[clap(setting = AppSettings::DeriveDisplayOrder)] pub struct AbiCommand { + /// Include rustdocs in the ABI file + #[clap(long)] + pub doc: bool, + /// Copy final artifacts to the this directory + #[clap(long, parse(from_os_str), value_name = "PATH")] + pub out_dir: Option, /// Path to the `Cargo.toml` of the contract to build - #[clap(long, parse(from_os_str))] + #[clap(long, parse(from_os_str), value_name = "PATH")] pub manifest_path: Option, - /// Include rustdocs in the ABI file - #[clap(long, takes_value = false)] +} + +#[derive(Debug, clap::Args)] +#[clap(setting = AppSettings::DeriveDisplayOrder)] +pub struct BuildCommand { + /// Build contract in release mode, with optimizations + #[clap(short, long)] + pub release: bool, + /// Embed the ABI in the contract binary + #[clap(long)] + pub embed_abi: bool, + /// Include rustdocs in the embedded ABI + #[clap(long, requires = "embed-abi")] pub doc: bool, + /// Do not generate ABI for the contract + #[clap(long, conflicts_with_all = &["doc", "embed-abi"])] + pub no_abi: bool, + /// Copy final artifacts to the this directory + #[clap(long, parse(from_os_str), value_name = "PATH")] + pub out_dir: Option, + /// Path to the `Cargo.toml` of the contract to build + #[clap(long, parse(from_os_str), value_name = "PATH")] + pub manifest_path: Option, } pub fn exec(cmd: NearCommand) -> anyhow::Result<()> { - match &cmd { - NearCommand::Abi(abi) => { - let manifest_path = abi - .manifest_path - .clone() - .unwrap_or_else(|| "Cargo.toml".into()); - let manifest_path = CargoManifestPath::try_from(manifest_path)?; - - let result = abi::execute(&manifest_path, abi.doc)?; - println!("ABI successfully generated at {}", result.path.display()); - Ok(()) - } + match cmd { + NearCommand::Abi(args) => abi::run(args), + NearCommand::Build(args) => build::run(args), } } diff --git a/cargo-near/src/main.rs b/cargo-near/src/main.rs index d25019d3..4ca9f1e6 100644 --- a/cargo-near/src/main.rs +++ b/cargo-near/src/main.rs @@ -9,11 +9,7 @@ fn main() { match cargo_near::exec(args.cmd) { Ok(()) => {} Err(err) => { - eprintln!( - "{} {}", - "ERROR:".bright_red().bold(), - format!("{:?}", err).bright_red() - ); + eprintln!("{} {:?}", "error:".bright_red().bold(), err); std::process::exit(1); } } diff --git a/cargo-near/src/util.rs b/cargo-near/src/util.rs index 1317f6e9..0d6e7454 100644 --- a/cargo-near/src/util.rs +++ b/cargo-near/src/util.rs @@ -1,13 +1,14 @@ +use crate::cargo::manifest::CargoManifestPath; use anyhow::{Context, Result}; use cargo_metadata::diagnostic::DiagnosticLevel; use cargo_metadata::Message; +use std::env; use std::ffi::OsStr; +use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use crate::cargo::manifest::CargoManifestPath; - -const fn dylib_extension() -> &'static str { +pub(crate) const fn dylib_extension() -> &'static str { #[cfg(target_os = "linux")] return "so"; @@ -50,7 +51,7 @@ pub(crate) fn invoke_cargo( env: Vec<(&str, &str)>, ) -> Result> where - I: IntoIterator + std::fmt::Debug, + I: IntoIterator, S: AsRef, P: AsRef, { @@ -90,25 +91,56 @@ where } } -fn build_cargo_project(manifest_path: &CargoManifestPath) -> anyhow::Result> { - let output = invoke_cargo( +pub(crate) fn invoke_rustup(args: I) -> anyhow::Result> +where + I: IntoIterator, + S: AsRef, +{ + let rustup = env::var("RUSTUP").unwrap_or_else(|_| "rustup".to_string()); + + let mut cmd = Command::new(rustup); + cmd.args(args); + + log::info!("Invoking rustup: {:?}", cmd); + + let child = cmd + .stdout(std::process::Stdio::piped()) + .spawn() + .context(format!("Error executing `{:?}`", cmd))?; + + let output = child.wait_with_output()?; + if output.status.success() { + Ok(output.stdout) + } else { + anyhow::bail!( + "`{:?}` failed with exit code: {:?}", + cmd, + output.status.code() + ); + } +} + +pub struct CompilationArtifact { + pub path: PathBuf, + pub fresh: bool, +} + +/// Builds the cargo project with manifest located at `manifest_path` and returns the path to the generated artifact. +pub(crate) fn compile_project( + manifest_path: &CargoManifestPath, + args: &[&str], + env: Vec<(&str, &str)>, + artifact_extension: &str, +) -> anyhow::Result { + let stdout = invoke_cargo( "build", - &["--message-format=json"], + [&["--message-format=json"], args].concat(), manifest_path.directory().ok(), - vec![ - ("CARGO_PROFILE_DEV_OPT_LEVEL", "0"), - ("CARGO_PROFILE_DEV_DEBUG", "0"), - ("CARGO_PROFILE_DEV_LTO", "off"), - ], + env, )?; + let reader = std::io::BufReader::new(&*stdout); + let messages: Vec<_> = Message::parse_stream(reader).collect::>()?; - let reader = std::io::BufReader::new(output.as_slice()); - Ok(Message::parse_stream(reader).map(|m| m.unwrap()).collect()) -} - -/// Builds the cargo project with manifest located at `manifest_path` and returns the path to the generated dynamic lib. -pub(crate) fn compile_dylib_project(manifest_path: &CargoManifestPath) -> anyhow::Result { - let messages = build_cargo_project(manifest_path)?; // We find the last compiler artifact message which should contain information about the // resulting dylib file let compile_artifact = messages @@ -132,7 +164,7 @@ pub(crate) fn compile_dylib_project(manifest_path: &CargoManifestPath) -> anyhow .cloned() .filter(|f| { f.extension() - .map(|e| e == dylib_extension()) + .map(|e| e == artifact_extension) .unwrap_or(false) }) .collect::>(); @@ -140,13 +172,41 @@ pub(crate) fn compile_dylib_project(manifest_path: &CargoManifestPath) -> anyhow [] => Err(anyhow::anyhow!( "Compilation resulted in no '.{}' target files. \ Please check that your project contains a NEAR smart contract.", - dylib_extension() + artifact_extension )), - [file] => Ok(file.to_owned().into_std_path_buf()), + [file] => Ok(CompilationArtifact { + path: file.to_owned().into_std_path_buf(), + fresh: !compile_artifact.fresh, + }), _ => Err(anyhow::anyhow!( "Compilation resulted in more than one '.{}' target file: {:?}", - dylib_extension(), + artifact_extension, dylib_files )), } } + +/// Create the directory if it doesn't exist, and return the absolute path to it. +pub(crate) fn force_canonicalize_dir(dir: &Path) -> anyhow::Result { + fs::create_dir_all(&dir) + .with_context(|| format!("failed to create directory `{}`", dir.display()))?; + dir.canonicalize() + .with_context(|| format!("failed to access output directory `{}`", dir.display())) +} + +/// Copy a file to a destination. +/// +/// Does nothing if the destination is the same as the source to avoid truncating the file. +pub(crate) fn copy(from: &Path, to: &Path) -> anyhow::Result { + let out_path = to.join(from.file_name().unwrap()); + if from != out_path { + fs::copy(&from, &out_path).with_context(|| { + format!( + "failed to copy `{}` to `{}`", + from.display(), + out_path.display(), + ) + })?; + } + Ok(out_path) +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 2a6d1155..68212bea 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -24,6 +24,7 @@ macro_rules! generate_abi { cargo_near::exec(cargo_near::NearCommand::Abi(cargo_near::AbiCommand { manifest_path: Some(cargo_path), doc: false, + out_dir: None, }))?; let abi_root: near_abi::AbiRoot = diff --git a/integration-tests/templates/_Cargo.toml b/integration-tests/templates/_Cargo.toml index e3bcb980..eef313f6 100644 --- a/integration-tests/templates/_Cargo.toml +++ b/integration-tests/templates/_Cargo.toml @@ -7,10 +7,14 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" +[dependencies.near-sdk] +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" +features = ["abi"] + [workspace] members = [] diff --git a/integration-tests/templates/_Cargo_no_abi_feature.toml b/integration-tests/templates/_Cargo_no_abi_feature.toml index 62629112..d86a51e4 100644 --- a/integration-tests/templates/_Cargo_no_abi_feature.toml +++ b/integration-tests/templates/_Cargo_no_abi_feature.toml @@ -7,10 +7,13 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.2" } serde = { version = "1", features = ["derive"] } schemars = "0.8" +[dependencies.near-sdk] +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" + [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml b/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml index f7bc7042..eef313f6 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml @@ -11,7 +11,8 @@ serde = { version = "1", features = ["derive"] } schemars = "0.8" [dependencies.near-sdk] -version = "4.1.0-pre.2" +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" features = ["abi"] [workspace] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml b/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml index ff79a015..7a34c458 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml @@ -7,10 +7,14 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.2", features = ["abi", "unstable"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" +[dependencies.near-sdk] +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" +features = ["abi", "unstable"] + [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml b/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml index dc87a94a..6b8ba3f4 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml @@ -7,10 +7,15 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.2", default-features = false, features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" +[dependencies.near-sdk] +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" +default-features = false +features = ["abi"] + [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_patch.toml b/integration-tests/templates/sdk-dependency/_Cargo_patch.toml index ff50f417..9c5b85b8 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_patch.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_patch.toml @@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] } schemars = "0.8" [patch.crates-io] -near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "83cb1c40403e4156bd6d1d258237bbdf03326afc" } +near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" } [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml b/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml index a73e8de7..462b4e90 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml @@ -10,11 +10,15 @@ crate-type = ["cdylib"] serde = { version = "1", features = ["derive"] } schemars = "0.8" -[target.'cfg(windows)'.dependencies] -near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } +[target.'cfg(windows)'.dependencies.near-sdk] +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" +features = ["abi"] -[target.'cfg(unix)'.dependencies] -near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } +[target.'cfg(unix)'.dependencies.near-sdk] +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" +features = ["abi"] [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml b/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml index 0ff84f34..e4967d0d 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml @@ -7,10 +7,15 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near = { version = "4.1.0-pre.2", package = "near-sdk", features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" +[dependencies.near] +package = "near-sdk" +git = "https://github.com/near/near-sdk-rs.git" +rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" +features = ["abi"] + [workspace] members = [] diff --git a/integration-tests/tests/cargo/mod.rs b/integration-tests/tests/cargo/mod.rs index bba06439..a5030bee 100644 --- a/integration-tests/tests/cargo/mod.rs +++ b/integration-tests/tests/cargo/mod.rs @@ -19,7 +19,7 @@ fn clone_git_repo(version: &str) -> anyhow::Result { #[test] #[named] fn test_dependency_local_path() -> anyhow::Result<()> { - let near_sdk_dir = clone_git_repo("83cb1c40403e4156bd6d1d258237bbdf03326afc")?; + let near_sdk_dir = clone_git_repo("03bab8db6145e038626c4b15b34b0bd8a33fba44")?; let near_sdk_dep_path = near_sdk_dir.path().join("near-sdk"); // near-sdk = { path = "::path::", features = ["abi"] } @@ -40,7 +40,7 @@ fn test_dependency_local_path() -> anyhow::Result<()> { #[test] #[named] fn test_dependency_local_path_with_version() -> anyhow::Result<()> { - let near_sdk_dir = clone_git_repo("83cb1c40403e4156bd6d1d258237bbdf03326afc")?; + let near_sdk_dir = clone_git_repo("03bab8db6145e038626c4b15b34b0bd8a33fba44")?; let near_sdk_dep_path = near_sdk_dir.path().join("near-sdk"); // near-sdk = { path = "::path::", version = "4.1.0-pre.2", features = ["abi"] } @@ -172,7 +172,7 @@ fn test_dependency_patch() -> anyhow::Result<()> { // near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } // // [patch.crates-io] - // near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "83cb1c40403e4156bd6d1d258237bbdf03326afc" } + // near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "03bab8db6145e038626c4b15b34b0bd8a33fba44" } let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_patch.toml";