Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start migrating some Wasmtime crates to no_std #8463

Merged
merged 9 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ jobs:
- run: cargo check -p wasmtime-c-api --no-default-features --features wat
- run: cargo check -p wasmtime-c-api --no-default-features --features wasi

# Checks for no_std support, ensure that crates can build on a no_std
# target
- run: rustup target add x86_64-unknown-none
- run: cargo check -p wasmtime-jit-icache-coherence
env:
CARGO_BUILD_TARGET: x86_64-unknown-none
- run: cargo check -p wasmtime-component-util
env:
CARGO_BUILD_TARGET: x86_64-unknown-none
- run: cargo check -p wasmtime-asm-macros
env:
CARGO_BUILD_TARGET: x86_64-unknown-none

# Check that wasmtime-runtime compiles with panic=abort since there's some
# #[cfg] for specifically panic=abort there.
- run: cargo check -p wasmtime-runtime
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ wasmtime-cranelift = { workspace = true, optional = true }
wasmtime-environ = { workspace = true }
wasmtime-explorer = { workspace = true, optional = true }
wasmtime-wast = { workspace = true, optional = true }
wasi-common = { workspace = true, default-features = true, features = ["exit" ], optional = true }
wasi-common = { workspace = true, default-features = true, features = ["exit"], optional = true }
wasmtime-wasi = { workspace = true, default-features = true, optional = true }
wasmtime-wasi-nn = { workspace = true, optional = true }
wasmtime-wasi-threads = { workspace = true, optional = true }
wasmtime-wasi-http = { workspace = true, optional = true }
wasmtime-runtime = { workspace = true, optional = true }
clap = { workspace = true }
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
target-lexicon = { workspace = true }
once_cell = { workspace = true }
listenfd = { version = "1.0.0", optional = true }
Expand Down Expand Up @@ -104,7 +104,7 @@ object = { workspace = true }
windows-sys = { workspace = true, features = ["Win32_System_Memory"] }

[build-dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }

[profile.release.build-override]
opt-level = 0
Expand Down Expand Up @@ -248,7 +248,7 @@ wit-component = "0.206.0"
# --------------------------
object = { version = "0.33", default-features = false, features = ['read_core', 'elf', 'std'] }
gimli = { version = "0.28.0", default-features = false, features = ['read', 'std'] }
anyhow = "1.0.22"
anyhow = { version = "1.0.22", default-features = false }
windows-sys = "0.52.0"
env_logger = "0.10"
log = { version = "0.4.8", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition.workspace = true
workspace = true

[dependencies]
anyhow = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true, features = ['std'] }
bumpalo = "3"
capstone = { workspace = true, optional = true }
cranelift-codegen-shared = { path = "./shared", version = "0.108.0" }
Expand Down
2 changes: 1 addition & 1 deletion cranelift/module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspace = true
cranelift-codegen = { workspace = true }
cranelift-control = { workspace = true }
hashbrown = { workspace = true, optional = true }
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }

Expand Down
2 changes: 1 addition & 1 deletion cranelift/reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition.workspace = true
workspace = true

[dependencies]
anyhow.workspace = true
anyhow = { workspace = true, features = ['std'] }
cranelift-codegen = { workspace = true }
smallvec = { workspace = true }
target-lexicon = { workspace = true }
2 changes: 2 additions & 0 deletions crates/asm-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! function) and additionally handles visibility across platforms. All symbols
//! should be visible to Rust but not visible externally outside of a `*.so`.

#![no_std]

cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
#[macro_export]
Expand Down
2 changes: 1 addition & 1 deletion crates/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition.workspace = true
workspace = true

[dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
base64 = "0.21.0"
postcard = { workspace = true }
directories-next = "2.0"
Expand Down
2 changes: 2 additions & 0 deletions crates/component-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![no_std]

/// Represents the possible sizes in bytes of the discriminant of a variant type in the component model
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DiscriminantSize {
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition.workspace = true
workspace = true

[dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
postcard = { workspace = true }
cpp_demangle = { version = "0.4.3", optional = true }
cranelift-entity = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/jit-icache-coherence/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace = true

[dependencies]
cfg-if = { workspace = true }
anyhow = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
workspace = true
Expand Down
11 changes: 6 additions & 5 deletions crates/jit-icache-coherence/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//! # len: usize,
//! # }
//! #
//! # fn main() -> io::Result<()> {
//! # fn main() -> anyhow::Result<()> {
//! #
//! # let run_code = || {};
//! # let code = vec![0u8; 64];
Expand Down Expand Up @@ -67,8 +67,9 @@
//!
//! [ARM Community - Caches and Self-Modifying Code]: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/caches-and-self-modifying-code

use std::ffi::c_void;
use std::io::Result;
#![no_std]

use core::ffi::c_void;

cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
Expand All @@ -91,7 +92,7 @@ cfg_if::cfg_if! {
/// after all calls to [clear_cache].
///
/// If the architecture does not require a pipeline flush, this function does nothing.
pub fn pipeline_flush_mt() -> Result<()> {
pub fn pipeline_flush_mt() -> imp::Result<()> {
imp::pipeline_flush_mt()
}

Expand All @@ -103,6 +104,6 @@ pub fn pipeline_flush_mt() -> Result<()> {
///
/// It is necessary to call [pipeline_flush_mt] after this function if you are running in a multi-threaded
/// environment.
pub unsafe fn clear_cache(ptr: *const c_void, len: usize) -> Result<()> {
pub unsafe fn clear_cache(ptr: *const c_void, len: usize) -> imp::Result<()> {
imp::clear_cache(ptr, len)
}
22 changes: 18 additions & 4 deletions crates/jit-icache-coherence/src/libc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use std::ffi::c_void;
use std::io::Result;
use core::ffi::c_void;

#[cfg(any(target_os = "linux", target_os = "android"))]
extern crate std;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub use std::io::Result;

#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub use anyhow::Result;

#[cfg(all(
target_arch = "aarch64",
any(target_os = "linux", target_os = "android")
))]
mod details {
extern crate std;

use super::*;
use libc::{syscall, EINVAL, EPERM};
use std::io::Error;
Expand Down Expand Up @@ -87,20 +96,25 @@ mod details {
any(target_os = "linux", target_os = "android")
)))]
mod details {
pub(crate) fn pipeline_flush_mt() -> std::io::Result<()> {
// NB: this uses `anyhow::Result` instead of `std::io::Result` to compile on
// `no_std`.
pub(crate) fn pipeline_flush_mt() -> super::Result<()> {
Ok(())
}
}

#[cfg(all(target_arch = "riscv64", target_os = "linux"))]
fn riscv_flush_icache(start: u64, end: u64) -> Result<()> {
cfg_if::cfg_if! {
if #[cfg(feature = "one-core")] {
use std::arch::asm;
use core::arch::asm;
unsafe {
asm!("fence.i");
};
Ok(())
} else {
extern crate std;

match unsafe {
libc::syscall(
{
Expand Down
4 changes: 2 additions & 2 deletions crates/jit-icache-coherence/src/miri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ffi::c_void;
use std::io::Result;
pub use anyhow::Result;
use core::ffi::c_void;

pub(crate) fn pipeline_flush_mt() -> Result<()> {
Ok(())
Expand Down
6 changes: 5 additions & 1 deletion crates/jit-icache-coherence/src/win.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
extern crate std;

use std::ffi::c_void;
use std::io::{Error, Result};
use std::io::Error;
use windows_sys::Win32::System::Diagnostics::Debug::FlushInstructionCache;
use windows_sys::Win32::System::Threading::FlushProcessWriteBuffers;
use windows_sys::Win32::System::Threading::GetCurrentProcess;

pub use std::io::Result;

/// See docs on [crate::pipeline_flush_mt] for a description of what this function is trying to do.
#[inline]
pub(crate) fn pipeline_flush_mt() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "Apache-2.0 WITH LLVM-exception"
workspace = true

[dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
wasi = "0.11.0"
wasi-nn = "0.6.0"
wit-bindgen = { workspace = true, features = ['default'] }
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-preview1-component-adapter/verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ workspace = true
[dependencies]
wasmparser = { workspace = true }
wat = { workspace = true }
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
2 changes: 1 addition & 1 deletion examples/min-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ rust-version.workspace = true
workspace = true

[dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, features = ['std'] }
libloading = "0.8"
object = { workspace = true }
Loading