Skip to content

Commit

Permalink
rust/oak_abi: Make oak_abi no_std compatible (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaxill authored Feb 24, 2020
1 parent 9a47fc4 commit 7b150a4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
7 changes: 6 additions & 1 deletion oak/server/rust/oak_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ authors = ["David Drysdale <drysdale@google.com>"]
edition = "2018"
license = "Apache-2.0"

[features]
std = ["protobuf"]
no_std = []
default = ["std"]

[dependencies]
protobuf = "*"
protobuf = { version = "*", optional = true }

[build-dependencies]
oak_utils = "*"
Expand Down
43 changes: 40 additions & 3 deletions oak/server/rust/oak_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,47 @@

//! Type, constant and Wasm host function definitions for the Oak application binary interface.
pub use proto::oak_api::ChannelReadStatus;
pub use proto::oak_api::OakStatus;

// TODO(#638): Generate from protobuf in a no_std compatible way
#[cfg(feature = "std")]
pub mod proto;
#[cfg(feature = "std")]
mod inner {
pub use super::proto::oak_api::{ChannelReadStatus, OakStatus};
}

#[cfg(feature = "no_std")]
mod inner {
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub enum OakStatus {
OAK_STATUS_UNSPECIFIED = 0,
OK = 1,
ERR_BAD_HANDLE = 2,
ERR_INVALID_ARGS = 3,
ERR_CHANNEL_CLOSED = 4,
ERR_BUFFER_TOO_SMALL = 5,
ERR_HANDLE_SPACE_TOO_SMALL = 6,
ERR_OUT_OF_RANGE = 7,
ERR_INTERNAL = 8,
ERR_TERMINATED = 9,
ERR_CHANNEL_EMPTY = 10,
}

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub enum ChannelReadStatus {
NOT_READY = 0,
READ_READY = 1,
INVALID_CHANNEL = 2,
ORPHANED = 3,
}
}

pub use inner::*;

/// Handle used to identify read or write channel halves.
///
Expand Down
6 changes: 3 additions & 3 deletions oak/server/rust/oak_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ edition = "2018"
license = "Apache-2.0"

[features]
std = ["no-std-compat/std"]
no_std = []
std = ["no-std-compat/std", "oak_abi/std"]
no_std = ["oak_abi/no_std"]
default = ["std"]

[dependencies]
byteorder = { version = "*", default-features = false }
itertools = "*"
log = { version = "*" }
oak_abi = "=0.1.0"
oak_abi = { version = "=0.1.0", default-features = false }
protobuf = "*"
rand = { version = "*" }
wasmi = { version = "*", default-features = false, features = ["core"] }
Expand Down

0 comments on commit 7b150a4

Please sign in to comment.