Skip to content

Commit e66160a

Browse files
committed
ln: add WASI support via symlink_path
On wasm32-wasip1, std::os::unix::fs::symlink is not available, but WASI preview 1 provides path_symlink which Rust exposes as std::os::wasi::fs::symlink_path. Import it under the symlink alias so the existing call site works without changes. Follows the same pattern as cp.rs for enabling wasi_ext.
1 parent 3ba572b commit e66160a

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/uu/ln/src/ln.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6+
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
7+
68
// spell-checker:ignore (ToDO) srcpath targetpath EEXIST
79

810
use clap::{Arg, ArgAction, Command};
@@ -21,6 +23,8 @@ use thiserror::Error;
2123

2224
#[cfg(any(unix, target_os = "redox"))]
2325
use std::os::unix::fs::symlink;
26+
#[cfg(target_os = "wasi")]
27+
use std::os::wasi::fs::symlink_path as symlink;
2428
#[cfg(windows)]
2529
use std::os::windows::fs::{symlink_dir, symlink_file};
2630
use std::path::{Path, PathBuf};
@@ -489,10 +493,3 @@ pub fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> std::io::R
489493
}
490494
}
491495

492-
#[cfg(target_os = "wasi")]
493-
fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(_src: P1, _dst: P2) -> std::io::Result<()> {
494-
Err(std::io::Error::new(
495-
std::io::ErrorKind::Unsupported,
496-
"symlinks not supported on this platform",
497-
))
498-
}

0 commit comments

Comments
 (0)