Skip to content

Commit

Permalink
fix(wasm): Get the wasi-hermes-component-adapter working with the new…
Browse files Browse the repository at this point in the history
… rust builders.
  • Loading branch information
stevenj committed May 7, 2024
1 parent 433a72b commit f18aa29
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 169 deletions.
15 changes: 6 additions & 9 deletions wasm/wasi-hermes-component-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

[workspace]
resolver = "2"
members = [
"./byte-array-literals"
]

[workspace.package]
edition = "2021"
version = "0.0.1"
version = "0.0.2"
authors = [
"Apisit Ritreungroj <apisit.ritreungroj@iohk.io>",
"Steven Johnson <steven.johnson@iohk.io>"
Expand Down Expand Up @@ -53,11 +50,11 @@ unreachable = "deny"
missing_docs_in_private_items = "deny"

[workspace.dependencies]
wit-bindgen = { version = "0.16.0", default-features = false }
wasi = { version = "0.11.0", default-features = false }
byte-array-literals = { path = "./byte-array-literals", version = "0.0.1" }
wasm-encoder = "0.38.1"
object = { version = "0.32.1", default-features = false }
wit-bindgen = { version = "0.19.2", default-features = false } # Anything after 0.19.2 does not work. Do not bump version.
wasi = { version = "0.11.0", default-features = false } # Needs to be 0.11 or it fails to build. Do not bump version.
byte-array-literals = { git = "https://github.com/bytecodealliance/wasmtime", tag = "v20.0.1" }
wasm-encoder = "0.206.0"
object = { version = "0.35.0", default-features = false }

[package]
name = "wasi-hermes-component-adapter"
Expand Down
16 changes: 9 additions & 7 deletions wasm/wasi-hermes-component-adapter/Earthfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
VERSION 0.7
VERSION 0.8

IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:fix/improve-rust-builder-sj AS rust-ci

#cspell: words rustfmt wasi

# Set up our target toolchains, and copy source files.
builder:
DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.11.2+SETUP
DO rust-ci+SETUP

COPY --dir .cargo .config src byte-array-literals .
COPY --dir .cargo .config src .
COPY ..+wasi-src/wasi ../wasi
COPY Cargo.toml build.rs .
COPY clippy.toml deny.toml rustfmt.toml .
Expand All @@ -15,7 +17,7 @@ builder:
check:
FROM +builder

RUN /scripts/std_checks.py
DO rust-ci+EXECUTE --cmd="/scripts/std_checks.py"

# Test which runs check with all supported host tooling. Needs qemu or rosetta to run.
# Only used to validate tooling is working across host toolsets.
Expand All @@ -26,9 +28,9 @@ all-hosts-check:
build:
FROM +builder

RUN /scripts/std_build.py --disable_tests \
--disable_benches \
--build_flags="--target=wasm32-unknown-unknown"
DO rust-ci+EXECUTE \
--cmd="/scripts/std_build.py --disable_tests --disable_benches --disable_docs --build_flags=\"--target=wasm32-unknown-unknown\" --verbose" \
--output="wasm32-unknown-unknown/release/wasi_snapshot_hermes.wasm"

SAVE ARTIFACT target/wasm32-unknown-unknown/release/wasi_snapshot_hermes.wasm wasi-hermes-component-adapter.wasm

Expand Down
2 changes: 2 additions & 0 deletions wasm/wasi-hermes-component-adapter/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn build_raw_intrinsics() -> Vec<u8> {
GlobalType {
val_type: ValType::I32,
mutable: true,
shared: false,
},
&ConstExpr::i32_const(0),
);
Expand All @@ -106,6 +107,7 @@ fn build_raw_intrinsics() -> Vec<u8> {
GlobalType {
val_type: ValType::I32,
mutable: true,
shared: false,
},
&ConstExpr::i32_const(0),
);
Expand Down
13 changes: 0 additions & 13 deletions wasm/wasi-hermes-component-adapter/byte-array-literals/Cargo.toml

This file was deleted.

16 changes: 0 additions & 16 deletions wasm/wasi-hermes-component-adapter/byte-array-literals/README.md

This file was deleted.

108 changes: 0 additions & 108 deletions wasm/wasi-hermes-component-adapter/byte-array-literals/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion wasm/wasi-hermes-component-adapter/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.75.0"
channel = "1.78"
profile = "default"
targets = ["wasm32-unknown-unknown"]
2 changes: 1 addition & 1 deletion wasm/wasi-hermes-component-adapter/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl Descriptors {
len: 0,
};
import_alloc.with_arena(arena, || unsafe {
get_preopens_import(&mut list as *mut _)
get_preopens_import(std::ptr::from_mut(&mut list))
});
let preopens: &'static [Preopen] = unsafe {
// allocation comes from long lived arena, so it is safe to
Expand Down
26 changes: 12 additions & 14 deletions wasm/wasi-hermes-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ pub unsafe extern "C" fn fd_readdir(
// Copy a `dirent` describing this entry into the destination `buf`,
// truncating it if it doesn't fit entirely.
let bytes = slice::from_raw_parts(
(&dirent as *const wasi::Dirent).cast::<u8>(),
(std::ptr::from_ref::<wasi::Dirent>(&dirent)).cast::<u8>(),
size_of::<Dirent>(),
);
let dirent_bytes_to_copy = buf.len().min(bytes.len());
Expand Down Expand Up @@ -2277,10 +2277,8 @@ pub unsafe extern "C" fn sock_shutdown(_fd: Fd, _how: Sdflags) -> Errno {
#[allow(clippy::missing_docs_in_private_items)]
fn datetime_to_timestamp(datetime: Option<filesystem::Datetime>) -> Timestamp {
match datetime {
Some(datetime) => {
u64::from(datetime.nanoseconds)
.saturating_add(datetime.seconds.saturating_mul(1_000_000_000))
},
Some(datetime) => u64::from(datetime.nanoseconds)
.saturating_add(datetime.seconds.saturating_mul(1_000_000_000)),
None => 0,
}
}
Expand Down Expand Up @@ -2493,7 +2491,7 @@ pub struct File {
/// The handle to the preview2 descriptor that this file is referencing.
fd: filesystem::Descriptor,

/// The descriptor type, as supplied by filesystem::get_type at opening
/// The descriptor type, as supplied by `filesystem::get_type` at opening
descriptor_type: filesystem::DescriptorType,

/// The current-position pointer.
Expand All @@ -2502,9 +2500,9 @@ pub struct File {
/// In append mode, all writes append to the file.
append: bool,

/// In blocking mode, read and write calls dispatch to blocking_read and
/// blocking_check_write on the underlying streams. When false, read and write
/// dispatch to stream's plain read and check_write.
/// In blocking mode, read and write calls dispatch to `blocking_read` and
/// `blocking_check_write` on the underlying streams. When false, read and write
/// dispatch to stream's plain read and `check_write`.
blocking_mode: BlockingMode,
}

Expand Down Expand Up @@ -2543,7 +2541,7 @@ struct State {
/// Storage of mapping from preview1 file descriptors to preview2 file
/// descriptors.
///
/// Do not use this member directly - use State::descriptors() to ensure
/// Do not use this member directly - use `State::descriptors()` to ensure
/// lazy initialization happens.
descriptors: RefCell<Option<Descriptors>>,

Expand All @@ -2553,7 +2551,7 @@ struct State {

/// Long-lived bump allocated memory arena.
///
/// This is used for the cabi_export_realloc to allocate data passed to the
/// This is used for the `cabi_export_realloc` to allocate data passed to the
/// `run` entrypoint. Allocations in this arena are safe to use for
/// the lifetime of the State struct. It may also be used for import allocations
/// which need to be long-lived, by using `import_alloc.with_arena`.
Expand Down Expand Up @@ -2797,7 +2795,7 @@ impl State {

/// Mut accessor for the descriptors member that ensures it is properly initialized
#[allow(clippy::unreachable)]
fn descriptors_mut(&self) -> impl DerefMut + Deref<Target = Descriptors> + '_ {
fn descriptors_mut(&self) -> impl DerefMut<Target = Descriptors> + '_ {
let mut d = self
.descriptors
.try_borrow_mut()
Expand Down Expand Up @@ -2825,7 +2823,7 @@ impl State {
};
self.import_alloc
.with_arena(&self.long_lived_arena, || unsafe {
get_environment_import(&mut list as *mut _);
get_environment_import(std::ptr::from_mut(&mut list));
});
self.env_vars.set(Some(unsafe {
// allocation comes from long lived arena, so it is safe to
Expand Down Expand Up @@ -2853,7 +2851,7 @@ impl State {
};
self.import_alloc
.with_arena(&self.long_lived_arena, || unsafe {
get_args_import(&mut list as *mut _);
get_args_import(std::ptr::from_mut(&mut list));
});
self.args.set(Some(unsafe {
// allocation comes from long lived arena, so it is safe to
Expand Down

0 comments on commit f18aa29

Please sign in to comment.