Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Land preview2-prototyping's Wasi Preview 2 implementation into wasmtime #6391

Merged
merged 289 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
289 commits
Select commit Hold shift + click to select a range
18a8d26
Implement host file flags and type functions. (#42)
sunfishcode Dec 24, 2022
310fdbc
Implement `command` exit statuses. (#40)
sunfishcode Dec 24, 2022
3dabe07
implement `wasi-filesystem::readdir` and related functions (#45)
dicej Jan 4, 2023
7387d3a
fix compile failed by wasmtime::component::Error dropped (#46)
fuxiaohei Jan 4, 2023
b2fb8b9
update `readdir` etc to use new error handling scheme (#47)
dicej Jan 4, 2023
d833bc6
Add `close` functions for clock handles. (#39)
sunfishcode Jan 6, 2023
44eebc5
Minor cleanups (#49)
sunfishcode Jan 6, 2023
a091d61
fix a couple of host/src/main.rs issues (#51)
dicej Jan 9, 2023
2d61276
Implement file append functionality. (#50)
sunfishcode Jan 9, 2023
8eaa35c
Add CI tests for Windows and start tidying up Windows support.
sunfishcode Dec 24, 2022
7721c2b
Rename AsBorrowedHandleOrSocket to AsHandleOrSocket.
sunfishcode Dec 24, 2022
0a10f44
Remove the `get_nonblocking` method, which is no longer needed.
sunfishcode Dec 27, 2022
ac3f305
Update to cap-std 1.0.3.
sunfishcode Dec 24, 2022
08150fe
Fix compilation on Windows.
sunfishcode Dec 27, 2022
1fe86b4
Merge the Windows and Unix `poll_oneoff` implementations.
sunfishcode Dec 27, 2022
1cd1474
Add the ability to `poll` on non-OS-stream objects.
sunfishcode Dec 27, 2022
d27d9f0
Fix some bugs turned up in the Wasmtime testsuite.
sunfishcode Dec 27, 2022
68f8fb3
Fix a test to open a directory handle in a way that works on Windows.
sunfishcode Dec 28, 2022
02ae36e
Use `Dir::open_ambient_dir` to open directories.
sunfishcode Jan 17, 2023
09692b0
Teach poll_oneoff how to poll for immediately-available I/O
sunfishcode Jan 9, 2023
934ba0e
Install the wasm targets for nightly.
sunfishcode Jan 9, 2023
ba9e428
Make `subscribe_monotonic_clock` infallible.
sunfishcode Jan 18, 2023
266effe
Remove eager num_ready_bytes call.
sunfishcode Jan 18, 2023
5946561
Implement `sync` and `datasync` on files and directories.
sunfishcode Jan 11, 2023
940747c
Fix directory opening on Windows.
sunfishcode Jan 18, 2023
f724bb1
Remove a redundant check.
sunfishcode Jan 18, 2023
ee0fdad
Import the Wasmtime WASI tests. (#64)
sunfishcode Jan 18, 2023
457ae4d
implement some filesystem primitives (#65)
pchickey Jan 19, 2023
af3b2a0
Change the filesystem timestamp to seconds+nanoseconds. (#55)
sunfishcode Jan 21, 2023
479661d
On Windows, ignore access-denied errors from `sync_all`. (#67)
sunfishcode Jan 23, 2023
d238f9a
Rename the `wasi` world to `wasi-command`. (#61)
sunfishcode Jan 24, 2023
7a10820
Update wasmtime and wit-bindgen (#68)
alexcrichton Jan 25, 2023
7711ed8
Rename `wasi-future` to `waitable`. (#70)
sunfishcode Jan 30, 2023
ef8df43
update `wit-component` to pull in https://github.com/bytecodealliance…
dicej Feb 1, 2023
eefa54f
Merge pull request #74 from dicej/use-realloc
dicej Feb 1, 2023
689f20f
Add basic TCP socket APIs. (#33)
sunfishcode Feb 2, 2023
89ce28a
update wasm-tools, plus minor build fix (#75)
pchickey Feb 3, 2023
bb95c24
Fix `poll_oneoff`'s timeout value when no timeout is requested. (#76)
sunfishcode Feb 4, 2023
2ae727c
Split wasi-stream into separate input and output stream types. (#73)
sunfishcode Feb 6, 2023
d006b1b
wasi-tests: add configuration to ignore rights readback (#81)
pchickey Feb 7, 2023
e6a81fb
use OpenOptionsSyncExt to support opening with FdFlags::SYNC family
Feb 6, 2023
a36cdd6
test-programs builder: rerun if test-programs source changes
Feb 6, 2023
aa4cf13
Fill in remaining preview1-based filesystem todos hit by wasi-tests (…
pchickey Feb 9, 2023
b42c6bd
short-circuit reentrance when allocating stack and `State` (#83)
dicej Feb 13, 2023
abf5b1c
Move to crates.io/releases of dependencies (#84)
alexcrichton Feb 13, 2023
dd0c03e
Update wasi-filesystem, wasi-clocks, wasi-io, and wasi-poll.
sunfishcode Feb 15, 2023
8b2da4f
rustfmt
sunfishcode Feb 15, 2023
6f31e84
Merge pull request #87 from bytecodealliance/sunfishcode/update-wasi
pchickey Feb 15, 2023
3037d41
wasi-common: put env and preopens back in WasiCtx
Feb 9, 2023
8384ac0
get environment and preopens through import functions
Feb 9, 2023
dc645a2
Merge pull request #90 from bytecodealliance/pch/import_preopens_envi…
pchickey Feb 17, 2023
0eb8dd2
Make Preview2's directory iterator omit `.` and `..`. (#89)
sunfishcode Feb 21, 2023
9a10e85
Fix timestamp-to-nanosecond conversion in the adapter (#93)
alexcrichton Feb 22, 2023
31cce7a
Depend on Wasmtime from crates.io (#95)
alexcrichton Feb 24, 2023
ea56fba
Rebase on the new wasi-sockets. (#91)
sunfishcode Feb 25, 2023
9915800
Allow preopen file descriptors to be closed. (#96)
sunfishcode Feb 27, 2023
08b1d5e
Make `read-via-stream` etc. infallible. (#98)
sunfishcode Mar 1, 2023
70f0ef5
Rebase on the wasi-cli world. (#100)
sunfishcode Mar 6, 2023
66fbb0e
Co-habitate with wasi-common from wasmtime
elliottt Feb 1, 2023
be9ef1f
Merge pull request #102 from bytecodealliance/trevor/wasi-common-linking
elliottt Mar 7, 2023
2e4df87
code motion: cli related feature names (#104)
pchickey Mar 8, 2023
6771d58
Update to the latest wit files.
sunfishcode Feb 27, 2023
63ae90f
Support command-line argument preopens.
sunfishcode Mar 8, 2023
3e353c2
Merge pull request #106 from bytecodealliance/sunfishcode/update-wit
pchickey Mar 8, 2023
8a6e1e7
drop cli- prefix from reactor, command features & artifact names
Mar 8, 2023
c3453b5
Merge pull request #107 from bytecodealliance/pch/features_drop_cli
pchickey Mar 8, 2023
b227ee1
chore: use wit-bindgen from workspace
eduardomourar Mar 13, 2023
fd832c4
chore: set default features to false
eduardomourar Mar 13, 2023
4fd1a4b
Merge pull request #111 from eduardomourar/feat/bindings-crate
pchickey Mar 13, 2023
a5802d2
feat: add basic scaffolding for wasi http (#85)
eduardomourar Mar 17, 2023
88e5b94
Use the pinned nightly in test-programs/macros/build.rs too.
sunfishcode Mar 17, 2023
70bf465
NFC: switch to flags .contains as a method (#115)
pchickey Mar 17, 2023
04372df
Add the proxy world, and remove HTTP from command. (#116)
sunfishcode Mar 17, 2023
1b6c33a
Initial TCP socket host implementation. (#113)
sunfishcode Mar 20, 2023
90e8554
trappable errors in wasi filesystem
Mar 17, 2023
9f49845
look at all these new tests that pass!!!
Mar 17, 2023
31c84f8
these 6 tests still fail on windows
Mar 17, 2023
76d01f8
fix warning from rebase
Mar 20, 2023
148ff72
Update to Wasmtime 7
alexcrichton Mar 21, 2023
58c6de9
Merge pull request #120 from alexcrichton/update-wasmtime
pchickey Mar 21, 2023
f93109d
Merge pull request #117 from bytecodealliance/pch/trappable_for_real_…
pchickey Mar 21, 2023
549bc5e
command tests: inherit stdout and stderr
Mar 9, 2023
9352401
host and adapter: provide stdio via preopens, dont pass stdio or arg …
Mar 21, 2023
017f85e
add `ReadOnlyDir` and `ReadOnlyFile`
dicej Mar 22, 2023
fd9e0a5
fix nanosecond->millisecond conversion in `poll_oneoff`
dicej Mar 22, 2023
cbca97e
Merge pull request #122 from dicej/nanos-millis
dicej Mar 22, 2023
978b898
Merge pull request #121 from dicej/read-only-fs
dicej Mar 22, 2023
4cb0351
Merge remote-tracking branch 'origin/main' into pch/stdio3
Mar 23, 2023
adf9024
fix
Mar 23, 2023
ae174ce
chore: add relevant linker
eduardomourar Mar 23, 2023
77e9b9d
apparently poll_oneoff_stdio is hosed on windows but thats fine i guess
Mar 23, 2023
bba17a8
cap-std-sync: trap, instead of panic, in poll_oneoff
Mar 23, 2023
9eea9ce
chore: include command host implementation for http
eduardomourar Mar 23, 2023
6370d3b
fix warnings
Mar 23, 2023
9089979
Merge pull request #123 from bytecodealliance/pch/stdio3
pchickey Mar 23, 2023
fa04088
Merge branch 'main' into fix/include-outgoing-http-command-world
eduardomourar Mar 24, 2023
960a184
wasi-common: args are back to being part of WasiCtx
Mar 24, 2023
985710d
host: get-arguments available from environment::get_arguments
Mar 24, 2023
3db2a44
rename command's `main` to `run` (unfortunately)
Mar 24, 2023
a6ac27e
Merge pull request #125 from bytecodealliance/pch/environ_args
pchickey Mar 24, 2023
8696d83
Revert "chore: include command host implementation for http"
eduardomourar Mar 27, 2023
5e3dd78
chore: remove outgoing http from command linker
eduardomourar Mar 27, 2023
f8b964a
Merge pull request #124 from eduardomourar/fix/include-outgoing-http-…
pchickey Mar 27, 2023
e3f999f
add `trappable_error_type` for `streams::stream-error`
dicej Apr 4, 2023
b2792b9
Merge pull request #128 from dicej/stream-errors
pchickey Apr 4, 2023
146f576
Remove resource abstraction from clocks (#129)
pchickey Apr 4, 2023
ccfd132
Rename the command entrypoint from `run` back to `main`. (#131)
sunfishcode Apr 5, 2023
f22652b
fix wasi renumber test: return an error in adapter if closing a close…
Apr 6, 2023
4243167
fd_seek: return the expected errno when trying to seek on a directory.
Apr 7, 2023
4be0eb2
Simplify the sockets implementation. (#135)
sunfishcode Apr 10, 2023
7ecaf66
Merge pull request #137 from bytecodealliance/pch/fix_renumber
pchickey Apr 11, 2023
8257372
fix fd_filestat_get: adapter special-case StreamType::Unknown (#139)
pchickey Apr 11, 2023
5b7932b
use git wasmtime so we can use the only_interfaces feature on host bi…
Apr 12, 2023
336746a
de-duplicate command and proxy definitions, useing only_interfaces
Apr 12, 2023
f6d72aa
use latest wit-component, and fix tests
Apr 12, 2023
0c66a84
reactor-tests: fixes to use wasi-base packages
Apr 12, 2023
4b22875
host bindgen macros: fixes
Apr 12, 2023
7fb64c6
io: inline implementation
Apr 12, 2023
391d725
poll: inline definitions into single trait
Apr 13, 2023
e5a9c5b
random: inline implementations into single trait
Apr 13, 2023
0196207
wip
Apr 13, 2023
0fa64f1
host main.rs: implement --mapdir cli flag
Apr 13, 2023
4c1eddc
add dir_fd_op_failures to wasi testsuite
Apr 13, 2023
51dc803
bump wasmtime and use new syntax, but it doesnt quite work yet
Apr 14, 2023
e56487c
bump wasmtime to latest main, we need https://github.com/bytecodealli…
Apr 14, 2023
8eeb800
Merge remote-tracking branch 'origin/main' into pch/fix_more_fs_tests
Apr 14, 2023
59bbdf1
wasmtime matches trace pr
Apr 14, 2023
9c017c6
Merge pull request #142 from bytecodealliance/pch/trace
pchickey Apr 14, 2023
6111c86
Merge pull request #132 from bytecodealliance/pch/fix_more_fs_tests
pchickey Apr 14, 2023
71666a4
Merge remote-tracking branch 'origin/main' into pch/use_only_interfaces
Apr 14, 2023
3d1915b
tests: always expect fd_allocate to fail with NOTSUP
Apr 17, 2023
51e6ad1
adapter: fd_allocate gives notsup on all files
Apr 17, 2023
4ee24e1
readlink: fix adapter to return right len, and test to expect truncation
Apr 17, 2023
1a427ce
Merge pull request #143 from bytecodealliance/pch/deprecate_fd_allocate
pchickey Apr 17, 2023
a2bd4d4
latest wasmtime, where path works with interfaces
Apr 18, 2023
0219acb
Add a WASI test for creating an absolute-path symlink
Apr 18, 2023
0e335a8
Merge pull request #140 from bytecodealliance/pch/use_only_interfaces
pchickey Apr 18, 2023
4afacef
Merge pull request #147 from bytecodealliance/pch/abs_symlink_test
pchickey Apr 18, 2023
08b2161
Merge pull request #144 from bytecodealliance/pch/fix_readlink
pchickey Apr 19, 2023
23bf8b2
triage
Apr 14, 2023
770b0ba
delete truncation_rights test
Apr 18, 2023
6326e0a
host: remove nonblock descriptor flags and set-flags
Apr 20, 2023
3a9e8c1
readlink test: fix warning
Apr 20, 2023
1e84032
adapter: change logic around interpeting ATIM and ATIM_NOW (and MTIM …
Apr 20, 2023
77b98be
command tests: set the whole suite of test config env variables for w…
Apr 20, 2023
1ba5488
with prev commit, some tests that previously failed only on windows pass
Apr 20, 2023
b5f3b82
cap-std-sync: explicitly error with notsup for opening with sync fdfl…
Apr 20, 2023
1c08c65
unlink file trailing slashes: i have no idea why windows returns NOTD…
Apr 20, 2023
01b44ab
Merge pull request #148 from bytecodealliance/pch/trunc
pchickey Apr 20, 2023
f29ab77
Merge pull request #149 from bytecodealliance/pch/files_and_nonblocki…
pchickey Apr 20, 2023
e46f50e
Merge remote-tracking branch 'origin/main' into pch/atim_now
Apr 20, 2023
4b2294c
typo
Apr 20, 2023
05ae90c
Merge pull request #150 from bytecodealliance/pch/atim_now
pchickey Apr 20, 2023
c5b796a
fd_seek: error with invalid offsets in the adapter
Apr 20, 2023
d62b986
fix bug in adapter fd_fdstat_set_flags to frob the append flag.
Apr 21, 2023
344ac74
Merge pull request #151 from bytecodealliance/pch/seek
pchickey Apr 21, 2023
6f44c91
adapter poll_oneoff: when descriptors.get_*_stream(fd) fails, die wit…
pchickey Apr 24, 2023
fa859ea
remove test expectations around rights (#153)
pchickey Apr 24, 2023
68c33b1
wasi-common ctx: new push methods
Apr 25, 2023
ce78199
reactor tests: add a new method showing interaction with streams, who…
Apr 25, 2023
ebd3f4f
add test case showing `with` can use another crate's definition of st…
Apr 25, 2023
0a96d51
Merge pull request #155 from bytecodealliance/pch/reactor-tests-reusi…
pchickey Apr 26, 2023
c8fa55e
adapter: path_ apis return NOTDIR instead of BADF when passed file; f…
pchickey Apr 27, 2023
3e888f7
Redesign wasi ctx a bit (#156)
pchickey Apr 27, 2023
eb082a2
move all of host library into wasi_common
Apr 28, 2023
75a92d3
fix build of all moved code, and the tests
Apr 28, 2023
493aa23
move existing wasi-common sockets proposal interfaces to wasmtime-was…
Apr 29, 2023
9baf5d4
wasi-common: remove all sockets from ctx and scheduler
Apr 29, 2023
3621386
wasi-sockets: crate builds
Apr 29, 2023
f443a3f
wasi-sockets: moved net impl from cap-std-sync there and it builds
Apr 29, 2023
8b76095
move context construction duties from wasi-cap-std-sync to wasmtime-w…
Apr 29, 2023
22ed2a6
and now views work for wasi-common as well
Apr 29, 2023
2811ab5
fix host tests
May 1, 2023
544db7e
uniform view trait
May 1, 2023
03aaa55
Merge pull request #160 from bytecodealliance/pch/separate-sockets
pchickey May 2, 2023
4117272
add scaffolding of preview 1 adapter to wasi-common crate
May 1, 2023
66775e0
possible to run preview 1 modules through host adapter
May 2, 2023
c320988
test-programs crate is called command-tests now
May 2, 2023
5573b0f
test-programs-macros is called test-programs now
May 2, 2023
61fe11a
rejigger test generation and suites
May 2, 2023
39730be
wasi-common: Table operations return a distinct TableError enum
May 2, 2023
c789879
Merge pull request #164 from bytecodealliance/pch/table_error
pchickey May 3, 2023
3752809
Merge pull request #162 from bytecodealliance/pch/scaffold_host_p1
pchickey May 3, 2023
e4f2968
Revert #131, renaming `main` back to `run`. (#165)
sunfishcode May 3, 2023
70fa783
wip
May 4, 2023
0d1fe10
making real progress
May 4, 2023
018deb8
set times, pread, pwrite
May 4, 2023
0522da0
sync is basically the same as datasync
May 4, 2023
6ea8be1
more stat
May 4, 2023
9cc2c0f
everything in fs is done except open, readdir, and the stream read/wr…
May 4, 2023
4ca29f4
readdir done
May 5, 2023
fbf2c6e
filesystem::open_at implemented (i think?)
May 5, 2023
a453eb3
add all the streams. consolidate file and dir into one file.
May 8, 2023
7feecfe
start making host actually kick over by disabling stuff...
May 8, 2023
7ac78c5
a bunch of fixes, move clocks and randomness impls in
May 8, 2023
7f06ffb
fix some table accessors and tests
May 8, 2023
003c94f
fix a few more bugs
May 8, 2023
49ec1a6
fix readonly test
May 8, 2023
eb3b507
remove last vestiges of wasi-cap-std-sync
May 8, 2023
3ea5d15
fix wasi-sockets-sync build to not use wasi_common::Error
May 8, 2023
7fb918d
fixes for windows
May 9, 2023
bef458e
command directory list test: inherit stdio so i can figure out why th…
May 9, 2023
541a1f4
directory_list test: add some context for debugging
May 9, 2023
39cbb74
wild guess
May 9, 2023
cc97390
fix windows error translation
May 9, 2023
403aa95
delete wasi-tokio as well, which was always dead code in this repo
May 9, 2023
0ebd564
rename WasiCtxBuilder::new_sync() to new()
May 9, 2023
54e6405
Merge pull request #167 from bytecodealliance/pch/next
pchickey May 10, 2023
4aa54b3
feat(preview1): implement `args_get`
rvolosatovs May 9, 2023
1cadc42
feat(preview1): implement `args_sizes_get`
rvolosatovs May 9, 2023
e8010e8
feat(preview1): implement `environ_get`
rvolosatovs May 9, 2023
93e753d
feat(preview1): implement `environ_sizes_get`
rvolosatovs May 9, 2023
7c22cb7
feat(preview1): implement `proc_exit`
rvolosatovs May 9, 2023
d63d598
feat(preview1): implement `clock_res_get`
rvolosatovs May 9, 2023
8662a77
feat(preview1): implement `clock_time_get`
rvolosatovs May 9, 2023
59ab6be
feat(preview1): implement `WasiPreview1Adapter::new`
rvolosatovs May 9, 2023
2599bbc
feat(preview1): implement `proc_raise`
rvolosatovs May 9, 2023
c1c6720
feat(preview1): implement `sched_yield`
rvolosatovs May 9, 2023
d15e804
feat(preview1): implement `random_get`
rvolosatovs May 9, 2023
e319603
test: add `environment` test program
rvolosatovs May 9, 2023
e944531
refactor(preview1): trap explicitly
rvolosatovs May 10, 2023
f70eb99
Merge pull request #169 from rvolosatovs/feat/preview1
pchickey May 11, 2023
22763b4
Rename wasi-base to wasi-cli-base. (#171)
sunfishcode May 11, 2023
88e451a
prepare adapter directory layout for upstreaming (#172)
pchickey May 12, 2023
96d8f62
add directory prefix
May 16, 2023
1ccf1a6
Merge remote-tracking branch 'upstream/main' into main
May 17, 2023
e4d9ea6
move preview2-prototyping's wasi-common crate to crates/wasi/src/prev…
May 16, 2023
c2a2aee
add copy of wit; make all fixes to make wasmtime-wasi compile
May 16, 2023
dd55600
move the command and reactor tests into test-programs
May 17, 2023
9a7ea4a
reactor-tests: prune unneeded wit deps
May 17, 2023
403f32d
add command and reactor tests
May 17, 2023
103870c
eelete all remaining files in from-preview2-prototying: done merging …
May 17, 2023
2248661
exclude command-tests and reactor-tests wasm crates from run-tests
May 17, 2023
26e27ec
pipe docs
May 17, 2023
f749b82
fix typo
May 18, 2023
8d9bbb8
add test of preview2 running as components
May 18, 2023
d0e2982
vet: update to getrandom crate is covered by imports
May 18, 2023
43501d8
cargo vet prune
May 18, 2023
535acaa
factor out common config to test-programs crate
May 18, 2023
55281df
add test for preview2's preview 1 host adapter, which is in its infancy
May 18, 2023
5aee0b7
Merge remote-tracking branch 'upstream/main' into pch/merge_preview2_…
May 18, 2023
317320e
add comments, make everything scheduler-related private to crate
May 18, 2023
c368c55
docs: try ignoring the rust_wasi_markdown_parser block in tests
May 18, 2023
d6dace0
delete bogus cargo doc
May 18, 2023
85f05b6
wasmtime-wasi needs windows-sys
May 18, 2023
ff4ad05
turn prtest:full on the hard way. will revert
May 18, 2023
6bde6a1
bump cargo.lock
May 18, 2023
b44ac13
wasmtime-wasi: include witx and wit in publish
May 18, 2023
fa4bdb5
poll_oneoff_files doesnt work on windows, apparently
May 18, 2023
0b8b022
back out prtest:full override
May 19, 2023
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
49 changes: 36 additions & 13 deletions Cargo.lock

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

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ wasmtime-component-util = { workspace = true }
component-macro-test = { path = "crates/misc/component-macro-test" }
component-test-util = { workspace = true }
bstr = "0.2.17"
libc = "0.2.60"
libc = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
walkdir = { workspace = true }
Expand Down Expand Up @@ -99,6 +99,8 @@ members = [
"crates/jit-icache-coherence",
"crates/test-programs/wasi-tests",
"crates/test-programs/wasi-http-tests",
"crates/test-programs/command-tests",
"crates/test-programs/reactor-tests",
"crates/wasi-preview1-component-adapter",
"crates/wasi-preview1-component-adapter/verify",
"crates/winch",
Expand Down Expand Up @@ -187,8 +189,12 @@ regalloc2 = "0.8.1"

# cap-std family:
target-lexicon = { version = "0.12.3", default-features = false, features = ["std"] }
cap-std = "1.0.0"
cap-rand = "1.0.0"
cap-std = "1.0.12"
cap-rand = "1.0.12"
cap-fs-ext = "1.0.12"
cap-time-ext = "1.0.0"
fs-set-times = "0.19.0"
system-interface = { version = "0.25.1", features = ["cap_std_impls"] }
io-lifetimes = { version = "1.0.0", default-features = false }
rustix = "0.37.13"

Expand Down Expand Up @@ -234,6 +240,7 @@ walkdir = "2.3.3"
cfg-if = "1.0"
tempfile = "3.1.0"
filecheck = "0.5.0"
libc = "0.2.60"

[features]
default = [
Expand Down
2 changes: 2 additions & 0 deletions ci/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ cargo test \
--exclude wasi-crypto \
--exclude wasi-tests \
--exclude wasi-http-tests \
--exclude command-tests \
--exclude reactor-tests \
$@
1 change: 1 addition & 0 deletions crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ wasi-common = { workspace = true }
wasi-cap-std-sync = { workspace = true }
wasmtime-wasi = { workspace = true, features = ["tokio"] }
cap-std = { workspace = true }
cap-rand = { workspace = true }
tokio = { version = "1.8.0", features = ["net", "rt-multi-thread", "macros"] }

wasmtime-wasi-http = { workspace = true }
Expand Down
17 changes: 12 additions & 5 deletions crates/test-programs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ fn main() {
fn build_and_generate_tests() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

// Not needed yet, but will be shortly:
//let reactor_adapter = build_adapter("reactor", &[]);

let reactor_adapter = build_adapter(&out_dir, "reactor", &[]);
let command_adapter = build_adapter(
&out_dir,
"command",
Expand All @@ -26,6 +24,8 @@ fn build_and_generate_tests() {

println!("cargo:rerun-if-changed=./wasi-tests");
println!("cargo:rerun-if-changed=./wasi-http-tests");
println!("cargo:rerun-if-changed=./command-tests");
println!("cargo:rerun-if-changed=./reactor-tests");

// Build the test programs:
let mut cmd = Command::new("rustup");
Expand All @@ -36,6 +36,8 @@ fn build_and_generate_tests() {
.arg("--target=wasm32-wasi")
.arg("--package=wasi-tests")
.arg("--package=wasi-http-tests")
.arg("--package=command-tests")
.arg("--package=reactor-tests")
.env("CARGO_TARGET_DIR", &out_dir)
.env("CARGO_PROFILE_DEV_DEBUG", "1")
.env_remove("CARGO_ENCODED_RUSTFLAGS");
Expand All @@ -48,8 +50,13 @@ fn build_and_generate_tests() {
components_rs(&meta, "wasi-tests", "bin", &command_adapter, &out_dir);

modules_rs(&meta, "wasi-http-tests", "bin", &out_dir);
// FIXME Unsure why this is broken at the moment:
// FIXME this is broken at the moment because guest bindgen is embedding the proxy world type,
// so wit-component expects the module to contain the proxy's exports. we need a different
// world to pass guest bindgen that is just "a command that also can do outbound http"
//components_rs(&meta, "wasi-http-tests", "bin", &command_adapter, &out_dir);

components_rs(&meta, "command-tests", "bin", &command_adapter, &out_dir);
components_rs(&meta, "reactor-tests", "cdylib", &reactor_adapter, &out_dir);
}

// Creates an `${out_dir}/${package}_modules.rs` file that exposes a `get_module(&str) -> Module`,
Expand Down Expand Up @@ -170,7 +177,7 @@ fn components_rs(
"
);
cases += &format!("{stem:?} => {global}.clone(),\n");
uses += &format!("use self::{stem} as _;\n");
uses += &format!("#[allow(unused_imports)] use self::{stem} as _;\n");
}

std::fs::write(
Expand Down
18 changes: 18 additions & 0 deletions crates/test-programs/command-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "command-tests"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
anyhow = { workspace = true }
getrandom = "0.2.8"
wit-bindgen = { workspace = true, default-features = true }

# FIXME: building cap-std and rustix currently requires a nightly rust, so we
# are not including it in the test suite.
# The poll_stdin and file_dir_sync tests contain commented-out uses of these
# crates. They should be re-enabled once these crates can build for
# wasm32-wasi on stable rust.
# rustix = { workspace = true }
# cap-std = { workspace = true }
7 changes: 7 additions & 0 deletions crates/test-programs/command-tests/src/bin/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let args = std::env::args().collect::<Vec<_>>();
assert_eq!(
args,
["hello", "this", "", "is an argument", "with 🚩 emoji"]
);
}
10 changes: 10 additions & 0 deletions crates/test-programs/command-tests/src/bin/default_clocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
let a = std::time::Instant::now();
let b = std::time::Instant::now();
let _ = b.checked_duration_since(a).unwrap();

let c = std::time::SystemTime::now();
let d = std::time::SystemTime::now();
let _ = c.duration_since(std::time::UNIX_EPOCH).unwrap();
let _ = d.duration_since(std::time::UNIX_EPOCH).unwrap();
}
30 changes: 30 additions & 0 deletions crates/test-programs/command-tests/src/bin/directory_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use anyhow::{Context, Error};
use std::{collections::HashSet, fs, path::PathBuf};

fn main() -> Result<(), Error> {
assert_eq!(
["/foo.txt", "/bar.txt", "/baz.txt", "/sub"]
.into_iter()
.map(PathBuf::from)
.collect::<HashSet<_>>(),
fs::read_dir("/")
.context("read_dir /")?
.map(|r| r.map(|d| d.path()))
.collect::<Result<_, _>>()
.context("elem in /")?
);

assert_eq!(
["/sub/wow.txt", "/sub/yay.txt"]
.into_iter()
.map(PathBuf::from)
.collect::<HashSet<_>>(),
fs::read_dir("/sub")
.context("read_dir /sub")?
.map(|r| r.map(|d| d.path()))
.collect::<Result<_, _>>()
.context("elem in /sub")?
);

Ok(())
}
10 changes: 10 additions & 0 deletions crates/test-programs/command-tests/src/bin/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
let vars = std::env::vars().collect::<std::collections::HashMap<_, _>>();
assert_eq!(
vars,
[("frabjous", "day"), ("callooh", "callay")]
.into_iter()
.map(|(k, v)| (k.to_owned(), v.to_owned()))
.collect()
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
3 changes: 3 additions & 0 deletions crates/test-programs/command-tests/src/bin/exit_failure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
std::process::exit(1)
}
3 changes: 3 additions & 0 deletions crates/test-programs/command-tests/src/bin/exit_panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
panic!("Curiouser and curiouser!")
}
3 changes: 3 additions & 0 deletions crates/test-programs/command-tests/src/bin/exit_success.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
std::process::exit(0)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! `wit-component` handles modules which export `cabi_realloc` in a special way, using it instead of `memory.grow`
//! to allocate the adapter stack, hence this test.

#[export_name = "cabi_realloc"]
#[no_mangle]
unsafe extern "C" fn cabi_realloc(
old_ptr: *mut u8,
old_len: usize,
align: usize,
new_len: usize,
) -> *mut u8 {
use std::alloc::{self, Layout};

let layout;
let ptr = if old_len == 0 {
if new_len == 0 {
return align as *mut u8;
}
layout = Layout::from_size_align_unchecked(new_len, align);
alloc::alloc(layout)
} else {
debug_assert_ne!(new_len, 0, "non-zero old_len requires non-zero new_len!");
layout = Layout::from_size_align_unchecked(old_len, align);
alloc::realloc(old_ptr, layout, new_len)
};
if ptr.is_null() {
core::arch::wasm32::unreachable();
}
return ptr;
}

fn main() {
println!("hello, world");
}
17 changes: 17 additions & 0 deletions crates/test-programs/command-tests/src/bin/file_append.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::{
error::Error,
fs::OpenOptions,
io::{Seek, SeekFrom, Write},
};

fn main() -> Result<(), Box<dyn Error>> {
let mut file = OpenOptions::new().append(true).open("bar.txt")?;

file.write_all(b"Did gyre and gimble in the wabe;\n")
.unwrap();
file.seek(SeekFrom::Start(0)).unwrap();
file.write_all(b"All mimsy were the borogoves,\n").unwrap();
file.write_all(b"And the mome raths outgrabe.\n").unwrap();

Ok(())
}
14 changes: 14 additions & 0 deletions crates/test-programs/command-tests/src/bin/file_dir_sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main() -> std::io::Result<()> {
let file = std::fs::File::open("bar.txt")?;
file.sync_all()?;
file.sync_data()?;

/*
* TODO: Support opening directories with `File::open` on Windows.
let dir = cap_std::fs::Dir::open(".")?;
dir.sync_all()?;
dir.sync_data()?;
*/

Ok(())
}
Loading