Skip to content
Open
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# fs
OPENDAL_FS_ROOT=/path/to/dir
OPENDAL_FS_ATOMIC_WRITE_DIR=/path/to/tempdir
# wasi-fs - WASI Filesystem (requires wasm32-wasip2 target + wasmtime)
# OPENDAL_WASI_FS_ROOT=/
# cos
OPENDAL_COS_BUCKET=opendal-testing-1318209832
OPENDAL_COS_ENDPOINT=https://cos.ap-singapore.myqcloud.com
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/test_wasi_fs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Check WASI-FS Service

on:
push:
branches: [main]
paths:
- 'core/services/wasi-fs/**'
- 'core/core/src/**'
- '.github/workflows/test_wasi_fs.yml'
pull_request:
branches: [main]
paths:
- 'core/services/wasi-fs/**'
- 'core/core/src/**'
- '.github/workflows/test_wasi_fs.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Setup Rust toolchain
uses: ./.github/actions/setup

- name: Add wasm32-wasip2 target
run: rustup target add wasm32-wasip2

# Verify the wasi-fs service compiles for the WASI target.
# Note: Full behavior tests cannot run because tokio doesn't support wasm32-wasip2.
# The service uses blocking WASI Preview 2 APIs which work correctly at runtime.
- name: Check wasi-fs compiles
working-directory: core
run: |
cargo check --target wasm32-wasip2 \
--features services-wasi-fs \
-p opendal
23 changes: 23 additions & 0 deletions core/Cargo.lock

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

2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ services-vercel-artifacts = ["opendal-core/services-vercel-artifacts"]
services-vercel-blob = ["dep:opendal-service-vercel-blob"]
services-webdav = ["opendal-core/services-webdav"]
services-webhdfs = ["opendal-core/services-webhdfs"]
services-wasi-fs = ["dep:opendal-service-wasi-fs"]
services-yandex-disk = ["opendal-core/services-yandex-disk"]
tests = ["opendal-core/tests"]

Expand Down Expand Up @@ -218,6 +219,7 @@ opendal-service-sled = { path = "services/sled", version = "0.55.0", optional =
opendal-service-s3 = { path = "services/s3", version = "0.55.0", optional = true, default-features = false }
opendal-service-tikv = { path = "services/tikv", version = "0.55.0", optional = true, default-features = false }
opendal-service-vercel-blob = { path = "services/vercel-blob", version = "0.55.0", optional = true, default-features = false }
opendal-service-wasi-fs = { path = "services/wasi-fs", version = "0.55.0", optional = true, default-features = false }

[dev-dependencies]
anyhow = { version = "1.0.100", features = ["std"] }
Expand Down
18 changes: 12 additions & 6 deletions core/core/src/raw/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ use std::ops::{Add, AddAssign, Sub, SubAssign};
use std::str::FromStr;

pub use std::time::{Duration, UNIX_EPOCH};
#[cfg(not(target_arch = "wasm32"))]
// For native and WASI targets, use std::time
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub use std::time::{Instant, SystemTime};
#[cfg(target_arch = "wasm32")]
// For browser wasm (target_os = "unknown"), use web_time
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub use web_time::{Instant, SystemTime};

/// An instant in time represented as the number of nanoseconds since the Unix epoch.
Expand Down Expand Up @@ -179,12 +181,14 @@ impl From<jiff::Timestamp> for Timestamp {

impl From<Timestamp> for SystemTime {
fn from(ts: Timestamp) -> Self {
#[cfg(not(target_arch = "wasm32"))]
// For native and WASI targets, use std::time directly
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
{
SystemTime::from(ts.0)
}

#[cfg(target_arch = "wasm32")]
// For browser wasm (target_os = "unknown"), use web_time
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
{
use std::time::SystemTime as StdSystemTime;

Expand All @@ -199,12 +203,14 @@ impl TryFrom<SystemTime> for Timestamp {

fn try_from(t: SystemTime) -> Result<Self> {
let t = {
#[cfg(not(target_arch = "wasm32"))]
// For native and WASI targets, use std::time directly
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
{
t
}

#[cfg(target_arch = "wasm32")]
// For browser wasm (target_os = "unknown"), use web_time
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
{
<web_time::SystemTime as web_time::web::SystemTimeExt>::to_std(t)
}
Expand Down
59 changes: 59 additions & 0 deletions core/scripts/test_wasi_fs.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to not use scripts. We can just move those logic to github workflows.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to not use scripts. We can just move those logic to github workflows.

@Xuanwo you mean inlining the script into the github workflow?

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Test runner for wasi-fs service
# Requires: wasmtime, wasm32-wasip2 target

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CORE_DIR="$(dirname "$SCRIPT_DIR")"
TEST_DIR="${TEST_DIR:-/tmp/opendal-wasi-fs-test}"

echo "=== WASI-FS Behavior Test Runner ==="
echo "Test directory: $TEST_DIR"

# Create test directory
mkdir -p "$TEST_DIR"

# Build behavior tests for wasm32-wasip2
echo "Building behavior tests for wasm32-wasip2..."
cd "$CORE_DIR"
cargo build --tests --target wasm32-wasip2 --features tests,services-wasi-fs

# Find the test binary
TEST_BINARY=$(find target/wasm32-wasip2/debug/deps -name "behavior-*.wasm" | head -1)

if [ -z "$TEST_BINARY" ]; then
echo "Error: Could not find behavior test binary"
exit 1
fi

echo "Running tests with wasmtime..."
echo "Binary: $TEST_BINARY"

# Run with wasmtime, granting access to test directory
OPENDAL_TEST=wasi-fs \
OPENDAL_WASI_FS_ROOT=/ \
wasmtime run \
--dir "$TEST_DIR::/" \
--env "OPENDAL_TEST=wasi-fs" \
--env "OPENDAL_WASI_FS_ROOT=/" \
"$TEST_BINARY"

echo "=== Tests completed ==="
40 changes: 40 additions & 0 deletions core/services/wasi-fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
description = "Apache OpenDAL WASI filesystem service implementation"
name = "opendal-service-wasi-fs"

authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[package.metadata.docs.rs]
all-features = true

[dependencies]
opendal-core = { path = "../../core", version = "0.55.0", default-features = false }

ctor = { workspace = true }
serde = { workspace = true, features = ["derive"] }

[target.'cfg(all(target_arch = "wasm32", target_os = "wasi"))'.dependencies]
wasi = "0.14.7"
Loading