Skip to content

fix(wasm): avoid panic in split_paths on wasm#1064

Merged
reubeno merged 1 commit intomainfrom
split-paths-error-on-wasm
Mar 27, 2026
Merged

fix(wasm): avoid panic in split_paths on wasm#1064
reubeno merged 1 commit intomainfrom
split-paths-error-on-wasm

Conversation

@reubeno
Copy link
Copy Markdown
Owner

@reubeno reubeno commented Mar 17, 2026

std::env::split_paths panics on some WASM platforms. For now, let's route calls to it through the sys module and provide an alternate implementation for some targets.

@github-actions
Copy link
Copy Markdown

Test Results

    3 files     32 suites   15m 34s ⏱️
2 041 tests 2 041 ✅ 0 💤 0 ❌
6 094 runs  6 094 ✅ 0 💤 0 ❌

Results for commit 3a9790c.

@github-actions
Copy link
Copy Markdown

Public API changes for crate: brush-core

Added items

+pub fn brush_core::sys::fs::split_paths<T: core::convert::AsRef<std::ffi::os_str::OsStr> + ?core::marker::Sized>(s: &T) -> std::env::SplitPaths<'_>

Performance Benchmark Report

Benchmark name Baseline (μs) Test/PR (μs) Delta (μs) Delta %
clone_shell_object 17.05 μs 17.22 μs 0.17 μs 🟠 +1.01%
eval_arithmetic 0.15 μs 0.15 μs 0.00 μs ⚪ Unchanged
expand_one_string 1.55 μs 1.54 μs -0.01 μs ⚪ Unchanged
for_loop 27.05 μs 26.94 μs -0.11 μs ⚪ Unchanged
full_peg_complex 57.95 μs 56.68 μs -1.27 μs 🟢 -2.19%
full_peg_for_loop 6.24 μs 6.16 μs -0.08 μs 🟢 -1.36%
full_peg_nested_expansions 16.88 μs 16.44 μs -0.44 μs 🟢 -2.59%
full_peg_pipeline 4.38 μs 4.24 μs -0.14 μs 🟢 -3.22%
full_peg_simple 1.84 μs 1.82 μs -0.01 μs ⚪ Unchanged
function_call 2.94 μs 2.99 μs 0.05 μs ⚪ Unchanged
instantiate_shell 55.58 μs 55.91 μs 0.34 μs ⚪ Unchanged
instantiate_shell_with_init_scripts 26915.73 μs 27064.30 μs 148.57 μs ⚪ Unchanged
parse_peg_bash_completion 2121.66 μs 2065.32 μs -56.34 μs 🟢 -2.66%
parse_peg_complex 20.55 μs 20.05 μs -0.49 μs 🟢 -2.39%
parse_peg_for_loop 2.07 μs 2.01 μs -0.06 μs 🟢 -2.99%
parse_peg_pipeline 2.32 μs 2.09 μs -0.23 μs 🟢 -10.00%
parse_peg_simple 1.14 μs 1.12 μs -0.03 μs 🟢 -2.36%
run_echo_builtin_command 18.22 μs 18.50 μs 0.28 μs ⚪ Unchanged
tokenize_sample_script 3.50 μs 3.39 μs -0.11 μs 🟢 -3.23%

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
brush-core/src/sys/unix/fs.rs 🟠 60.19% 🟠 61.32% 🟢 1.13%
Overall Coverage 🟢 74.33% 🟢 74.33% ⚪ 0%

Minimum allowed coverage is 70%, this run produced 74.33%

Test Summary: bash-completion test suite

Outcome Count Percentage
✅ Pass 1583 75.06
❗️ Error 17 0.81
❌ Fail 155 7.35
⏩ Skip 339 16.07
❎ Expected Fail 13 0.62
✔️ Unexpected Pass 2 0.09
📊 Total 2109 100.00

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR mitigates a runtime panic on some WASM targets by routing PATH splitting through brush-core’s platform abstraction layer (crate::sys) and providing a WASM-safe fallback implementation.

Changes:

  • Introduces crate::sys::fs::split_paths with platform-specific implementations (Unix/Windows delegate to std::env::split_paths, WASM uses a : split).
  • Updates shell PATH searching to use crate::sys::fs::split_paths instead of calling std::env::split_paths directly.
  • Switches Windows/WASM platform modules to provide a real fs module rather than re-exporting the stub module directly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
brush-core/src/sys/windows/fs.rs Adds Windows split_paths wrapper delegating to std::env::split_paths.
brush-core/src/sys/windows.rs Uses a concrete fs module so split_paths can be provided on Windows.
brush-core/src/sys/wasm/mod.rs Uses a concrete fs module so split_paths can be provided on WASM.
brush-core/src/sys/wasm/fs.rs Adds WASM split_paths implementation (currently allocates and string-converts).
brush-core/src/sys/unix/fs.rs Adds Unix split_paths wrapper and routes existing code through it.
brush-core/src/shell/fs.rs Switches PATH searching to use crate::sys::fs::split_paths.

@reubeno reubeno merged commit 3e96cae into main Mar 27, 2026
47 checks passed
@reubeno reubeno deleted the split-paths-error-on-wasm branch March 27, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants