Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
fix WASM API generation
  • Loading branch information
rphmeier committed Feb 8, 2018
commit 3a691b235c7427ec97ea41b2be4b233d7a57d0f9
1 change: 0 additions & 1 deletion polkadot/runtime/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use rstd::prelude::*;
use runtime::{system, parachains, consensus, session};

impl_stubs!(
Expand Down
6 changes: 3 additions & 3 deletions polkadot/runtime/src/genesismap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

//! Tool for creating the genesis block.

use std::collections::HashMap;
use runtime_io::twox_128;
use codec::{KeyedVec, Joiner};
use support::Hashable;
use polkadot_primitives::{BlockNumber, Block, AccountId};
use std::collections::HashMap;
use runtime_io::twox_128;
use runtime::staking::Balance;
use support::Hashable;

/// Configuration of a general Polkadot genesis block.
pub struct GenesisConfig {
Expand Down
4 changes: 3 additions & 1 deletion polkadot/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ extern crate hex_literal;
#[macro_use]
pub mod support;
pub mod runtime;
pub mod genesismap;
pub mod api;

#[cfg(feature = "std")]
pub mod genesismap;

/// Type definitions and helpers for transactions.
pub mod transaction {
use rstd::ops;
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions substrate/codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]

#[macro_use]
extern crate substrate_runtime_std as rstd;

mod endiansensitive;
Expand Down
2 changes: 2 additions & 0 deletions substrate/codec/src/slicable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ macro_rules! tuple_impl {

#[allow(non_snake_case)]
mod inner_tuple_impl {
use rstd::vec::Vec;

use super::{Input, Slicable};
tuple_impl!(A, B, C, D, E, F, G, H, I, J, K,);
}
Expand Down
56 changes: 27 additions & 29 deletions substrate/runtime-io/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,34 +182,32 @@ pub fn print<T: Printable + Sized>(value: T) {
#[macro_export]
macro_rules! impl_stubs {
( $( $new_name:ident => $invoke:expr ),* ) => {
pub mod _internal {
$(
#[no_mangle]
pub fn $new_name(input_data: *mut u8, input_len: usize) -> u64 {
let mut input = if input_len == 0 {
&[0u8; 0]
} else {
unsafe {
$crate::slice::from_raw_parts(input_data, input_len)
}
};

let input = match $crate::codec::Slicable::from_slice(&mut input) {
Some(input) => input,
None => panic!("Bad input data provided to {}", stringify!($name)),
};

let output = ($invoke)(input);
let output = $crate::codec::Slicable::to_vec(&output);
let res = output.as_ptr() as u64 + ((output.len() as u64) << 32);

// Leak the output vector to avoid it being freed.
// This is fine in a WASM context since the heap
// will be discarded after the call.
::core::mem::forget(output);
res
}
)*
}
$(
#[no_mangle]
pub fn $new_name(input_data: *mut u8, input_len: usize) -> u64 {
let mut input = if input_len == 0 {
&[0u8; 0]
} else {
unsafe {
$crate::slice::from_raw_parts(input_data, input_len)
}
};

let input = match $crate::codec::Slicable::decode(&mut input) {
Some(input) => input,
None => panic!("Bad input data provided to {}", stringify!($name)),
};

let output = ($invoke)(input);
let output = $crate::codec::Slicable::to_vec(&output);
let res = output.as_ptr() as u64 + ((output.len() as u64) << 32);

// Leak the output vector to avoid it being freed.
// This is fine in a WASM context since the heap
// will be discarded after the call.
::core::mem::forget(output);
res
}
)*
}
}
1 change: 1 addition & 0 deletions substrate/runtime-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#![cfg_attr(not(feature = "std"), feature(lang_items))]
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#![cfg_attr(not(feature = "std"), feature(macro_reexport))]

#![cfg_attr(feature = "std", doc = "Polkadot runtime standard library as compiled when linked with Rust's standard library.")]
#![cfg_attr(not(feature = "std"), doc = "Polkadot's runtime standard library as compiled without Rust's standard library.")]
Expand Down
1 change: 1 addition & 0 deletions substrate/runtime-std/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

#[cfg(feature = "nightly")]
#[macro_reexport(vec)]
extern crate alloc;
#[cfg(feature = "nightly")]
extern crate pwasm_libc;
Expand Down