Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Some fixes to compile for Android (#1063)
Browse files Browse the repository at this point in the history
* Some fixes to compile for Android

* Revert change to cli
  • Loading branch information
tomaka authored May 4, 2020
1 parent fa1536c commit 8d78cd9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", op
parking_lot = { version = "0.10.0", 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 }

[features]
Expand Down
26 changes: 16 additions & 10 deletions parachain/src/wasm_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sp_core::traits::CallInWasm;
use sp_wasm_interface::HostFunctions as _;
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};

mod validation_host;
Expand All @@ -49,21 +49,27 @@ impl ParachainExt {
}
}

/// A stub validation-pool defined when compiling for WASM.
#[cfg(target_os = "unknown")]
/// A stub validation-pool defined when compiling for Android or WASM.
#[cfg(any(target_os = "android", target_os = "unknown"))]
#[derive(Clone)]
pub struct ValidationPool {
_inner: (), // private field means not publicly-instantiable
}

#[cfg(target_os = "unknown")]
#[cfg(any(target_os = "android", target_os = "unknown"))]
impl ValidationPool {
/// Create a new `ValidationPool`.
pub fn new() -> Self {
ValidationPool { _inner: () }
}
}

/// 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.
///
/// > Note: When compiling for WASM, the `Remote` variants are not available.
Expand Down Expand Up @@ -101,7 +107,7 @@ pub enum Error {
#[display(fmt = "WASM worker error: {}", _0)]
External(String),
#[display(fmt = "Shared memory error: {}", _0)]
#[cfg(not(target_os = "unknown"))]
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
SharedMem(shared_memory::SharedMemError),
}

Expand All @@ -111,7 +117,7 @@ impl std::error::Error for Error {
Error::WasmExecutor(ref err) => Some(err),
Error::Io(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),
_ => None,
}
Expand All @@ -137,20 +143,20 @@ pub fn validate_candidate<E: Externalities + 'static>(
ExecutionMode::Local => {
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) => {
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) => {
pool.validate_candidate(validation_code, params, ext, true)
},
#[cfg(target_os = "unknown")]
#[cfg(any(target_os = "android", target_os = "unknown"))]
ExecutionMode::Remote(pool) =>
Err(Error::System(Box::<dyn std::error::Error + Send + Sync>::from(
"Remote validator not available".to_string()
) as Box<_>)),
#[cfg(target_os = "unknown")]
#[cfg(any(target_os = "android", target_os = "unknown"))]
ExecutionMode::RemoteTest(pool) =>
Err(Error::System(Box::<dyn std::error::Error + Send + Sync>::from(
"Remote validator not available".to_string()
Expand Down
2 changes: 1 addition & 1 deletion parachain/src/wasm_executor/validation_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// 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 codec::{Decode, Encode, EncodeAppend};
Expand Down
2 changes: 1 addition & 1 deletion service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub use polkadot_primitives::parachain::{CollatorId, ParachainHost};
pub use polkadot_primitives::Block;
pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256};
pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec};
#[cfg(not(target_os = "unknown"))]
#[cfg(feature = "full-node")]
pub use consensus::run_validation_worker;
pub use codec::Codec;
pub use polkadot_runtime;
Expand Down
1 change: 0 additions & 1 deletion validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub use self::shared_table::{
};
pub use self::validation_service::{ServiceHandle, ServiceBuilder};

#[cfg(not(target_os = "unknown"))]
pub use parachain::wasm_executor::run_worker as run_validation_worker;

mod dynamic_inclusion;
Expand Down

0 comments on commit 8d78cd9

Please sign in to comment.