Versioning for #[runtime-interface] (#5328)

* versionned runtime-interface

* use only one additional wasm blob

* alter docs

* formatting, naming and docs

* add comment for test

* version duplicate err

* RuntimeInterfaceItem -> RuntimeInterfaceFunction<

* test naming

* version checking

* remove spaces

* Update primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* remove sanity checks and reduce coverage

* add doc comment

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Nikolay Volf
2020-03-23 07:09:05 -07:00
committed by GitHub
parent fe68d6fd8c
commit 4d3557d5a1
22 changed files with 556 additions and 104 deletions
@@ -0,0 +1,23 @@
[package]
name = "sp-runtime-interface-test-wasm-deprecated"
version = "2.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
build = "build.rs"
license = "GPL-3.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
publish = false
[dependencies]
sp-runtime-interface = { version = "2.0.0-alpha.2", default-features = false, path = "../" }
sp-std = { version = "2.0.0-alpha.2", default-features = false, path = "../../std" }
sp-io = { version = "2.0.0-alpha.2", default-features = false, path = "../../io" }
sp-core = { version = "2.0.0-alpha.2", default-features = false, path = "../../core" }
[build-dependencies]
wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" }
[features]
default = [ "std" ]
std = [ "sp-runtime-interface/std", "sp-std/std", "sp-core/std", "sp-io/std" ]
@@ -0,0 +1,26 @@
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use wasm_builder_runner::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates_or_path("1.0.9", "../../../utils/wasm-builder")
.export_heap_base()
.import_memory()
.build()
}
@@ -0,0 +1,52 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Tests for the runtime interface traits and proc macros.
#![cfg_attr(not(feature = "std"), no_std)]
use sp_core::wasm_export_functions;
use sp_runtime_interface::runtime_interface;
// Include the WASM binary
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
/// This function is not used, but we require it for the compiler to include `sp-io`.
/// `sp-io` is required for its panic and oom handler.
#[no_mangle]
pub fn import_sp_io() {
sp_io::misc::print_utf8(&[]);
}
#[runtime_interface]
pub trait TestApi {
fn test_versionning(&self, _data: u32) -> bool {
// should not be called
unimplemented!()
}
}
wasm_export_functions! {
fn test_versionning_works() {
// old api allows only 42 and 50
assert!(test_api::test_versionning(42));
assert!(test_api::test_versionning(50));
assert!(!test_api::test_versionning(142));
assert!(!test_api::test_versionning(0));
}
}