Some fixes to compile for Android (#1063)

* Some fixes to compile for Android

* Revert change to cli
This commit is contained in:
Pierre Krieger
2020-05-04 16:04:33 +02:00
committed by GitHub
parent 3b309c776c
commit 626a4aeccf
5 changed files with 19 additions and 14 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", op
parking_lot = { version = "0.10.0", optional = true } parking_lot = { version = "0.10.0", optional = true }
log = { version = "0.4.8", optional = true } log = { version = "0.4.8", optional = true }
[target.'cfg(not(target_os = "unknown"))'.dependencies] [target.'cfg(not(any(target_os = "android", target_os = "unknown")))'.dependencies]
shared_memory = { version = "0.10.0", optional = true } shared_memory = { version = "0.10.0", optional = true }
[features] [features]
+16 -10
View File
@@ -28,7 +28,7 @@ use sp_core::traits::CallInWasm;
use sp_wasm_interface::HostFunctions as _; use sp_wasm_interface::HostFunctions as _;
use sp_externalities::Extensions; use sp_externalities::Extensions;
#[cfg(not(target_os = "unknown"))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
pub use validation_host::{run_worker, ValidationPool, EXECUTION_TIMEOUT_SEC}; pub use validation_host::{run_worker, ValidationPool, EXECUTION_TIMEOUT_SEC};
mod validation_host; mod validation_host;
@@ -49,14 +49,14 @@ impl ParachainExt {
} }
} }
/// A stub validation-pool defined when compiling for WASM. /// A stub validation-pool defined when compiling for Android or WASM.
#[cfg(target_os = "unknown")] #[cfg(any(target_os = "android", target_os = "unknown"))]
#[derive(Clone)] #[derive(Clone)]
pub struct ValidationPool { pub struct ValidationPool {
_inner: (), // private field means not publicly-instantiable _inner: (), // private field means not publicly-instantiable
} }
#[cfg(target_os = "unknown")] #[cfg(any(target_os = "android", target_os = "unknown"))]
impl ValidationPool { impl ValidationPool {
/// Create a new `ValidationPool`. /// Create a new `ValidationPool`.
pub fn new() -> Self { pub fn new() -> Self {
@@ -64,6 +64,12 @@ impl ValidationPool {
} }
} }
/// A stub function defined when compiling for Android or WASM.
#[cfg(any(target_os = "android", target_os = "unknown"))]
pub fn run_worker(_: &str) -> Result<(), String> {
Err("Cannot run validation worker on this platform".to_string())
}
/// WASM code execution mode. /// WASM code execution mode.
/// ///
/// > Note: When compiling for WASM, the `Remote` variants are not available. /// > Note: When compiling for WASM, the `Remote` variants are not available.
@@ -101,7 +107,7 @@ pub enum Error {
#[display(fmt = "WASM worker error: {}", _0)] #[display(fmt = "WASM worker error: {}", _0)]
External(String), External(String),
#[display(fmt = "Shared memory error: {}", _0)] #[display(fmt = "Shared memory error: {}", _0)]
#[cfg(not(target_os = "unknown"))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
SharedMem(shared_memory::SharedMemError), SharedMem(shared_memory::SharedMemError),
} }
@@ -111,7 +117,7 @@ impl std::error::Error for Error {
Error::WasmExecutor(ref err) => Some(err), Error::WasmExecutor(ref err) => Some(err),
Error::Io(ref err) => Some(err), Error::Io(ref err) => Some(err),
Error::System(ref err) => Some(&**err), Error::System(ref err) => Some(&**err),
#[cfg(not(target_os = "unknown"))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
Error::SharedMem(ref err) => Some(err), Error::SharedMem(ref err) => Some(err),
_ => None, _ => None,
} }
@@ -137,20 +143,20 @@ pub fn validate_candidate<E: Externalities + 'static>(
ExecutionMode::Local => { ExecutionMode::Local => {
validate_candidate_internal(validation_code, &params.encode(), ext) validate_candidate_internal(validation_code, &params.encode(), ext)
}, },
#[cfg(not(target_os = "unknown"))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
ExecutionMode::Remote(pool) => { ExecutionMode::Remote(pool) => {
pool.validate_candidate(validation_code, params, ext, false) pool.validate_candidate(validation_code, params, ext, false)
}, },
#[cfg(not(target_os = "unknown"))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
ExecutionMode::RemoteTest(pool) => { ExecutionMode::RemoteTest(pool) => {
pool.validate_candidate(validation_code, params, ext, true) pool.validate_candidate(validation_code, params, ext, true)
}, },
#[cfg(target_os = "unknown")] #[cfg(any(target_os = "android", target_os = "unknown"))]
ExecutionMode::Remote(pool) => ExecutionMode::Remote(pool) =>
Err(Error::System(Box::<dyn std::error::Error + Send + Sync>::from( Err(Error::System(Box::<dyn std::error::Error + Send + Sync>::from(
"Remote validator not available".to_string() "Remote validator not available".to_string()
) as Box<_>)), ) as Box<_>)),
#[cfg(target_os = "unknown")] #[cfg(any(target_os = "android", target_os = "unknown"))]
ExecutionMode::RemoteTest(pool) => ExecutionMode::RemoteTest(pool) =>
Err(Error::System(Box::<dyn std::error::Error + Send + Sync>::from( Err(Error::System(Box::<dyn std::error::Error + Send + Sync>::from(
"Remote validator not available".to_string() "Remote validator not available".to_string()
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
#![cfg(not(target_os = "unknown"))] #![cfg(not(any(target_os = "android", target_os = "unknown")))]
use std::{process, env, sync::Arc, sync::atomic, mem}; use std::{process, env, sync::Arc, sync::atomic, mem};
use codec::{Decode, Encode, EncodeAppend}; use codec::{Decode, Encode, EncodeAppend};
+1 -1
View File
@@ -45,7 +45,7 @@ pub use polkadot_primitives::parachain::{CollatorId, ParachainHost};
pub use polkadot_primitives::Block; pub use polkadot_primitives::Block;
pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256}; pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256};
pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec}; pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec};
#[cfg(not(target_os = "unknown"))] #[cfg(feature = "full-node")]
pub use consensus::run_validation_worker; pub use consensus::run_validation_worker;
pub use codec::Codec; pub use codec::Codec;
pub use polkadot_runtime; pub use polkadot_runtime;
-1
View File
@@ -53,7 +53,6 @@ pub use self::shared_table::{
}; };
pub use self::validation_service::{ServiceHandle, ServiceBuilder}; pub use self::validation_service::{ServiceHandle, ServiceBuilder};
#[cfg(not(target_os = "unknown"))]
pub use parachain::wasm_executor::run_worker as run_validation_worker; pub use parachain::wasm_executor::run_worker as run_validation_worker;
mod dynamic_inclusion; mod dynamic_inclusion;