Skip to content

sync: build for wasm - #14769

Closed
oech3 wants to merge 3 commits into
uutils:mainfrom
oech3:sync-wasi
Closed

oech3 wants to merge 3 commits into
uutils:mainfrom
oech3:sync-wasi

Conversation

@oech3

@oech3 oech3 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Syncing a file seems possible on wasip at least for.

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)

Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread Cargo.toml Outdated
@oech3
oech3 force-pushed the sync-wasi branch 9 times, most recently from 0a75721 to 4e15855 Compare September 21, 2026 17:04
Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread src/uu/sync/src/sync.rs Outdated
Comment thread src/uu/sync/src/sync.rs
@oech3
oech3 force-pushed the sync-wasi branch 3 times, most recently from ffa6449 to 196bd97 Compare September 22, 2026 05:36
@oech3

oech3 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

It seems std::fs::File::sync_fata is fdatasync. Should we drop rustix::fs::fdatasync?

@oech3
oech3 force-pushed the sync-wasi branch 2 times, most recently from 1e2c389 to 0dade4f Compare September 22, 2026 07:46
@oech3

oech3 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Permission denied on Windows...

@oech3
oech3 force-pushed the sync-wasi branch 4 times, most recently from 469590d to d320767 Compare September 23, 2026 01:02
@oech3
oech3 force-pushed the sync-wasi branch 3 times, most recently from 15b97ad to dfd1264 Compare September 23, 2026 01:22
@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 39.29%

⚠️ 118 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚡ 3 improved benchmarks
✅ 398 untouched benchmarks
⏩ 54 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Simulation three_39_bit_primes 591.3 ms 264 ms ×2.2
⚡ Simulation five_38_bit_primes 2.1 s 1.9 s +11.1%
⚡ Simulation thirteen_39_bit_primes 9.6 s 8.9 s +8.58%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing oech3:sync-wasi (3488fc4) with main (8b27533)2

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (a26a332) during the generation of this report, so 8b27533 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@oech3
oech3 requested a review from sylvestre September 23, 2026 02:16
@oech3

oech3 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

OK to merge this? I'd like to port this for simpler workspace even feature is very limited.

Comment thread src/uu/sync/src/sync.rs Outdated
Comment on lines 319 to 335
#[cfg(not(any(target_os = "linux", target_os = "android", windows)))]
fn do_sync_with_regular_file<F>(files: &[String], op: F) -> UResult<()>
where
F: Fn(std::fs::File) -> std::io::Result<()>,
{
use uucore::error::FromIo;
for path in files {
let mut f = std::fs::OpenOptions::new();
f.read(true);
// FIXME: sync_data() fails with permission denied even f.write(true) is used on Windows
#[cfg(windows)]
f.write(true);
op(f.open(path)?)
.map_err_context(|| translate!("sync-error-syncing-file", "file" => path.quote()))?;
}
Ok(())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Before this PR, syncfs/fdatasync on macOS/BSD/wasm were not compiled at all, so sync -f/sync -d on those targets was a silent no-op. The existing Linux/Android platform::open_and_reset_nonblock deliberately opens with O_NONBLOCK and resets it, specifically to avoid hanging on FIFOs. The new fallback in do_sync_with_regular_file does a plain std::fs::OpenOptions::open() with no non-blocking handling, so sync -f /path/to/fifo on macOS/BSD/wasm can now hang indefinitely instead of being a no-op.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do I just need to set O_NONBLOCK?

Comment thread src/uu/sync/src/sync.rs Outdated
Comment on lines +328 to +329
// FIXME: sync_data() fails with permission denied even f.write(true) is used on Windows
#[cfg(windows)]

@eduardomourar eduardomourar Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe there is an error in this line as this check is never compiled to Windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But I saw CI's failure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably before it was gated to not Windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Even if the test is disabled, user see the error if the cfg was removed. Is it acceptible?

@oech3

oech3 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@eduardomourar I'm fine with this PR was replaced with your one if you have knowledge more than me.
This PR does not more than making *.wasm compilable.

Comment thread src/uu/sync/src/sync.rs Outdated
@eduardomourar

Copy link
Copy Markdown
Contributor

@eduardomourar I'm fine with this PR was replaced with your one if you have knowledge more than me. This PR does not more than making *.wasm compilable.

I don't want to hijack your PR. I am just reviewing it and helping us improve the code a little bit.

@oech3
oech3 force-pushed the sync-wasi branch 3 times, most recently from 08fafdb to 3488fc4 Compare October 11, 2026 12:15
@oech3

This comment was marked as outdated.

@oech3

oech3 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

I'd like to split this PR e.g. #15733

@oech3
oech3 marked this pull request as draft October 25, 2026 05:37
@oech3
oech3 marked this pull request as ready for review October 25, 2026 15:33
@oech3
oech3 marked this pull request as draft October 25, 2026 15:36
@oech3 oech3 closed this Oct 25, 2026
@oech3
oech3 deleted the sync-wasi branch October 25, 2026 16:02
@oech3

oech3 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Oh wait! Does wasip* support NINBLOCK? I was too early to close this PR.

@oech3
oech3 restored the sync-wasi branch October 25, 2026 16:31
@oech3 oech3 reopened this Oct 25, 2026
@oech3 oech3 closed this Oct 25, 2026
@oech3
oech3 deleted the sync-wasi branch October 25, 2026 16:54
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.

3 participants